Skip to content

Commit c70dae4

Browse files
committed
test(@angular/build): add unit tests for unit-test builder options
Adds a suite of disabled unit tests for the options of the unit-test builder. These tests cover the functionality of each option and will be enabled in a future commit.
1 parent f68bdb2 commit c70dae4

12 files changed

+645
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
xdescribe('Option: "browsers"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
});
22+
23+
it('should use jsdom when browsers is not provided', async () => {
24+
harness.useTarget('test', {
25+
...BASE_OPTIONS,
26+
browsers: undefined,
27+
});
28+
29+
const { result, logs } = await harness.executeOnce();
30+
expect(result?.success).toBeTrue();
31+
expect(logs).toContain(
32+
jasmine.objectContaining({ message: 'Using jsdom in Node.js for test execution.' }),
33+
);
34+
});
35+
36+
it('should fail when browsers is empty', async () => {
37+
harness.useTarget('test', {
38+
...BASE_OPTIONS,
39+
browsers: [],
40+
});
41+
42+
await expectAsync(harness.executeOnce()).toBeRejectedWithError(
43+
/must NOT have fewer than 1 items/,
44+
);
45+
});
46+
47+
it('should launch a browser when provided', async () => {
48+
harness.useTarget('test', {
49+
...BASE_OPTIONS,
50+
browsers: ['chrome'],
51+
});
52+
53+
const { result, logs } = await harness.executeOnce();
54+
expect(result?.success).toBeTrue();
55+
expect(logs).toContain(
56+
jasmine.objectContaining({ message: jasmine.stringMatching(/Starting browser "chrome"/) }),
57+
);
58+
});
59+
60+
it('should launch a browser in headless mode when specified', async () => {
61+
harness.useTarget('test', {
62+
...BASE_OPTIONS,
63+
browsers: ['chromeheadless'],
64+
});
65+
66+
const { result, logs } = await harness.executeOnce();
67+
expect(result?.success).toBeTrue();
68+
expect(logs).toContain(
69+
jasmine.objectContaining({
70+
message: jasmine.stringMatching(/Starting browser "chrome" in headless mode/),
71+
}),
72+
);
73+
});
74+
});
75+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
xdescribe('Option: "buildTarget"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
});
22+
23+
it('should fail when buildTarget is not provided', async () => {
24+
const { buildTarget, ...rest } = BASE_OPTIONS;
25+
harness.useTarget('test', rest as any);
26+
27+
await expectAsync(harness.executeOnce()).toBeRejectedWithError(/"buildTarget" is required/);
28+
});
29+
30+
it('should fail when buildTarget is empty', async () => {
31+
harness.useTarget('test', {
32+
...BASE_OPTIONS,
33+
buildTarget: '',
34+
});
35+
36+
await expectAsync(harness.executeOnce()).toBeRejectedWithError(
37+
/must match "\^\S+:\S+(:\S+)?\$"/,
38+
);
39+
});
40+
41+
it('should fail when buildTarget does not have a project name', async () => {
42+
harness.useTarget('test', {
43+
...BASE_OPTIONS,
44+
buildTarget: ':build',
45+
});
46+
47+
await expectAsync(harness.executeOnce()).toBeRejectedWithError(
48+
/must match "\^\S+:\S+(:\S+)?\$"/,
49+
);
50+
});
51+
52+
it('should fail when buildTarget does not have a target name', async () => {
53+
harness.useTarget('test', {
54+
...BASE_OPTIONS,
55+
buildTarget: 'app:',
56+
});
57+
58+
await expectAsync(harness.executeOnce()).toBeRejectedWithError(
59+
/must match "\^\S+:\S+(:\S+)?\$"/,
60+
);
61+
});
62+
});
63+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
xdescribe('Option: "codeCoverageExclude"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
await harness.writeFiles({
22+
'src/app/error.ts': `export const a = 1;`,
23+
});
24+
});
25+
26+
it('should not exclude any files from coverage when not provided', async () => {
27+
harness.useTarget('test', {
28+
...BASE_OPTIONS,
29+
codeCoverage: true,
30+
});
31+
32+
const { result } = await harness.executeOnce();
33+
expect(result?.success).toBeTrue();
34+
const summary = harness.readFile('coverage/coverage-summary.json');
35+
expect(summary).toContain('"src/app/error.ts"');
36+
});
37+
38+
it('should exclude files from coverage that match the glob pattern', async () => {
39+
harness.useTarget('test', {
40+
...BASE_OPTIONS,
41+
codeCoverage: true,
42+
codeCoverageExclude: ['**/error.ts'],
43+
});
44+
45+
const { result } = await harness.executeOnce();
46+
expect(result?.success).toBeTrue();
47+
const summary = harness.readFile('coverage/coverage-summary.json');
48+
expect(summary).not.toContain('"src/app/error.ts"');
49+
});
50+
});
51+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
xdescribe('Option: "codeCoverageReporters"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
});
22+
23+
it('should generate a json summary report when specified', async () => {
24+
harness.useTarget('test', {
25+
...BASE_OPTIONS,
26+
codeCoverage: true,
27+
codeCoverageReporters: ['json-summary'] as any,
28+
});
29+
30+
const { result } = await harness.executeOnce();
31+
expect(result?.success).toBeTrue();
32+
expect(harness.hasFile('coverage/coverage-summary.json')).toBeTrue();
33+
});
34+
35+
it('should generate multiple reports when specified', async () => {
36+
harness.useTarget('test', {
37+
...BASE_OPTIONS,
38+
codeCoverage: true,
39+
codeCoverageReporters: ['json-summary', 'lcov'] as any,
40+
});
41+
42+
const { result } = await harness.executeOnce();
43+
expect(result?.success).toBeTrue();
44+
expect(harness.hasFile('coverage/coverage-summary.json')).toBeTrue();
45+
expect(harness.hasFile('coverage/lcov.info')).toBeTrue();
46+
});
47+
});
48+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
xdescribe('Option: "codeCoverage"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
});
22+
23+
it('should not generate a code coverage report when codeCoverage is false', async () => {
24+
harness.useTarget('test', {
25+
...BASE_OPTIONS,
26+
codeCoverage: false,
27+
});
28+
29+
const { result } = await harness.executeOnce();
30+
expect(result?.success).toBeTrue();
31+
expect(harness.hasFile('coverage/index.html')).toBeFalse();
32+
});
33+
34+
it('should generate a code coverage report when codeCoverage is true', async () => {
35+
harness.useTarget('test', {
36+
...BASE_OPTIONS,
37+
codeCoverage: true,
38+
});
39+
40+
const { result } = await harness.executeOnce();
41+
expect(result?.success).toBeTrue();
42+
expect(harness.hasFile('coverage/index.html')).toBeTrue();
43+
});
44+
});
45+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
xdescribe('Option: "debug"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
});
22+
23+
it('should not enter debug mode when debug is false', async () => {
24+
harness.useTarget('test', {
25+
...BASE_OPTIONS,
26+
debug: false,
27+
});
28+
29+
const { result, logs } = await harness.executeOnce();
30+
expect(result?.success).toBeTrue();
31+
expect(logs).not.toContain(
32+
jasmine.objectContaining({ message: jasmine.stringMatching(/Node.js inspector/) }),
33+
);
34+
});
35+
36+
it('should enter debug mode when debug is true', async () => {
37+
harness.useTarget('test', {
38+
...BASE_OPTIONS,
39+
debug: true,
40+
});
41+
42+
const { result, logs } = await harness.executeOnce();
43+
expect(result?.success).toBeTrue();
44+
expect(logs).toContain(
45+
jasmine.objectContaining({
46+
message: jasmine.stringMatching(/Node.js inspector is active/),
47+
}),
48+
);
49+
});
50+
});
51+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
import { execute } from '../../index';
10+
import {
11+
BASE_OPTIONS,
12+
describeBuilder,
13+
UNIT_TEST_BUILDER_INFO,
14+
setupApplicationTarget,
15+
} from '../setup';
16+
17+
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
18+
xdescribe('Option: "providersFile"', () => {
19+
beforeEach(async () => {
20+
setupApplicationTarget(harness);
21+
});
22+
23+
it('should fail when providersFile does not exist', async () => {
24+
harness.useTarget('test', {
25+
...BASE_OPTIONS,
26+
providersFile: 'src/my.providers.ts',
27+
});
28+
29+
const { result, error } = await harness.executeOnce({ outputLogsOnFailure: false });
30+
expect(result).toBeUndefined();
31+
expect(error?.message).toMatch(
32+
`The specified providers file "src/my.providers.ts" does not exist.`,
33+
);
34+
});
35+
36+
it('should use providers from the specified file', async () => {
37+
await harness.writeFiles({
38+
'src/my.providers.ts': `
39+
import { importProvidersFrom } from '@angular/core';
40+
import { CommonModule } from '@angular/common';
41+
export default [importProvidersFrom(CommonModule)];
42+
`,
43+
});
44+
45+
harness.useTarget('test', {
46+
...BASE_OPTIONS,
47+
providersFile: 'src/my.providers.ts',
48+
});
49+
50+
const { result } = await harness.executeOnce();
51+
expect(result?.success).toBeTrue();
52+
});
53+
});
54+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy