Skip to content

Commit 7f101f1

Browse files
committed
test(@angular/build): remove isViteRun from dev-server test harness
Removes the `isViteRun` parameter from the `describeServeBuilder` helper and updates usage in test files. This change simplifies the tests by assuming the modern application builder behavior, removing conditional logic for legacy builders.
1 parent f7e02fe commit 7f101f1

File tree

10 files changed

+620
-705
lines changed

10 files changed

+620
-705
lines changed

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,25 @@ import { executeDevServer } from '../../index';
1111
import { describeServeBuilder } from '../jasmine-helpers';
1212
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
1313

14-
describeServeBuilder(
15-
executeDevServer,
16-
DEV_SERVER_BUILDER_INFO,
17-
(harness, setupTarget, isViteRun) => {
18-
// TODO(fix-vite): currently this is broken in vite.
19-
(isViteRun ? xdescribe : describe)('Behavior: "browser builder budgets"', () => {
20-
beforeEach(() => {
21-
setupTarget(harness, {
22-
// Add a budget error for any file over 100 bytes
23-
budgets: [{ type: BudgetType.All, maximumError: '100b' }],
24-
optimization: true,
25-
});
14+
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
15+
// TODO(fix-vite): currently this is broken in vite.
16+
xdescribe('Behavior: "browser builder budgets"', () => {
17+
beforeEach(() => {
18+
setupTarget(harness, {
19+
// Add a budget error for any file over 100 bytes
20+
budgets: [{ type: BudgetType.All, maximumError: '100b' }],
21+
optimization: true,
2622
});
23+
});
2724

28-
it('should ignore budgets defined in the "buildTarget" options', async () => {
29-
harness.useTarget('serve', {
30-
...BASE_OPTIONS,
31-
});
25+
it('should ignore budgets defined in the "buildTarget" options', async () => {
26+
harness.useTarget('serve', {
27+
...BASE_OPTIONS,
28+
});
3229

33-
const { result } = await harness.executeOnce();
30+
const { result } = await harness.executeOnce();
3431

35-
expect(result?.success).toBe(true);
36-
});
32+
expect(result?.success).toBe(true);
3733
});
38-
},
39-
);
34+
});
35+
});

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

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,86 +15,74 @@ import { executeOnceAndFetch } from '../execute-fetch';
1515
import { describeServeBuilder } from '../jasmine-helpers';
1616
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
1717

18-
describeServeBuilder(
19-
executeDevServer,
20-
DEV_SERVER_BUILDER_INFO,
21-
(harness, setupTarget, isApplicationBuilder) => {
22-
describe('Behavior: "conditional imports"', () => {
23-
if (!isApplicationBuilder) {
24-
it('requires esbuild', () => {
25-
expect(true).toBeTrue();
26-
});
27-
28-
return;
29-
}
30-
31-
beforeEach(async () => {
32-
setupTarget(harness);
18+
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
19+
describe('Behavior: "conditional imports"', () => {
20+
beforeEach(async () => {
21+
setupTarget(harness);
3322

34-
await setupConditionImport(harness);
35-
});
23+
await setupConditionImport(harness);
24+
});
3625

37-
interface ImportsTestCase {
38-
name: string;
39-
mapping: unknown;
40-
output?: string;
41-
}
26+
interface ImportsTestCase {
27+
name: string;
28+
mapping: unknown;
29+
output?: string;
30+
}
4231

43-
const GOOD_TARGET = './src/good.js';
44-
const BAD_TARGET = './src/bad.js';
32+
const GOOD_TARGET = './src/good.js';
33+
const BAD_TARGET = './src/bad.js';
4534

46-
const testCases: ImportsTestCase[] = [
47-
{ name: 'simple string', mapping: GOOD_TARGET },
48-
{
49-
name: 'default fallback without matching condition',
50-
mapping: {
51-
'never': BAD_TARGET,
52-
'default': GOOD_TARGET,
53-
},
35+
const testCases: ImportsTestCase[] = [
36+
{ name: 'simple string', mapping: GOOD_TARGET },
37+
{
38+
name: 'default fallback without matching condition',
39+
mapping: {
40+
'never': BAD_TARGET,
41+
'default': GOOD_TARGET,
5442
},
55-
{
56-
name: 'development condition',
57-
mapping: {
58-
'development': GOOD_TARGET,
59-
'default': BAD_TARGET,
60-
},
43+
},
44+
{
45+
name: 'development condition',
46+
mapping: {
47+
'development': GOOD_TARGET,
48+
'default': BAD_TARGET,
6149
},
62-
{
63-
name: 'production condition',
64-
mapping: {
65-
'production': BAD_TARGET,
66-
'default': GOOD_TARGET,
67-
},
50+
},
51+
{
52+
name: 'production condition',
53+
mapping: {
54+
'production': BAD_TARGET,
55+
'default': GOOD_TARGET,
6856
},
69-
{
70-
name: 'browser condition (in browser)',
71-
mapping: {
72-
'browser': GOOD_TARGET,
73-
'default': BAD_TARGET,
74-
},
57+
},
58+
{
59+
name: 'browser condition (in browser)',
60+
mapping: {
61+
'browser': GOOD_TARGET,
62+
'default': BAD_TARGET,
7563
},
76-
];
64+
},
65+
];
7766

78-
for (const testCase of testCases) {
79-
describe(testCase.name, () => {
80-
beforeEach(async () => {
81-
await setTargetMapping(harness, testCase.mapping);
82-
});
67+
for (const testCase of testCases) {
68+
describe(testCase.name, () => {
69+
beforeEach(async () => {
70+
await setTargetMapping(harness, testCase.mapping);
71+
});
8372

84-
it('resolves to expected target', async () => {
85-
harness.useTarget('serve', {
86-
...BASE_OPTIONS,
87-
});
73+
it('resolves to expected target', async () => {
74+
harness.useTarget('serve', {
75+
...BASE_OPTIONS,
76+
});
8877

89-
const { result, response } = await executeOnceAndFetch(harness, '/main.js');
78+
const { result, response } = await executeOnceAndFetch(harness, '/main.js');
9079

91-
expect(result?.success).toBeTrue();
92-
const output = await response?.text();
93-
expect(output).toContain('good-value');
94-
expect(output).not.toContain('bad-value');
95-
});
80+
expect(result?.success).toBeTrue();
81+
const output = await response?.text();
82+
expect(output).toContain('good-value');
83+
expect(output).not.toContain('bad-value');
9684
});
97-
}
98-
});
99-
},
100-
);
85+
});
86+
}
87+
});
88+
});

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

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,70 +12,66 @@ import { executeDevServer } from '../../index';
1212
import { describeServeBuilder } from '../jasmine-helpers';
1313
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
1414

15-
describeServeBuilder(
16-
executeDevServer,
17-
DEV_SERVER_BUILDER_INFO,
18-
(harness, setupTarget, isViteRun) => {
19-
// TODO(fix-vite): currently this is broken in vite.
20-
(isViteRun ? xdescribe : describe)('Behavior: "i18n translation file watching"', () => {
21-
beforeEach(() => {
22-
harness.useProject('test', {
23-
root: '.',
24-
sourceRoot: 'src',
25-
cli: {
26-
cache: {
27-
enabled: false,
28-
},
15+
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
16+
// TODO(fix-vite): currently this is broken in vite.
17+
xdescribe('Behavior: "i18n translation file watching"', () => {
18+
beforeEach(() => {
19+
harness.useProject('test', {
20+
root: '.',
21+
sourceRoot: 'src',
22+
cli: {
23+
cache: {
24+
enabled: false,
2925
},
30-
i18n: {
31-
locales: {
32-
fr: 'src/locales/messages.fr.xlf',
33-
},
26+
},
27+
i18n: {
28+
locales: {
29+
fr: 'src/locales/messages.fr.xlf',
3430
},
35-
});
36-
37-
setupTarget(harness, { localize: ['fr'] });
31+
},
3832
});
3933

40-
it('watches i18n translation files by default', async () => {
41-
harness.useTarget('serve', {
42-
...BASE_OPTIONS,
43-
watch: true,
44-
});
34+
setupTarget(harness, { localize: ['fr'] });
35+
});
36+
37+
it('watches i18n translation files by default', async () => {
38+
harness.useTarget('serve', {
39+
...BASE_OPTIONS,
40+
watch: true,
41+
});
4542

46-
await harness.writeFile(
47-
'src/app/app.component.html',
48-
`
43+
await harness.writeFile(
44+
'src/app/app.component.html',
45+
`
4946
<p id="hello" i18n="An introduction header for this sample">Hello {{ title }}! </p>
5047
`,
51-
);
48+
);
5249

53-
await harness.writeFile('src/locales/messages.fr.xlf', TRANSLATION_FILE_CONTENT);
50+
await harness.writeFile('src/locales/messages.fr.xlf', TRANSLATION_FILE_CONTENT);
5451

55-
await harness.executeWithCases([
56-
async ({ result }) => {
57-
expect(result?.success).toBe(true);
52+
await harness.executeWithCases([
53+
async ({ result }) => {
54+
expect(result?.success).toBe(true);
5855

59-
const mainUrl = new URL('main.js', `${result?.baseUrl}`);
60-
const response = await fetch(mainUrl);
61-
expect(await response?.text()).toContain('Bonjour');
56+
const mainUrl = new URL('main.js', `${result?.baseUrl}`);
57+
const response = await fetch(mainUrl);
58+
expect(await response?.text()).toContain('Bonjour');
6259

63-
await harness.modifyFile('src/locales/messages.fr.xlf', (content) =>
64-
content.replace('Bonjour', 'Salut'),
65-
);
66-
},
67-
async ({ result }) => {
68-
expect(result?.success).toBe(true);
60+
await harness.modifyFile('src/locales/messages.fr.xlf', (content) =>
61+
content.replace('Bonjour', 'Salut'),
62+
);
63+
},
64+
async ({ result }) => {
65+
expect(result?.success).toBe(true);
6966

70-
const mainUrl = new URL('main.js', `${result?.baseUrl}`);
71-
const response = await fetch(mainUrl);
72-
expect(await response?.text()).toContain('Salut');
73-
},
74-
]);
75-
});
67+
const mainUrl = new URL('main.js', `${result?.baseUrl}`);
68+
const response = await fetch(mainUrl);
69+
expect(await response?.text()).toContain('Salut');
70+
},
71+
]);
7672
});
77-
},
78-
);
73+
});
74+
});
7975

8076
const TRANSLATION_FILE_CONTENT = `
8177
<?xml version="1.0" encoding="UTF-8" ?>

0 commit comments

Comments
 (0)