Skip to content

Commit 66c55df

Browse files
committed
test(@angular-devkit/build-angular): add application/browser test runs
Runs all existing karma tests twice: Once in an environment that uses the application builder and once in one that uses the browser builder. The general approach is taken from the dev server tests. This is in preparation for supporting the application builder for karma tests.
1 parent 65b6e75 commit 66c55df

File tree

13 files changed

+212
-23
lines changed

13 files changed

+212
-23
lines changed

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ LARGE_SPECS = {
318318
},
319319
"extract-i18n": {},
320320
"karma": {
321-
"shards": 3,
321+
"shards": 6,
322322
"size": "large",
323323
"flaky": True,
324324
"extra_deps": [

packages/angular_devkit/build_angular/src/builders/karma/tests/behavior/code-coverage_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { setTimeout } from 'node:timers/promises';
1010
import { tags } from '@angular-devkit/core';
1111
import { last, tap } from 'rxjs';
1212
import { execute } from '../../index';
13-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
13+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1414

1515
// In each of the test below we'll have to call setTimeout to wait for the coverage
1616
// analysis to be done. This is because karma-coverage performs the analysis
@@ -21,8 +21,12 @@ import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
2121

2222
const coveragePath = 'coverage/lcov.info';
2323

24-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
24+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget, isApplicationBuilder) => {
2525
describe('Behavior: "codeCoverage"', () => {
26+
beforeEach(() => {
27+
setupTarget(harness);
28+
});
29+
2630
it('should generate coverage report when file was previously processed by Babel', async () => {
2731
// Force Babel transformation.
2832
await harness.appendToFile('src/app/app.component.ts', '// async');

packages/angular_devkit/build_angular/src/builders/karma/tests/behavior/errors_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
*/
88

99
import { execute } from '../../index';
10-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
10+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1111

12-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
12+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
1313
describe('Behavior: "Errors"', () => {
14+
beforeEach(() => {
15+
setupTarget(harness);
16+
});
17+
1418
it('should fail when there is a TypeScript error', async () => {
1519
harness.useTarget('test', {
1620
...BASE_OPTIONS,

packages/angular_devkit/build_angular/src/builders/karma/tests/behavior/module-cjs_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
*/
88

99
import { execute } from '../../index';
10-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
10+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1111

12-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
12+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
1313
describe('Behavior: "module commonjs"', () => {
14+
beforeEach(() => {
15+
setupTarget(harness);
16+
});
17+
1418
it('should work when module is commonjs', async () => {
1519
harness.useTarget('test', {
1620
...BASE_OPTIONS,

packages/angular_devkit/build_angular/src/builders/karma/tests/behavior/rebuilds_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88

99
import { concatMap, count, debounceTime, take, timeout } from 'rxjs';
1010
import { execute } from '../../index';
11-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
11+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1212

13-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
13+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
1414
describe('Behavior: "Rebuilds"', () => {
15+
beforeEach(() => {
16+
setupTarget(harness);
17+
});
18+
1519
it('recovers from compilation failures in watch mode', async () => {
1620
harness.useTarget('test', {
1721
...BASE_OPTIONS,

packages/angular_devkit/build_angular/src/builders/karma/tests/options/assets_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
*/
88

99
import { execute } from '../../index';
10-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
10+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1111

12-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
12+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
1313
describe('Option: "assets"', () => {
14+
beforeEach(() => {
15+
setupTarget(harness);
16+
});
17+
1418
it('includes assets', async () => {
1519
await harness.writeFiles({
1620
'./src/string-file-asset.txt': 'string-file-asset.txt',

packages/angular_devkit/build_angular/src/builders/karma/tests/options/code-coverage-exclude_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { setTimeout } from 'node:timers/promises';
99
import { execute } from '../../index';
10-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
10+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1111

1212
// In each of the test below we'll have to call setTimeout to wait for the coverage
1313
// analysis to be done. This is because karma-coverage performs the analysis
@@ -18,8 +18,12 @@ import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
1818

1919
const coveragePath = 'coverage/lcov.info';
2020

21-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
21+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
2222
describe('Option: "codeCoverageExclude"', () => {
23+
beforeEach(() => {
24+
setupTarget(harness);
25+
});
26+
2327
it('should exclude file from coverage when set', async () => {
2428
harness.useTarget('test', {
2529
...BASE_OPTIONS,

packages/angular_devkit/build_angular/src/builders/karma/tests/options/code-coverage_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { setTimeout } from 'node:timers/promises';
1010
import { execute } from '../../index';
11-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
11+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1212

1313
// In each of the test below we'll have to call setTimeout to wait for the coverage
1414
// analysis to be done. This is because karma-coverage performs the analysis
@@ -19,8 +19,12 @@ import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
1919

2020
const coveragePath = 'coverage/lcov.info';
2121

22-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
22+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
2323
describe('Option: "codeCoverage"', () => {
24+
beforeEach(() => {
25+
setupTarget(harness);
26+
});
27+
2428
it('should generate coverage report when option is set to true', async () => {
2529
harness.useTarget('test', {
2630
...BASE_OPTIONS,

packages/angular_devkit/build_angular/src/builders/karma/tests/options/exclude_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
*/
88

99
import { execute } from '../../index';
10-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
10+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1111

12-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
12+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
1313
describe('Option: "exclude"', () => {
14+
beforeEach(() => {
15+
setupTarget(harness);
16+
});
17+
1418
beforeEach(async () => {
1519
await harness.writeFiles({
1620
'src/app/error.spec.ts': `

packages/angular_devkit/build_angular/src/builders/karma/tests/options/include_spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
*/
88

99
import { execute } from '../../index';
10-
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
10+
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1111

12-
describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
12+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
1313
describe('Option: "include"', () => {
14+
beforeEach(() => {
15+
setupTarget(harness);
16+
});
17+
1418
it(`should fail when includes doesn't match any files`, async () => {
1519
harness.useTarget('test', {
1620
...BASE_OPTIONS,

0 commit comments

Comments
 (0)