Skip to content

Commit f1ebc0d

Browse files
committed
fixup! test: migrate app-shell-with-service-worker E2E test to Puppeteer
1 parent 7774fbe commit f1ebc0d

File tree

5 files changed

+39
-35
lines changed

5 files changed

+39
-35
lines changed

packages/angular/build/src/builders/application/execute-post-bundle.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ export async function executePostBundleSteps(
138138

139139
// Pre-render (SSG) and App-shell
140140
// If localization is enabled, prerendering is handled in the inlining process.
141+
let indexHtmlOutputPath = indexHtmlOptions?.output;
141142
if (
142143
!partialSSRBuild &&
143144
(prerenderOptions || appShellOptions || (outputMode && serverEntryPoint)) &&
144145
!allErrors.length
145146
) {
146147
assert(
147-
indexHtmlOptions,
148+
indexHtmlOptions && indexHtmlOutputPath,
148149
'The "index" option is required when using the "ssg" or "appShell" options.',
149150
);
150151

@@ -163,17 +164,19 @@ export async function executePostBundleSteps(
163164
allErrors.push(...errors);
164165
allWarnings.push(...warnings);
165166

166-
const indexHasBeenPrerendered = output[indexHtmlOptions.output];
167+
const indexHasBeenPrerendered = output[indexHtmlOutputPath];
167168
for (const [path, { content, appShellRoute }] of Object.entries(output)) {
168169
// Update the index contents with the app shell under these conditions:
169170
// - Replace 'index.html' with the app shell only if it hasn't been prerendered yet.
170171
// - Always replace 'index.csr.html' with the app shell.
171172
let filePath = path;
172173
if (appShellRoute && !indexHasBeenPrerendered) {
173-
if (outputMode !== OutputMode.Server && indexHtmlOptions.output === INDEX_HTML_CSR) {
174+
if (outputMode !== OutputMode.Server && indexHtmlOutputPath === INDEX_HTML_CSR) {
174175
filePath = 'index.html';
176+
// Needed to update the ngsw.json "index" value.
177+
indexHtmlOutputPath = filePath;
175178
} else {
176-
filePath = indexHtmlOptions.output;
179+
filePath = indexHtmlOutputPath;
177180
}
178181
}
179182

@@ -232,7 +235,7 @@ export async function executePostBundleSteps(
232235
workspaceRoot,
233236
serviceWorker,
234237
baseHref,
235-
options.indexHtmlOptions?.output,
238+
indexHtmlOutputPath,
236239
// Ensure additional files recently added are used
237240
[...outputFiles, ...additionalOutputFiles],
238241
assetFiles,

packages/angular/build/src/builders/dev-server/vite/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
import type { BuilderContext } from '@angular-devkit/architect';
1010
import type { Plugin } from 'esbuild';
1111
import assert from 'node:assert';
12-
import { builtinModules, isBuiltin } from 'node:module';
1312
import { join } from 'node:path';
1413
import type { Connect, ViteDevServer } from 'vite';
1514
import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
1615
import { ServerSsrMode } from '../../../tools/vite/plugins';
1716
import { EsbuildLoaderOption, updateExternalMetadata } from '../../../tools/vite/utils';
1817
import { normalizeSourceMaps } from '../../../utils';
19-
import { useComponentStyleHmr, useComponentTemplateHmr } from '../../../utils/environment-options';
18+
import {
19+
useComponentStyleHmr,
20+
useComponentTemplateHmr,
21+
usePartialSsrBuild,
22+
} from '../../../utils/environment-options';
2023
import { Result, ResultKind } from '../../application/results';
2124
import { OutputHashing } from '../../application/schema';
2225
import {
2326
type ApplicationBuilderInternalOptions,
24-
type ExternalResultMetadata,
2527
JavaScriptTransformer,
2628
getSupportedBrowsers,
2729
isZonelessApp,
@@ -119,7 +121,7 @@ export async function* serveWithVite(
119121

120122
// Disable generating a full manifest with routes.
121123
// This is done during runtime when using the dev-server.
122-
browserOptions.partialSSRBuild = true;
124+
browserOptions.partialSSRBuild = usePartialSsrBuild;
123125

124126
// The development server currently only supports a single locale when localizing.
125127
// This matches the behavior of the Webpack-based development server but could be expanded in the future.

packages/angular/build/src/builders/dev-server/vite/utils.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,42 +48,35 @@ export function updateResultRecord(
4848
return;
4949
}
5050

51-
let filePath;
52-
if (outputPath === htmlIndexPath) {
53-
// Convert custom index output path to standard index path for dev-server usage.
54-
// This mimics the Webpack dev-server behavior.
55-
filePath = '/index.html';
56-
} else {
57-
filePath = '/' + normalizePath(outputPath);
58-
}
59-
60-
const servable =
61-
file.type === BuildOutputFileType.Browser || file.type === BuildOutputFileType.Media;
51+
const filePath = '/' + normalizePath(outputPath);
52+
const generatedFile: OutputFileRecord = {
53+
contents: file.contents,
54+
size: file.contents.byteLength,
55+
hash: file.hash,
56+
// Consider the files updated except on the initial build result
57+
updated: !initial,
58+
type: file.type,
59+
servable: file.type === BuildOutputFileType.Browser || file.type === BuildOutputFileType.Media,
60+
};
6261

6362
// Skip analysis of sourcemaps
6463
if (filePath.endsWith('.map')) {
6564
generatedFiles.set(filePath, {
66-
contents: file.contents,
67-
servable,
68-
size: file.contents.byteLength,
69-
hash: file.hash,
70-
type: file.type,
65+
...generatedFile,
7166
updated: false,
7267
});
7368

7469
return;
7570
}
7671

7772
// New or updated file
78-
generatedFiles.set(filePath, {
79-
contents: file.contents,
80-
size: file.contents.byteLength,
81-
hash: file.hash,
82-
// Consider the files updated except on the initial build result
83-
updated: !initial,
84-
type: file.type,
85-
servable,
86-
});
73+
generatedFiles.set(filePath, generatedFile);
74+
75+
if (outputPath === htmlIndexPath) {
76+
// Convert custom index output path to standard index path for dev-server usage.
77+
// This mimics the Webpack dev-server behavior.
78+
generatedFiles.set('/index.html', generatedFile);
79+
}
8780

8881
// Record any external component styles
8982
if (filePath.endsWith('.css') && /^\/[a-f0-9]{64}\.css$/.test(filePath)) {

packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { readFileSync } from 'node:fs';
1212
import type { ServerResponse } from 'node:http';
1313
import { extname } from 'node:path';
1414
import type { Connect, ViteDevServer } from 'vite';
15+
import { INDEX_HTML_CSR } from '../../../builders/application/options';
1516
import { ResultFile } from '../../../builders/application/results';
1617
import { AngularMemoryOutputFiles, AngularOutputAssets, pathnameWithoutBasePath } from '../utils';
1718

@@ -96,7 +97,9 @@ export function createAngularAssetsMiddleware(
9697
// Resource files are handled directly.
9798
// Global stylesheets (CSS files) are currently considered resources to workaround
9899
// dev server sourcemap issues with stylesheets.
99-
if (extension !== '.js' && extension !== '.html') {
100+
// Vite will added the client code even when no-live-reload and no-hmr are passed thus we need to
101+
// exclude .js and .html files when hmr is disabled.
102+
if ((extension !== '.js' && extension !== '.html') || !server.config.server?.hmr) {
100103
const outputFile = outputFiles.get(pathname);
101104
if (outputFile?.servable) {
102105
let data: Uint8Array | string = outputFile.contents;

tests/e2e/utils/puppeteer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ export async function executeBrowserTest(options: BrowserTestOptions = {}) {
2929
const { stdout } = await execAndWaitForOutputToMatch('ng', serveArgs, match, {
3030
...process.env,
3131
'NO_COLOR': '1',
32+
'NG_BUILD_PARTIAL_SSR': '0',
3233
});
34+
3335
url = stripVTControlCharacters(stdout).match(match)?.[1];
3436
if (!url) {
3537
throw new Error('Could not find serving URL');
3638
}
39+
3740
hasStartedServer = true;
3841
}
3942

0 commit comments

Comments
 (0)