Skip to content

Commit a5fcf80

Browse files
committed
fix(@angular/build): provide karma stack trace sourcemap support
When executing unit tests with `karma`, the stack traces within errors will now use any sourcemaps that were generated during the build process to provide source-based locations for the errors. Script sourcemaps must be enabled for this functionality.
1 parent 9f870b4 commit a5fcf80

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.npmrc=-1406867100
55
modules/testing/builder/package.json=973445093
66
package.json=2054604346
7-
packages/angular/build/package.json=-1460726595
7+
packages/angular/build/package.json=1250379839
88
packages/angular/cli/package.json=-1917515334
99
packages/angular/pwa/package.json=1108903917
1010
packages/angular/ssr/package.json=1856194341
@@ -17,6 +17,6 @@ packages/angular_devkit/schematics/package.json=673943597
1717
packages/angular_devkit/schematics_cli/package.json=-2026655035
1818
packages/ngtools/webpack/package.json=1021868664
1919
packages/schematics/angular/package.json=251715148
20-
pnpm-lock.yaml=-677899779
20+
pnpm-lock.yaml=-988408449
2121
pnpm-workspace.yaml=-1056556036
2222
yarn.lock=-535855759

packages/angular/build/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ ts_project(
120120
"//:node_modules/rollup",
121121
"//:node_modules/sass",
122122
"//:node_modules/semver",
123+
"//:node_modules/source-map-support",
123124
"//:node_modules/tslib",
124125
"//:node_modules/typescript",
125126
"//:node_modules/vite",

packages/angular/build/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"rollup": "4.34.8",
4242
"sass": "1.85.0",
4343
"semver": "7.7.1",
44+
"source-map-support": "0.5.21",
4445
"vite": "6.1.0",
4546
"watchpack": "2.4.2"
4647
},

packages/angular/build/src/builders/karma/application_builder.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ class AngularPolyfillsPlugin {
161161
f.type = 'module';
162162
}
163163
}
164+
165+
// Add browser sourcemap support as a classic script
166+
files.unshift({
167+
pattern: localResolve('source-map-support/browser-source-map-support.js'),
168+
included: true,
169+
watched: false,
170+
});
164171
}, AngularPolyfillsPlugin),
165172
],
166173
};
@@ -321,12 +328,13 @@ function normalizePolyfills(polyfills: string | string[] | undefined): [string[]
321328

322329
const jasmineGlobalEntryPoint = localResolve('./polyfills/jasmine_global.js');
323330
const jasmineGlobalCleanupEntrypoint = localResolve('./polyfills/jasmine_global_cleanup.js');
331+
const sourcemapEntrypoint = localResolve('./polyfills/init_sourcemaps.js');
324332

325333
const zoneTestingEntryPoint = 'zone.js/testing';
326334
const polyfillsExludingZoneTesting = polyfills.filter((p) => p !== zoneTestingEntryPoint);
327335

328336
return [
329-
polyfillsExludingZoneTesting.concat([jasmineGlobalEntryPoint]),
337+
polyfillsExludingZoneTesting.concat([jasmineGlobalEntryPoint, sourcemapEntrypoint]),
330338
polyfillsExludingZoneTesting.length === polyfills.length
331339
? [jasmineGlobalCleanupEntrypoint]
332340
: [jasmineGlobalCleanupEntrypoint, zoneTestingEntryPoint],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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.dev/license
7+
*/
8+
9+
// eslint-disable-next-line no-undef
10+
globalThis.sourceMapSupport?.install();

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/legacy-cli/e2e/tests/test/test-sourcemap.ts

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import { ng } from '../../utils/process';
55
import { assertIsError } from '../../utils/utils';
66

77
export default async function () {
8-
if (getGlobalVariable('argv')['esbuild']) {
9-
// TODO: enable once this is fixed when using the esbuild builder.
10-
return;
11-
}
12-
138
await writeFile(
149
'src/app/app.component.spec.ts',
1510
`

0 commit comments

Comments
 (0)