Skip to content

Commit 352416f

Browse files
committed
test(@angular-devkit/build-angular): add dev-server builder publicHost option
This change adds expanded unit tests for the dev-server builder's `publicHost` option using the builder test harness.
1 parent 888ac92 commit 352416f

File tree

2 files changed

+69
-66
lines changed

2 files changed

+69
-66
lines changed

packages/angular_devkit/build_angular/src/dev-server/public-host_spec.ts

-66
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. 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.io/license
7+
*/
8+
import { serveWebpackBrowser } from '../../index';
9+
import { executeOnceAndFetch } from '../execute-fetch';
10+
import {
11+
BASE_OPTIONS,
12+
DEV_SERVER_BUILDER_INFO,
13+
describeBuilder,
14+
setupBrowserTarget,
15+
} from '../setup';
16+
17+
const FETCH_HEADERS = Object.freeze({ host: 'example.com' });
18+
19+
describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
20+
describe('option: "publicHost"', () => {
21+
beforeEach(async () => {
22+
setupBrowserTarget(harness);
23+
24+
// Application code is not needed for these tests
25+
await harness.writeFile('src/main.ts', '');
26+
});
27+
28+
it('does not allow an invalid host when option is not present', async () => {
29+
harness.useTarget('serve', {
30+
...BASE_OPTIONS,
31+
});
32+
33+
const { result, response } = await executeOnceAndFetch(harness, '/', {
34+
request: { headers: FETCH_HEADERS },
35+
});
36+
37+
expect(result?.success).toBeTrue();
38+
expect(await response?.text()).toBe('Invalid Host header');
39+
});
40+
41+
it('does not allow an invalid host when option is a different host', async () => {
42+
harness.useTarget('serve', {
43+
...BASE_OPTIONS,
44+
publicHost: 'example.net',
45+
});
46+
47+
const { result, response } = await executeOnceAndFetch(harness, '/', {
48+
request: { headers: FETCH_HEADERS },
49+
});
50+
51+
expect(result?.success).toBeTrue();
52+
expect(await response?.text()).toBe('Invalid Host header');
53+
});
54+
55+
it('allows a host when option is set to used host', async () => {
56+
harness.useTarget('serve', {
57+
...BASE_OPTIONS,
58+
publicHost: 'example.com',
59+
});
60+
61+
const { result, response } = await executeOnceAndFetch(harness, '/', {
62+
request: { headers: FETCH_HEADERS },
63+
});
64+
65+
expect(result?.success).toBeTrue();
66+
expect(await response?.text()).toContain('<title>');
67+
});
68+
});
69+
});

0 commit comments

Comments
 (0)