|
| 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 { Architect, BuilderRun } from '@angular-devkit/architect'; |
| 9 | +import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies |
| 10 | +import { DevServerBuilderOutput } from '../../src/dev-server'; |
| 11 | +import { createArchitect, host } from '../utils'; |
| 12 | + |
| 13 | + |
| 14 | +describe('Dev Server Builder allowed host', () => { |
| 15 | + // We have to spoof the host to a non-numeric one because Webpack Dev Server does not |
| 16 | + // check the hosts anymore when requests come from numeric IP addresses. |
| 17 | + const headers = { host: 'spoofy.mcspoofface' }; |
| 18 | + |
| 19 | + const target = { project: 'app', target: 'serve' }; |
| 20 | + let architect: Architect; |
| 21 | + // We use runs like this to ensure it WILL stop the servers at the end of each tests. |
| 22 | + let runs: BuilderRun[]; |
| 23 | + |
| 24 | + beforeEach(async () => { |
| 25 | + await host.initialize().toPromise(); |
| 26 | + architect = (await createArchitect(host.root())).architect; |
| 27 | + runs = []; |
| 28 | + }); |
| 29 | + afterEach(async () => { |
| 30 | + await host.restore().toPromise(); |
| 31 | + await Promise.all(runs.map(r => r.stop())); |
| 32 | + }); |
| 33 | + |
| 34 | + it('works', async () => { |
| 35 | + const run = await architect.scheduleTarget(target, { allowedHosts: ['spoofy.mcspoofface'] }); |
| 36 | + runs.push(run); |
| 37 | + const output = await run.result as DevServerBuilderOutput; |
| 38 | + expect(output.success).toBe(true); |
| 39 | + expect(output.baseUrl).toBe('http://localhost:4200/'); |
| 40 | + |
| 41 | + const response = await fetch(`${output.baseUrl}`, { headers }); |
| 42 | + expect(await response.text()).toContain('<title>HelloWorldApp</title>'); |
| 43 | + }, 30000); |
| 44 | +}); |
0 commit comments