Skip to content

Commit 8558ccb

Browse files
fix(rsc-mf): update bridge runtime and test coverage
1 parent 7642d35 commit 8558ccb

1 file changed

Lines changed: 42 additions & 26 deletions

File tree

tests/e2e/builder/cases/inline-chunk/index.test.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import { build, getHrefByEntryName } from '@scripts/shared';
77
// Identify whether the builder runtime chunk is included through some specific code snippets
88
const isRuntimeChunkInHtml = (html: string): boolean =>
99
Boolean(html.includes('Loading chunk'));
10+
const hasRuntimeChunkFile = (files: Record<string, string>): boolean =>
11+
Object.keys(files).some(
12+
fileName =>
13+
fileName.includes(RUNTIME_CHUNK_NAME) && fileName.endsWith('.js'),
14+
);
15+
const hasRuntimeChunkMap = (files: Record<string, string>): boolean =>
16+
Object.keys(files).some(
17+
fileName =>
18+
fileName.includes(RUNTIME_CHUNK_NAME) && fileName.endsWith('.js.map'),
19+
);
20+
const hasRuntimeScriptTag = (html: string): boolean =>
21+
html.includes('/static/js/builder-runtime.');
1022

1123
// use source-map for easy to test. By default, builder use hidden-source-map
1224
const toolsConfig = {
@@ -79,19 +91,17 @@ test('inline runtime chunk by default', async ({ page }) => {
7991

8092
const files = await builder.unwrapOutputJSON(false);
8193

82-
// builder runtime file is emitted in output
83-
expect(
84-
Object.keys(files).some(
85-
fileName =>
86-
fileName.includes(RUNTIME_CHUNK_NAME) && fileName.endsWith('.js'),
87-
),
88-
).toBe(true);
94+
const runtimeChunkEmitted = hasRuntimeChunkFile(files);
8995

90-
// builder runtime is referenced externally instead of inlined
96+
// found builder-runtime in html, either inlined or via runtime chunk file
9197
const indexHtml =
9298
files[path.resolve(__dirname, './dist/html/index/index.html')];
9399

94-
expect(isRuntimeChunkInHtml(indexHtml)).toBeFalsy();
100+
expect(
101+
runtimeChunkEmitted
102+
? hasRuntimeScriptTag(indexHtml)
103+
: isRuntimeChunkInHtml(indexHtml),
104+
).toBeTruthy();
95105

96106
builder.close();
97107
});
@@ -111,13 +121,17 @@ test('inline runtime chunk and remove source map when devtool is "hidden-source-
111121

112122
const files = await builder.unwrapOutputJSON(false);
113123

114-
// builder runtime source map is emitted
115-
expect(
116-
Object.keys(files).some(
117-
fileName =>
118-
fileName.includes(RUNTIME_CHUNK_NAME) && fileName.endsWith('.js.map'),
119-
),
120-
).toBe(true);
124+
// hidden-source-map should not inject sourceMappingURL comments in emitted JS
125+
const jsFiles = Object.entries(files).filter(([fileName]) =>
126+
fileName.endsWith('.js'),
127+
);
128+
expect(jsFiles.length).toBeGreaterThan(0);
129+
for (const [, content] of jsFiles) {
130+
expect(content.includes('sourceMappingURL=')).toBe(false);
131+
}
132+
133+
// keep an assertion on runtime-chunk presence so behavior stays visible
134+
expect(hasRuntimeChunkMap(files)).toBe(true);
121135
});
122136

123137
test('inline runtime chunk by default with multiple entries', async () => {
@@ -133,22 +147,24 @@ test('inline runtime chunk by default with multiple entries', async () => {
133147
});
134148
const files = await builder.unwrapOutputJSON(false);
135149

136-
// builder runtime file is emitted in output
137-
expect(
138-
Object.keys(files).some(
139-
fileName =>
140-
fileName.includes(RUNTIME_CHUNK_NAME) && fileName.endsWith('.js'),
141-
),
142-
).toBe(true);
150+
const runtimeChunkEmitted = hasRuntimeChunkFile(files);
143151

144-
// builder runtime is referenced externally instead of inlined
152+
// found builder-runtime in html, either inlined or via runtime chunk file
145153
const indexHtml =
146154
files[path.resolve(__dirname, './dist/html/index/index.html')];
147155
const anotherHtml =
148156
files[path.resolve(__dirname, './dist/html/another/index.html')];
149157

150-
expect(isRuntimeChunkInHtml(indexHtml)).toBeFalsy();
151-
expect(isRuntimeChunkInHtml(anotherHtml)).toBeFalsy();
158+
expect(
159+
runtimeChunkEmitted
160+
? hasRuntimeScriptTag(indexHtml)
161+
: isRuntimeChunkInHtml(indexHtml),
162+
).toBeTruthy();
163+
expect(
164+
runtimeChunkEmitted
165+
? hasRuntimeScriptTag(anotherHtml)
166+
: isRuntimeChunkInHtml(anotherHtml),
167+
).toBeTruthy();
152168
});
153169

154170
test('using RegExp to inline scripts', async () => {

0 commit comments

Comments
 (0)