Skip to content

Commit 9494b1f

Browse files
committed
test(@angular/build): use correct builder names in integration tests
The integration test setup for the dev-server was incorrectly using the name of the `@angular-devkit/build-angular` builders. While this previously had no effect, recent changes have altered the behavior of the schema validation for the `@angular/build` builders. To ensure accurate testing, the names are now correctly specified in the test setup.
1 parent d067ced commit 9494b1f

File tree

2 files changed

+164
-2
lines changed

2 files changed

+164
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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 {
10+
setupConditionImport,
11+
setTargetMapping,
12+
} from '../../../../../../../../modules/testing/builder/src/dev_prod_mode';
13+
import { buildApplication } from '../../index';
14+
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
15+
16+
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
17+
describe('Option: "conditions"', () => {
18+
beforeEach(async () => {
19+
await setupConditionImport(harness);
20+
});
21+
22+
interface ImportsTestCase {
23+
name: string;
24+
mapping: unknown;
25+
output?: string;
26+
customConditions?: string[];
27+
}
28+
29+
const GOOD_TARGET = './src/good.js';
30+
const BAD_TARGET = './src/bad.js';
31+
32+
const emptyArrayCases: ImportsTestCase[] = [
33+
{
34+
name: 'default fallback without matching condition',
35+
mapping: {
36+
'never': BAD_TARGET,
37+
'default': GOOD_TARGET,
38+
},
39+
},
40+
{
41+
name: 'development condition',
42+
mapping: {
43+
'development': BAD_TARGET,
44+
'default': GOOD_TARGET,
45+
},
46+
},
47+
{
48+
name: 'production condition',
49+
mapping: {
50+
'production': BAD_TARGET,
51+
'default': GOOD_TARGET,
52+
},
53+
},
54+
{
55+
name: 'browser condition (in browser)',
56+
mapping: {
57+
'browser': GOOD_TARGET,
58+
'default': BAD_TARGET,
59+
},
60+
},
61+
{
62+
name: 'browser condition (in server)',
63+
output: 'server/main.server.mjs',
64+
mapping: {
65+
'browser': BAD_TARGET,
66+
'default': GOOD_TARGET,
67+
},
68+
},
69+
];
70+
71+
for (const testCase of emptyArrayCases) {
72+
describe('with empty array ' + testCase.name, () => {
73+
beforeEach(async () => {
74+
await setTargetMapping(harness, testCase.mapping);
75+
});
76+
77+
it('resolves to expected target', async () => {
78+
harness.useTarget('build', {
79+
...BASE_OPTIONS,
80+
optimization: true,
81+
ssr: true,
82+
server: 'src/main.ts',
83+
conditions: [],
84+
});
85+
86+
const { result } = await harness.executeOnce();
87+
88+
expect(result?.success).toBeTrue();
89+
const outputFile = `dist/${testCase.output ?? 'browser/main.js'}`;
90+
harness.expectFile(outputFile).content.toContain('"good-value"');
91+
harness.expectFile(outputFile).content.not.toContain('"bad-value"');
92+
});
93+
});
94+
}
95+
96+
const customCases: ImportsTestCase[] = [
97+
{
98+
name: 'default fallback without matching condition',
99+
mapping: {
100+
'never': BAD_TARGET,
101+
'default': GOOD_TARGET,
102+
},
103+
},
104+
{
105+
name: 'development condition',
106+
mapping: {
107+
'development': BAD_TARGET,
108+
'default': GOOD_TARGET,
109+
},
110+
},
111+
{
112+
name: 'staging condition',
113+
mapping: {
114+
'staging': GOOD_TARGET,
115+
'production': BAD_TARGET,
116+
'default': BAD_TARGET,
117+
},
118+
},
119+
{
120+
name: 'browser condition (in browser)',
121+
mapping: {
122+
'browser': GOOD_TARGET,
123+
'staging': BAD_TARGET,
124+
'default': BAD_TARGET,
125+
},
126+
},
127+
{
128+
name: 'browser condition (in server)',
129+
output: 'server/main.server.mjs',
130+
mapping: {
131+
'browser': BAD_TARGET,
132+
'default': GOOD_TARGET,
133+
},
134+
},
135+
];
136+
137+
for (const testCase of customCases) {
138+
describe('with custom condition ' + testCase.name, () => {
139+
beforeEach(async () => {
140+
await setTargetMapping(harness, testCase.mapping);
141+
});
142+
143+
it('resolves to expected target', async () => {
144+
harness.useTarget('build', {
145+
...BASE_OPTIONS,
146+
optimization: true,
147+
ssr: true,
148+
server: 'src/main.ts',
149+
conditions: ['staging'],
150+
});
151+
152+
const { result } = await harness.executeOnce();
153+
154+
expect(result?.success).toBeTrue();
155+
const outputFile = `dist/${testCase.output ?? 'browser/main.js'}`;
156+
harness.expectFile(outputFile).content.toContain('"good-value"');
157+
harness.expectFile(outputFile).content.not.toContain('"bad-value"');
158+
});
159+
});
160+
}
161+
});
162+
});

packages/angular/build/src/builders/dev-server/tests/setup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export * from '../../../../../../../modules/testing/builder/src';
2222

2323
// TODO: Remove and use import after Vite-based dev server is moved to new package
2424
export const APPLICATION_BUILDER_INFO = Object.freeze({
25-
name: '@angular-devkit/build-angular:application',
25+
name: '@angular/build:application',
2626
schemaPath: path.join(
2727
path.dirname(require.resolve('@angular/build/package.json')),
2828
'src/builders/application/schema.json',
@@ -49,7 +49,7 @@ export const APPLICATION_BASE_OPTIONS = Object.freeze<AppilicationSchema>({
4949
});
5050

5151
export const DEV_SERVER_BUILDER_INFO = Object.freeze({
52-
name: '@angular-devkit/build-angular:dev-server',
52+
name: '@angular/build:dev-server',
5353
schemaPath: __dirname + '/../schema.json',
5454
});
5555

0 commit comments

Comments
 (0)