Skip to content

Commit ef1631a

Browse files
committed
test: update snapshots for ESM-compatible Response wrapper
All generated HTTP clients now use a wrapper object instead of directly mutating the Response, which changes the generated output and requires snapshot updates.
1 parent c822b09 commit ef1631a

File tree

32 files changed

+10028
-4593
lines changed

32 files changed

+10028
-4593
lines changed

package-lock.json

Lines changed: 5149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"c12": "^3.3.0",
5555
"citty": "^0.1.6",
5656
"consola": "^3.4.2",
57+
"ejs": "^3.1.10",
5758
"eta": "^4.0.1",
5859
"lodash": "^4.17.21",
5960
"nanoid": "^5.1.5",

test-esm-fix.mjs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { readFileSync } from 'fs';
2+
import { fileURLToPath } from 'url';
3+
import { dirname, join } from 'path';
4+
import ejs from 'ejs';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
9+
// Read the template
10+
const templatePath = join(__dirname, 'templates/base/http-clients/fetch-http-client.ejs');
11+
const templateContent = readFileSync(templatePath, 'utf-8');
12+
13+
// Minimal config to render the template - the template uses 'it' as the variable name
14+
const it = {
15+
apiConfig: {
16+
baseUrl: 'https://api.example.com'
17+
},
18+
generateResponses: true,
19+
config: {
20+
unwrapResponseData: false
21+
}
22+
};
23+
24+
// Render the template
25+
try {
26+
const rendered = ejs.render(templateContent, { it });
27+
28+
// Check if the fix is in place
29+
if (rendered.includes('// Create a wrapper object that doesn\'t mutate the Response')) {
30+
console.log('✅ ESM fix is present in the template');
31+
32+
// Check that we're not directly mutating response
33+
if (!rendered.includes('response.data =') && !rendered.includes('response.error =')) {
34+
console.log('✅ Not directly mutating Response object');
35+
} else {
36+
console.log('❌ Still directly mutating Response object');
37+
process.exit(1);
38+
}
39+
40+
// Check that we're creating a wrapper
41+
if (rendered.includes('const r = {') && rendered.includes('data: (null as unknown)')) {
42+
console.log('✅ Creating wrapper object for Response');
43+
} else {
44+
console.log('❌ Not creating wrapper object');
45+
process.exit(1);
46+
}
47+
48+
console.log('\n✅ All checks passed! The template fix is correct.');
49+
} else {
50+
console.log('❌ ESM fix not found in template');
51+
process.exit(1);
52+
}
53+
} catch (error) {
54+
console.error('Error rendering template:', error);
55+
process.exit(1);
56+
}

0 commit comments

Comments
 (0)