Skip to content

Commit d43ca04

Browse files
alan-agius4mgechev
authored andcommitted
fix(@angular-devkit/build-angular): re-order reporters to set code coverage at the very end
1 parent c0eadbe commit d43ca04

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,15 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
7070
successCb = config.buildWebpack.successCb;
7171
failureCb = config.buildWebpack.failureCb;
7272

73-
config.reporters.unshift('@angular-devkit/build-angular--event-reporter');
74-
7573
// When using code-coverage, auto-add coverage-istanbul.
7674
config.reporters = config.reporters || [];
7775
if (options.codeCoverage && config.reporters.indexOf('coverage-istanbul') === -1) {
78-
config.reporters.unshift('coverage-istanbul');
76+
config.reporters.push('coverage-istanbul');
7977
}
8078

8179
// Add a reporter that fixes sourcemap urls.
8280
if (normalizeSourceMaps(options.sourceMap).scripts) {
83-
config.reporters.unshift('@angular-devkit/build-angular--sourcemap-reporter');
81+
config.reporters.push('@angular-devkit/build-angular--sourcemap-reporter');
8482

8583
// Code taken from https://github.com/tschaub/karma-source-map-support.
8684
// We can't use it directly because we need to add it conditionally in this file, and karma
@@ -94,6 +92,8 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
9492
], true);
9593
}
9694

95+
config.reporters.push('@angular-devkit/build-angular--event-reporter');
96+
9797
// Add webpack config.
9898
const webpackConfig = config.buildWebpack.webpackConfig;
9999
const webpackMiddlewareConfig = {

packages/angular_devkit/build_angular/test/karma/code-coverage_spec_large.ts

+17
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,21 @@ describe('Karma Builder code coverage', () => {
110110
expect(content).not.toContain('my-lib');
111111
}
112112
}, 120000);
113+
114+
it(`should fail when coverage is below threhold and 'emitWarning' is false`, async () => {
115+
host.replaceInFile('karma.conf.js', 'fixWebpackSourcePaths: true',
116+
`
117+
fixWebpackSourcePaths: true,
118+
thresholds: {
119+
emitWarning: false,
120+
global: {
121+
statements: 200
122+
}
123+
}`,
124+
);
125+
126+
const run = await architect.scheduleTarget(karmaTargetSpec, { codeCoverage: true });
127+
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: false }));
128+
await run.stop();
129+
}, 120000);
113130
});

0 commit comments

Comments
 (0)