|
| 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 } from '@angular-devkit/architect/src/index2'; |
| 9 | +import { TestingArchitectHost } from '@angular-devkit/architect/testing/index2'; |
| 10 | +import { experimental, join, normalize, schema } from '@angular-devkit/core'; |
| 11 | +import { NodeJsSyncHost } from '@angular-devkit/core/node'; |
| 12 | +import * as fs from 'fs'; |
| 13 | +import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies |
| 14 | +import * as path from 'path'; |
| 15 | +import { WorkspaceNodeModulesArchitectHost } from '../../../architect/node'; |
| 16 | +import { DevServerBuildResult } from './index2'; |
| 17 | + |
| 18 | +const devkitRoot = normalize((global as any)._DevKitRoot); // tslint:disable-line:no-any |
| 19 | + |
| 20 | + |
| 21 | +describe('Dev Server Builder', () => { |
| 22 | + let testArchitectHost: TestingArchitectHost; |
| 23 | + let architect: Architect; |
| 24 | + let vfHost: NodeJsSyncHost; |
| 25 | + |
| 26 | + const webpackTargetSpec = { project: 'app', target: 'serve' }; |
| 27 | + |
| 28 | + async function createArchitect(workspaceRoot: string) { |
| 29 | + vfHost = new NodeJsSyncHost(); |
| 30 | + const configContent = fs.readFileSync(path.join(workspaceRoot, 'angular.json'), 'utf-8'); |
| 31 | + const workspaceJson = JSON.parse(configContent); |
| 32 | + |
| 33 | + const registry = new schema.CoreSchemaRegistry(); |
| 34 | + registry.addPostTransform(schema.transforms.addUndefinedDefaults); |
| 35 | + |
| 36 | + const workspace = new experimental.workspace.Workspace(normalize(workspaceRoot), vfHost); |
| 37 | + await workspace.loadWorkspaceFromJson(workspaceJson).toPromise(); |
| 38 | + |
| 39 | + testArchitectHost = new TestingArchitectHost(workspaceRoot, workspaceRoot, |
| 40 | + new WorkspaceNodeModulesArchitectHost(workspace, workspaceRoot)); |
| 41 | + architect = new Architect(testArchitectHost, registry); |
| 42 | + } |
| 43 | + |
| 44 | + beforeEach(async () => { |
| 45 | + await createArchitect(join(devkitRoot, 'tests/angular_devkit/build_webpack/basic-app/')); |
| 46 | + }); |
| 47 | + |
| 48 | + it('works', async () => { |
| 49 | + const run = await architect.scheduleTarget(webpackTargetSpec); |
| 50 | + const output = await run.result as DevServerBuildResult; |
| 51 | + expect(output.success).toBe(true); |
| 52 | + |
| 53 | + const response = await fetch(`http://${output.address}:${output.port}/bundle.js`); |
| 54 | + expect(await response.text()).toContain(`console.log('hello world')`); |
| 55 | + |
| 56 | + await run.stop(); |
| 57 | + }, 30000); |
| 58 | +}); |
0 commit comments