Skip to content

Commit 004e2de

Browse files
test(sdk): format node esm fixture sources
1 parent a370d5b commit 004e2de

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

packages/sdk/__tests__/node-builtin-esm.spec.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const createResponse = (body: string) => ({
88
text: async () => body,
99
});
1010

11+
const moduleSource = (source: TemplateStringsArray, ...values: string[]) =>
12+
String.raw(source, ...values).trim();
13+
1114
const setFetchMock = (
1215
handler: (url: string) => ReturnType<typeof createResponse>,
1316
) => {
@@ -62,7 +65,12 @@ describe('Node ESM builtin loading', () => {
6265
it('loads node: builtin imports without fetching them as remote chunks', async () => {
6366
const fetchMock = setRemoteEntryFetchMock(
6467
DEFAULT_REMOTE_ENTRY_URL,
65-
"import { pathToFileURL } from 'node:url'; export const marker = pathToFileURL('/tmp/module-federation').href; export default {};",
68+
moduleSource`
69+
import { pathToFileURL } from 'node:url';
70+
71+
export const marker = pathToFileURL('/tmp/module-federation').href;
72+
export default {};
73+
`,
6674
);
6775

6876
const scriptContext = await loadNodeEsmScript<{
@@ -77,7 +85,12 @@ describe('Node ESM builtin loading', () => {
7785
it('loads bare Node.js builtin imports without fetching them as remote chunks', async () => {
7886
const fetchMock = setRemoteEntryFetchMock(
7987
DEFAULT_REMOTE_ENTRY_URL,
80-
"import { sep } from 'path'; export const separator = sep; export default {};",
88+
moduleSource`
89+
import { sep } from 'path';
90+
91+
export const separator = sep;
92+
export default {};
93+
`,
8194
);
8295

8396
const scriptContext = await loadNodeEsmScript<{
@@ -94,7 +107,16 @@ describe('Node ESM builtin loading', () => {
94107
'http://example.com/server/remoteEntry.js?v=123#entry';
95108
const fetchMock = setRemoteEntryFetchMock(
96109
remoteEntryUrl,
97-
"import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const webpack = require('webpack'); export const webpackType = typeof webpack; export const metaUrl = import.meta.url; export default {};",
110+
moduleSource`
111+
import { createRequire } from 'node:module';
112+
113+
const require = createRequire(import.meta.url);
114+
const webpack = require('webpack');
115+
116+
export const webpackType = typeof webpack;
117+
export const metaUrl = import.meta.url;
118+
export default {};
119+
`,
98120
);
99121

100122
const scriptContext = await loadNodeEsmScript<{
@@ -118,12 +140,21 @@ describe('Node ESM builtin loading', () => {
118140
const fetchMock = setFetchMock((url) => {
119141
if (url === remoteEntryUrl) {
120142
return createResponse(
121-
"export const chunkValuePromise = import('./chunk.mjs').then((chunk) => chunk.value); export default {};",
143+
moduleSource`
144+
export const chunkValuePromise = import('./chunk.mjs').then(
145+
(chunk) => chunk.value,
146+
);
147+
export default {};
148+
`,
122149
);
123150
}
124151

125152
if (url === chunkUrl) {
126-
return createResponse("export const value = 'loaded chunk';");
153+
return createResponse(
154+
moduleSource`
155+
export const value = 'loaded chunk';
156+
`,
157+
);
127158
}
128159

129160
throw new Error(`${url} should not be fetched`);
@@ -143,7 +174,11 @@ describe('Node ESM builtin loading', () => {
143174
const fileChunkUrl = 'file:///tmp/chunk.mjs';
144175
const fetchMock = setRemoteEntryFetchMock(
145176
remoteEntryUrl,
146-
`import value from '${fileChunkUrl}'; export default value;`,
177+
moduleSource`
178+
import value from '${fileChunkUrl}';
179+
180+
export default value;
181+
`,
147182
);
148183

149184
await expect(loadNodeEsmScript(remoteEntryUrl)).rejects.toThrow(
@@ -158,7 +193,11 @@ describe('Node ESM builtin loading', () => {
158193
const remoteEntryUrl = 'http://example.com/server/remoteEntry.js';
159194
const fetchMock = setRemoteEntryFetchMock(
160195
remoteEntryUrl,
161-
"import React from 'react'; export default React;",
196+
moduleSource`
197+
import React from 'react';
198+
199+
export default React;
200+
`,
162201
);
163202

164203
await expect(loadNodeEsmScript(remoteEntryUrl)).rejects.toThrow(

0 commit comments

Comments
 (0)