|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
| 8 | +import { workspaces } from '@angular-devkit/core'; |
8 | 9 | import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies
|
9 | 10 | import { DevServerBuilderOutput } from '../../src/dev-server/index';
|
10 | 11 | import { createArchitect, host } from '../utils';
|
@@ -38,6 +39,50 @@ describe('Dev Server Builder index', () => {
|
38 | 39 | await run.stop();
|
39 | 40 | });
|
40 | 41 |
|
| 42 | + it(`does not add 'type="module"' to custom scripts when differential loading is needed`, async () => { |
| 43 | + host.writeMultipleFiles({ |
| 44 | + browserslist: ` |
| 45 | + last 1 chrome version |
| 46 | + IE 10 |
| 47 | + `, |
| 48 | + 'test.js': 'console.log("test");', |
| 49 | + }); |
| 50 | + |
| 51 | + const { workspace } = await workspaces.readWorkspace(host.root(), workspaces.createWorkspaceHost(host)); |
| 52 | + const app = workspace.projects.get('app'); |
| 53 | + if (!app) { |
| 54 | + fail('Test application "app" not found.'); |
| 55 | + |
| 56 | + return; |
| 57 | + } |
| 58 | + const target = app.targets.get('build'); |
| 59 | + if (!target) { |
| 60 | + fail('Test application "app" target "build" not found.'); |
| 61 | + |
| 62 | + return; |
| 63 | + } |
| 64 | + if (!target.options) { |
| 65 | + target.options = {}; |
| 66 | + } |
| 67 | + target.options.scripts = ['test.js']; |
| 68 | + await workspaces.writeWorkspace(workspace, workspaces.createWorkspaceHost(host)); |
| 69 | + |
| 70 | + const architect = (await createArchitect(host.root())).architect; |
| 71 | + const run = await architect.scheduleTarget(targetSpec); |
| 72 | + const output = (await run.result) as DevServerBuilderOutput; |
| 73 | + expect(output.success).toBe(true); |
| 74 | + const response = await fetch('http://localhost:4200/index.html'); |
| 75 | + expect(await response.text()).toContain( |
| 76 | + '<script src="runtime.js" type="module"></script>' + |
| 77 | + '<script src="polyfills.js" type="module"></script>' + |
| 78 | + '<script src="styles.js" type="module"></script>' + |
| 79 | + '<script src="scripts.js"></script>' + |
| 80 | + '<script src="vendor.js" type="module"></script>' + |
| 81 | + '<script src="main.js" type="module"></script>', |
| 82 | + ); |
| 83 | + await run.stop(); |
| 84 | + }); |
| 85 | + |
41 | 86 | it(`doesn't 'type="module"' when differential loading is not needed`, async () => {
|
42 | 87 | host.writeMultipleFiles({
|
43 | 88 | browserslist: `
|
|
0 commit comments