Skip to content

Commit 9a32ed9

Browse files
committed
perf(@angular-devkit/build-angular): improve incremental time during Karma tests
With this change we now use Webpack memory cache when running Karma in watch mode. (cherry picked from commit b2e1d90)
1 parent 57ac7f3 commit 9a32ed9

File tree

2 files changed

+13
-11
lines changed
  • packages/angular_devkit/build_angular/src

2 files changed

+13
-11
lines changed

packages/angular_devkit/build_angular/src/karma/index.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ async function initialize(
5252
namedChunks: true,
5353
extractLicenses: false,
5454
outputHashing: OutputHashing.None,
55+
// The webpack tier owns the watch behavior so we want to force it in the config.
56+
// When not in watch mode, webpack-dev-middleware will call `compiler.watch` anyway.
57+
// https://github.com/webpack/webpack-dev-middleware/blob/698c9ae5e9bb9a013985add6189ff21c1a1ec185/src/index.js#L65
58+
// https://github.com/webpack/webpack/blob/cde1b73e12eb8a77eb9ba42e7920c9ec5d29c2c9/lib/Compiler.js#L379-L388
59+
watch: true,
5560
},
5661
context,
5762
wco => [
@@ -86,13 +91,16 @@ export function execute(
8691
// Check Angular version.
8792
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
8893

94+
let singleRun: boolean | undefined;
95+
if (options.watch !== undefined) {
96+
singleRun = !options.watch;
97+
}
98+
8999
return from(initialize(options, context, transforms.webpackConfiguration)).pipe(
90100
switchMap(async ([karma, webpackConfig]) => {
91-
const karmaOptions: KarmaConfigOptions = {};
92-
93-
if (options.watch !== undefined) {
94-
karmaOptions.singleRun = !options.watch;
95-
}
101+
const karmaOptions: KarmaConfigOptions = {
102+
singleRun,
103+
};
96104

97105
// Convert browsers from a string to an array
98106
if (options.browsers) {

packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma.ts

-6
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ const init: any = (config: any, emitter: any) => {
128128
config.middleware = config.middleware || [];
129129
config.middleware.push('@angular-devkit/build-angular--fallback');
130130

131-
// The webpack tier owns the watch behavior so we want to force it in the config.
132-
// When not in watch mode, webpack-dev-middleware will call `compiler.watch` anyway.
133-
// https://github.com/webpack/webpack-dev-middleware/blob/698c9ae5e9bb9a013985add6189ff21c1a1ec185/src/index.js#L65
134-
// https://github.com/webpack/webpack/blob/cde1b73e12eb8a77eb9ba42e7920c9ec5d29c2c9/lib/Compiler.js#L379-L388
135-
webpackConfig.watch = true;
136-
137131
if (config.singleRun) {
138132
// There's no option to turn off file watching in webpack-dev-server, but
139133
// we can override the file watcher instead.

0 commit comments

Comments
 (0)