|
| 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 { DevServerBuilderOutput } from '@angular-devkit/build-angular'; |
| 10 | +import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies |
| 11 | +import { createArchitect, host } from '../test-utils'; |
| 12 | + |
| 13 | + |
| 14 | +describe('Dev Server Builder hmr', () => { |
| 15 | + const target = { project: 'app', target: 'serve' }; |
| 16 | + let architect: Architect; |
| 17 | + // We use runs like this to ensure it WILL stop the servers at the end of each tests. |
| 18 | + let runs: BuilderRun[]; |
| 19 | + |
| 20 | + beforeEach(async () => { |
| 21 | + await host.initialize().toPromise(); |
| 22 | + architect = (await createArchitect(host.root())).architect; |
| 23 | + runs = []; |
| 24 | + }); |
| 25 | + afterEach(async () => { |
| 26 | + await host.restore().toPromise(); |
| 27 | + await Promise.all(runs.map(r => r.stop())); |
| 28 | + }); |
| 29 | + |
| 30 | + it('adds HMR accept code in all JS bundles', async () => { |
| 31 | + const run = await architect.scheduleTarget(target, { hmr: true }); |
| 32 | + runs.push(run); |
| 33 | + const output = await run.result as DevServerBuilderOutput; |
| 34 | + expect(output.success).toBe(true); |
| 35 | + expect(output.baseUrl).toBe('https://localhost:4200/'); |
| 36 | + |
| 37 | + const polyfills = await fetch('https://localhost:4200/polyfills.js'); |
| 38 | + expect(await polyfills.text()).toContain('ngHmrAccept(module);'); |
| 39 | + |
| 40 | + const main = await fetch('https://localhost:4200/main.js'); |
| 41 | + expect(await main.text()).toContain('ngHmrAccept(module);'); |
| 42 | + }, 30000); |
| 43 | +}); |
0 commit comments