Skip to content

Commit 99d1f43

Browse files
author
Angular Builds
committed
0a4ef30 feat(@angular-devkit/build-angular): karma-coverage w/ app builder
1 parent 9650fc0 commit 99d1f43

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "19.0.0-next.8+sha-422e847",
3+
"version": "19.0.0-next.8+sha-0a4ef30",
44
"description": "Angular Webpack Build Facade",
55
"main": "src/index.js",
66
"typings": "src/index.d.ts",
77
"builders": "builders.json",
88
"dependencies": {
99
"@ampproject/remapping": "2.3.0",
10-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#422e847",
11-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#422e847",
12-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#422e847",
13-
"@angular/build": "github:angular/angular-build-builds#422e847",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#0a4ef30",
11+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#0a4ef30",
12+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#0a4ef30",
13+
"@angular/build": "github:angular/angular-build-builds#0a4ef30",
1414
"@babel/core": "7.25.2",
1515
"@babel/generator": "7.25.6",
1616
"@babel/helper-annotate-as-pure": "7.24.7",
@@ -21,7 +21,7 @@
2121
"@babel/preset-env": "7.25.4",
2222
"@babel/runtime": "7.25.6",
2323
"@discoveryjs/json-ext": "0.6.1",
24-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#422e847",
24+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#0a4ef30",
2525
"@vitejs/plugin-basic-ssl": "1.1.0",
2626
"ansi-colors": "4.1.3",
2727
"autoprefixer": "10.4.20",
@@ -77,7 +77,7 @@
7777
"@angular/localize": "^19.0.0-next.0",
7878
"@angular/platform-server": "^19.0.0-next.0",
7979
"@angular/service-worker": "^19.0.0-next.0",
80-
"@angular/ssr": "github:angular/angular-ssr-builds#422e847",
80+
"@angular/ssr": "github:angular/angular-ssr-builds#0a4ef30",
8181
"@web/test-runner": "^0.19.0",
8282
"browser-sync": "^3.0.2",
8383
"jest": "^29.5.0",
@@ -98,7 +98,7 @@
9898
"@angular/service-worker": {
9999
"optional": true
100100
},
101-
"@angular/ssr": "github:angular/angular-ssr-builds#422e847",
101+
"@angular/ssr": "github:angular/angular-ssr-builds#0a4ef30",
102102
"@web/test-runner": {
103103
"optional": true
104104
},

src/builders/karma/application_builder.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
2929
__setModuleDefault(result, mod);
3030
return result;
3131
};
32+
var __importDefault = (this && this.__importDefault) || function (mod) {
33+
return (mod && mod.__esModule) ? mod : { "default": mod };
34+
};
3235
Object.defineProperty(exports, "__esModule", { value: true });
3336
exports.execute = execute;
3437
exports.writeTestFiles = writeTestFiles;
3538
const build_1 = require("@angular/build");
3639
const private_1 = require("@angular/build/private");
3740
const crypto_1 = require("crypto");
41+
const fast_glob_1 = __importDefault(require("fast-glob"));
3842
const fs = __importStar(require("fs/promises"));
3943
const path = __importStar(require("path"));
4044
const rxjs_1 = require("rxjs");
@@ -75,8 +79,7 @@ async function getProjectSourceRoot(context) {
7579
const sourceRoot = (projectMetadata.sourceRoot ?? projectMetadata.root ?? '');
7680
return path.join(context.workspaceRoot, sourceRoot);
7781
}
78-
async function collectEntrypoints(options, context) {
79-
const projectSourceRoot = await getProjectSourceRoot(context);
82+
async function collectEntrypoints(options, context, projectSourceRoot) {
8083
// Glob for files to test.
8184
const testFiles = await (0, find_tests_1.findTests)(options.include ?? [], options.exclude ?? [], context.workspaceRoot, projectSourceRoot);
8285
const entryPoints = new Set([
@@ -95,12 +98,16 @@ async function initializeApplication(options, context, karmaOptions, transforms
9598
context.logger.warn(`This build is using the application builder but transforms.webpackConfiguration was provided. The transform will be ignored.`);
9699
}
97100
const testDir = path.join(context.workspaceRoot, 'dist/test-out', (0, crypto_1.randomUUID)());
101+
const projectSourceRoot = await getProjectSourceRoot(context);
98102
const [karma, [entryPoints, polyfills]] = await Promise.all([
99103
Promise.resolve().then(() => __importStar(require('karma'))),
100-
collectEntrypoints(options, context),
104+
collectEntrypoints(options, context, projectSourceRoot),
101105
fs.rm(testDir, { recursive: true, force: true }),
102106
]);
103107
const outputPath = testDir;
108+
const instrumentForCoverage = options.codeCoverage
109+
? createInstrumentationFilter(projectSourceRoot, getInstrumentationExcludedPaths(context.workspaceRoot, options.codeCoverageExclude ?? []))
110+
: undefined;
104111
// Build tests with `application` builder, using test files as entry points.
105112
const buildOutput = await first((0, private_1.buildApplicationInternal)({
106113
entryPoints,
@@ -115,6 +122,7 @@ async function initializeApplication(options, context, karmaOptions, transforms
115122
styles: true,
116123
vendor: true,
117124
},
125+
instrumentForCoverage,
118126
styles: options.styles,
119127
polyfills,
120128
webWorkerTsConfig: options.webWorkerTsConfig,
@@ -207,3 +215,18 @@ async function first(generator) {
207215
}
208216
throw new Error('Expected generator to emit at least once.');
209217
}
218+
function createInstrumentationFilter(includedBasePath, excludedPaths) {
219+
return (request) => {
220+
return (!excludedPaths.has(request) &&
221+
!/\.(e2e|spec)\.tsx?$|[\\/]node_modules[\\/]/.test(request) &&
222+
request.startsWith(includedBasePath));
223+
};
224+
}
225+
function getInstrumentationExcludedPaths(root, excludedPaths) {
226+
const excluded = new Set();
227+
for (const excludeGlob of excludedPaths) {
228+
const excludePath = excludeGlob[0] === '/' ? excludeGlob.slice(1) : excludeGlob;
229+
fast_glob_1.default.sync(excludePath, { cwd: root }).forEach((p) => excluded.add(path.join(root, p)));
230+
}
231+
return excluded;
232+
}

src/utils/normalize-cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1010
exports.normalizeCacheOptions = normalizeCacheOptions;
1111
const node_path_1 = require("node:path");
1212
/** Version placeholder is replaced during the build process with actual package version */
13-
const VERSION = '19.0.0-next.8+sha-422e847';
13+
const VERSION = '19.0.0-next.8+sha-0a4ef30';
1414
function hasCacheMetadata(value) {
1515
return (!!value &&
1616
typeof value === 'object' &&

uniqueId

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fri Sep 27 2024 18:53:57 GMT+0000 (Coordinated Universal Time)
1+
Fri Sep 27 2024 19:11:14 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)