Skip to content

Commit 97bfd46

Browse files
clydinalan-agius4
authored andcommitted
test(@angular-devkit/build-angular): use harness for browser builder works test
This converts the 'works' spec to use the new builder harness for testing. The change also provides for a before/after comparison of an existing test.
1 parent bcac383 commit 97bfd46

File tree

1 file changed

+32
-24
lines changed
  • packages/angular_devkit/build_angular/src/browser/specs

1 file changed

+32
-24
lines changed

packages/angular_devkit/build_angular/src/browser/specs/works_spec.ts

+32-24
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,41 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { describeBuilder } from '../../testing';
9+
import { buildWebpackBrowser } from '../index';
810

9-
import { Architect } from '@angular-devkit/architect';
10-
import { normalize } from '@angular-devkit/core';
11-
import { browserBuild, createArchitect, host } from '../../test-utils';
11+
const BROWSER_BUILDER_INFO = {
12+
name: '@angular-devkit/build-angular:browser',
13+
schemaPath: __dirname + '/../schema.json',
14+
};
1215

16+
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
17+
describe('basic test', () => {
18+
it('works', async () => {
19+
// Provide a target and options for builder execution
20+
harness.useTarget('build', {
21+
outputPath: 'dist',
22+
index: 'src/index.html',
23+
main: 'src/main.ts',
24+
polyfills: 'src/polyfills.ts',
25+
tsConfig: 'src/tsconfig.app.json',
26+
progress: false,
27+
assets: ['src/favicon.ico', 'src/assets'],
28+
styles: ['src/styles.css'],
29+
scripts: [],
30+
});
1331

14-
describe('Browser Builder basic test', () => {
15-
const target = { project: 'app', target: 'build' };
16-
let architect: Architect;
32+
// Execute builder with above provided project, target, and options
33+
await harness.executeOnce();
1734

18-
beforeEach(async () => {
19-
await host.initialize().toPromise();
20-
architect = (await createArchitect(host.root())).architect;
21-
});
22-
23-
afterEach(async () => host.restore().toPromise());
24-
25-
it('works', async () => {
26-
await browserBuild(architect, host, target);
27-
28-
// Default files should be in outputPath.
29-
expect(await host.scopedSync().exists(normalize('dist/runtime.js'))).toBe(true);
30-
expect(await host.scopedSync().exists(normalize('dist/main.js'))).toBe(true);
31-
expect(await host.scopedSync().exists(normalize('dist/polyfills.js'))).toBe(true);
32-
expect(await host.scopedSync().exists(normalize('dist/vendor.js'))).toBe(true);
33-
expect(await host.scopedSync().exists(normalize('dist/favicon.ico'))).toBe(true);
34-
expect(await host.scopedSync().exists(normalize('dist/styles.css'))).toBe(true);
35-
expect(await host.scopedSync().exists(normalize('dist/index.html'))).toBe(true);
35+
// Default files should be in outputPath.
36+
expect(harness.hasFile('dist/runtime.js')).toBe(true);
37+
expect(harness.hasFile('dist/main.js')).toBe(true);
38+
expect(harness.hasFile('dist/polyfills.js')).toBe(true);
39+
expect(harness.hasFile('dist/vendor.js')).toBe(true);
40+
expect(harness.hasFile('dist/favicon.ico')).toBe(true);
41+
expect(harness.hasFile('dist/styles.css')).toBe(true);
42+
expect(harness.hasFile('dist/index.html')).toBe(true);
43+
});
3644
});
3745
});

0 commit comments

Comments
 (0)