-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathindex_spec.ts
90 lines (74 loc) · 2.99 KB
/
index_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Architect } from '@angular-devkit/architect';
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { schema, workspaces } from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
import fetch from 'node-fetch'; // eslint-disable-line import/no-extraneous-dependencies
import * as path from 'path';
import { DevServerBuildOutput } from './index';
describe('Dev Server Builder', () => {
let testArchitectHost: TestingArchitectHost;
let architect: Architect;
let vfHost: NodeJsSyncHost;
const webpackTargetSpec = { project: 'app', target: 'serve' };
async function createArchitect(workspaceRoot: string) {
vfHost = new NodeJsSyncHost();
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const { workspace } = await workspaces.readWorkspace(
workspaceRoot,
workspaces.createWorkspaceHost(vfHost),
);
testArchitectHost = new TestingArchitectHost(
workspaceRoot,
workspaceRoot,
new WorkspaceNodeModulesArchitectHost(workspace, workspaceRoot),
);
architect = new Architect(testArchitectHost, registry);
}
beforeEach(async () => {
const ngJsonPath = path.join(__dirname, '../../test/basic-app/angular.json');
const workspaceRoot = path.dirname(require.resolve(ngJsonPath));
await createArchitect(workspaceRoot);
});
it('works with CJS config', async () => {
const run = await architect.scheduleTarget(webpackTargetSpec, {
webpackConfig: 'webpack.config.cjs',
});
const output = (await run.result) as DevServerBuildOutput;
expect(output.success).toBe(true);
const response = await fetch(`http://localhost:${output.port}/bundle.js`);
expect(await response.text()).toContain(`console.log('hello world')`);
await run.stop();
}, 30000);
it('works with ESM config', async () => {
const run = await architect.scheduleTarget(webpackTargetSpec, {
webpackConfig: 'webpack.config.mjs',
});
const output = (await run.result) as DevServerBuildOutput;
expect(output.success).toBe(true);
const response = await fetch(`http://localhost:${output.port}/bundle.js`);
expect(await response.text()).toContain(`console.log('hello world')`);
await run.stop();
}, 30000);
it('works and returns emitted files', async () => {
const run = await architect.scheduleTarget(webpackTargetSpec);
const output = (await run.result) as DevServerBuildOutput;
expect(output.success).toBe(true);
expect(output.emittedFiles).toContain({
id: 'main',
name: 'main',
initial: true,
file: 'bundle.js',
extension: '.js',
});
await run.stop();
}, 30000);
});