10000 build: fix legacy saucelabs test bundle generation after ESM changes … · angular/angular@5c10efe · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c10efe

Browse files
committed
build: fix legacy saucelabs test bundle generation after ESM changes (#48521)
ZoneJS is no longer loaded as an UMD, but instead is included as part of the browser init entry-point. This means that ZoneJS is bundled and the ESBuild logic needs to be adjusted for that. PR Close #48521
1 parent 5d2e461 commit 5c10efe

File tree

7 files changed

+74
-64
lines changed

7 files changed

+74
-64
lines changed

.circleci/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,6 @@ jobs:
530530
mkdir -p packages/common/locales/extra
531531
cp dist/bin/packages/common/locales/*.ts packages/common/locales
532532
cp dist/bin/packages/common/locales/extra/*.ts packages/common/locales/extra
533-
# Build ZoneJS so that it can be loaded globally in the Karma tests.
534-
- run: yarn bazel build //packages/zone.js:npm_package
535533
# Build the bundle for all tests to run within Saucelabs
536534
- run: node tools/legacy-saucelabs/build-saucelabs-test-bundle.mjs
537535
- run:

karma-js.conf.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ module.exports = function(config) {
3838
'node_modules/core-js-bundle/index.js',
3939
'node_modules/jasmine-ajax/lib/mock-ajax.js',
4040

41-
// ZoneJS configuration needed for some event manager tests. This config could
42-
// affect all legacy tests but in reality is scoped to certain special tests.
43-
'packages/platform-browser/test/dom/events/zone_event_unpatched.init.js',
44-
45-
// Dependencies built by Bazel. See `config.yml` for steps running before
46-
// the legacy Saucelabs tests run.
47-
'dist/bin/packages/zone.js/npm_package/bundles/zone.umd.js',
48-
'dist/bin/packages/zone.js/npm_package/bundles/zone-testing.umd.js',
49-
'dist/bin/packages/zone.js/npm_package/bundles/task-tracking.umd.js',
50-
5141
// Static test assets.
5242
{pattern: 'packages/platform-browser/test/static_assets/**/*', included: false},
5343
{pattern: 'packages/platform-browser/test/browser/static_assets/**/*', included: false},

packages/platform-browser/test/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ts_library(
4343

4444
js_library(
4545
name = "zone_event_unpatched_init_lib",
46-
srcs = ["dom/events/zone_event_unpatched.init.js"],
46+
srcs = ["dom/events/zone_event_unpatched.init.mjs"],
4747
)
4848

4949
jasmine_node_test(

packages/platform-browser/test/dom/events/zone_event_unpatched.init.js renamed to packages/platform-browser/test/dom/events/zone_event_unpatched.init.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
// strictly needed, but done for a specific test verifying that unpatched events are
1515
// running outside the zone. See `event_manager_spec.ts` and the
1616
// `unpatchedEvents handler outside of ngZone` spec.
17-
window.__zone_symbol__UNPATCHED_EVENTS = ['unpatchedEventManagerTest'];
17+
18+
export function configureZoneUnpatchedEvent() {
19+
window.__zone_symbol__UNPATCHED_EVENTS = ['unpatchedEventManagerTest'];
20+
}
21+
22+
// Invoke the function as a side-effect. We still expose the function so that it could be
23+
// used e.g. in the Saucelabs legacy-job `test-init.ts` file.
24+
configureZoneUnpatchedEvent();

tools/legacy-saucelabs/build-saucelabs-test-bundle.mjs

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,33 @@ async function main() {
7474
async function findSpecFiles() {
7575
const baseTestFiles = glob.sync('**/*_spec.js', {absolute: true, cwd: legacyOutputDir});
7676

77-
return multimatch(
78-
baseTestFiles,
79-
[
80-
'**/*',
81-
`!${legacyOutputDir}/_testing_init/**`,
82-
`!${legacyOutputDir}/**/e2e_test/**`,
83-
`!${legacyOutputDir}/**/*node_only_spec.js`,
84-
`!${legacyOutputDir}/benchpress/**`,
85-
`!${legacyOutputDir}/compiler-cli/**`,
86-
`!${legacyOutputDir}/compiler-cli/src/ngtsc/**`,
87-
`!${legacyOutputDir}/compiler-cli/test/compliance/**`,
88-
`!${legacyOutputDir}/compiler-cli/test/ngtsc/**`,
89-
`!${legacyOutputDir}/compiler/test/aot/**`,
90-
`!${legacyOutputDir}/compiler/test/render3/**`,
91-
`!${legacyOutputDir}/core/test/bundling/**`,
92-
`!${legacyOutputDir}/core/schematics/test/**`,
93-
`!${legacyOutputDir}/core/test/render3/ivy/**`,
94-
`!${legacyOutputDir}/core/test/render3/jit/**`,
95-
`!${legacyOutputDir}/core/test/render3/perf/**`,
96-
`!${legacyOutputDir}/elements/schematics/**`,
97-
`!${legacyOutputDir}/examples/**/e2e_test/*`,
98-
`!${legacyOutputDir}/language-service/**`,
99-
`!${legacyOutputDir}/platform-server/**`,
100-
`!${legacyOutputDir}/localize/**/test/**`,
101-
`!${legacyOutputDir}/localize/schematics/**`,
102-
`!${legacyOutputDir}/router/**/test/**`,
103-
`!${legacyOutputDir}/zone.js/**/test/**`,
104-
`!${legacyOutputDir}/platform-browser/testing/e2e_util.js`,
105-
106-
]
107-
);
77+
return multimatch(baseTestFiles, [
78+
'**/*',
79+
`!${legacyOutputDir}/_testing_init/**`,
80+
`!${legacyOutputDir}/**/e2e_test/**`,
81+
`!${legacyOutputDir}/**/*node_only_spec.js`,
82+
`!${legacyOutputDir}/benchpress/**`,
83+
`!${legacyOutputDir}/compiler-cli/**`,
84+
`!${legacyOutputDir}/compiler-cli/src/ngtsc/**`,
85+
`!${legacyOutputDir}/compiler-cli/test/compliance/**`,
86+
`!${legacyOutputDir}/compiler-cli/test/ngtsc/**`,
87+
`!${legacyOutputDir}/compiler/test/aot/**`,
88+
`!${legacyOutputDir}/compiler/test/render3/**`,
89+
`!${legacyOutputDir}/core/test/bundling/**`,
90+
`!${legacyOutputDir}/core/schematics/test/**`,
91+
`!${legacyOutputDir}/core/test/render3/ivy/**`,
92+
`!${legacyOutputDir}/core/test/render3/jit/**`,
93+
`!${legacyOutputDir}/core/test/render3/perf/**`,
94+
`!${legacyOutputDir}/elements/schematics/**`,
95+
`!${legacyOutputDir}/examples/**/e2e_test/*`,
96+
`!${legacyOutputDir}/language-service/**`,
97+
`!${legacyOutputDir}/platform-server/**`,
98+
`!${legacyOutputDir}/localize/**/test/**`,
99+
`!${legacyOutputDir}/localize/schematics/**`,
100+
`!${legacyOutputDir}/router/**/test/**`,
101+
`!${legacyOutputDir}/zone.js/**/test/**`,
102+
`!${legacyOutputDir}/platform-browser/testing/e2e_util.js`,
103+
]);
108104
}
109105

110106
/**
@@ -149,13 +145,16 @@ async function createResolveEsbuildPlugin() {
149145
const resolveMappings = new Map([
150146
[/@angular\//, `${legacyOutputDir}/`],
151147
[/^angular-in-memory-web-api$/, join(legacyOutputDir, 'misc/angular-in-memory-web-api')],
148+
[/^zone.js\//, `${legacyOutputDir}/zone.js/`],
152149
]);
153150

154151
return {
155-
name: 'ng-resolve-esbuild', setup: (build) => {
156-
build.onResolve({filter: /(@angular\/|angular-in-memory-web-api)/}, async (args) => {
157-
const matchedPattern = Array.from(resolveMappings.keys()).find(
158-
pattern => args.path.match(pattern));
152+
name: 'ng-resolve-esbuild',
153+
setup: (build) => {
154+
build.onResolve({filter: /(@angular\/|angular-in-memory-web-api|zone.js)/}, async (args) => {
155+
const matchedPattern = Array.from(resolveMappings.keys()).find((pattern) =>
156+
args.path.match(pattern)
157+
);
159158

160159
if (matchedPattern === undefined) {
161160
return undefined;
@@ -177,7 +176,7 @@ async function createResolveEsbuildPlugin() {
177176

178177
return stats !== null ? {path: resolvedPath} : undefined;
179178
});
180-
}
179+
},
181180
};
182181
}
183182

@@ -210,9 +209,10 @@ async function transpileDecoratorDownlevelTransform() {
210209
* Compiles the project using the TypeScript compiler in order to produce
211210
* JS output of the packages and tests.
212211
*/
213-
async function compileProjectWithTsc() {
212+
async function compileProjectWithTsc() {
214213
const {legacyCompilationDownlevelDecoratorTransform} = await import(
215-
url.pathToFileURL(decoratorDownlevelOutFile));
214+
url.pathToFileURL(decoratorDownlevelOutFile)
215+
);
216216
const config = parseTsconfigFile(legacyTsconfigPath, dirname(legacyTsconfigPath));
217217
const program = ts.createProgram(config.fileNames, config.options);
218218

@@ -225,15 +225,17 @@ async function transpileDecoratorDownlevelTransform() {
225225
const diagnostics = [
226226
...result.diagnostics,
227227
...program.getSyntacticDiagnostics(),
228-
...program.getSemanticDiagnostics()
228+
...program.getSemanticDiagnostics(),
229229
];
230230

231231
if (diagnostics.length) {
232-
console.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, {
233-
getCanonicalFileName: fileName => fileName,
234-
getCurrentDirectory: () => program.getCurrentDirectory(),
235-
getNewLine: () => '\n',
236-
}));
232+
console.error(
233+
ts.formatDiagnosticsWithColorAndContext(diagnostics, {
234+
getCanonicalFileName: (fileName) => fileName,
235+
getCurrentDirectory: () => program.getCurrentDirectory(),
236+
getNewLine: () => '\n',
237+
})
238+
);
237239

238240
throw new Error('Compilation failed. See errors above.');
239241
}
@@ -261,7 +263,6 @@ function parseTsconfigFile(tsconfigPath, basePath) {
261263
return ts.parseJsonConfigFileContent(config, parseConfigHost, basePath, {});
262264
}
263265

264-
265266
/**
266267
* Retrieves the `fs.Stats` results for the given path gracefully.
267268
* If the file does not exist, returns `null`.
@@ -274,7 +275,7 @@ async function statGraceful(path) {
274275
}
275276
}
276277

277-
main().catch(e => {
278+
main().catch((e) => {
278279
console.error(e);
279280
process.exitCode = 1;
280281
});

tools/legacy-saucelabs/pre-setup.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
// ZoneJS configuration needed for some event manager tests. This config could
10+
// affect all legacy tests but in reality is scoped to certain special tests.
11+
import {configureZoneUnpatchedEvent} from '../../packages/platform-browser/test/dom/events/zone_event_unpatched.init.mjs';
12+
13+
// Increase the timeout for specs as Saucelabs devices can be slow.
14+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
15+
16+
configureZoneUnpatchedEvent();

tools/legacy-saucelabs/test-init.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// Increase the timeout for specs as Saucelabs devices can be slow.
10-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
11-
12-
import '../testing/init_browser_tests';
9+
import './pre-setup';
10+
import '../testing/browser_tests.init';

0 commit comments

Comments
 (0)
0