Skip to content

Commit 54c170b

Browse files
alan-agius4filipesilva
authored andcommitted
test(@angular-devkit/build-angular): refactor server builder tests to use test harness
1 parent 3d71c63 commit 54c170b

File tree

8 files changed

+324
-295
lines changed

8 files changed

+324
-295
lines changed

packages/angular_devkit/build_angular/src/server/base_spec.ts

Lines changed: 0 additions & 176 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/server/external_dependencies_spec.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/server/resources-output-path_spec.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC 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+
9+
import { execute } from '../../index';
10+
import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';
11+
12+
describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
13+
describe('Behavior: "Errors"', () => {
14+
it('should not try to resolve web-workers', async () => {
15+
harness.useTarget('test', {
16+
...BASE_OPTIONS,
17+
});
18+
19+
await harness.writeFiles({
20+
'src/app/app.worker.ts': `
21+
/// <reference lib="webworker" />
22+
23+
const foo: string = 'hello world';
24+
addEventListener('message', ({ data }) => {
25+
postMessage(foo);
26+
});
27+
`,
28+
'src/main.server.ts': `
29+
if (typeof Worker !== 'undefined') {
30+
const worker = new Worker(new URL('./app/app.worker', import.meta.url), { type: 'module' });
31+
worker.onmessage = ({ data }) => {
32+
console.log('page got message:', data);
33+
};
34+
worker.postMessage('hello');
35+
}
36+
`,
37+
});
38+
39+
const { result } = await harness.executeOnce();
40+
41+
expect(result?.success).toBeTrue();
42+
});
43+
});
44+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC 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+
9+
import { execute } from '../../index';
10+
import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';
11+
12+
describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
13+
describe('Option: "externalDependencies"', () => {
14+
it(`should not bundle dependency when set "externalDependencies" is set.`, async () => {
15+
harness.useTarget('server', {
16+
...BASE_OPTIONS,
17+
externalDependencies: ['@angular/core'],
18+
});
19+
20+
const { result } = await harness.executeOnce();
21+
expect(result?.success).toBe(true);
22+
23+
harness.expectFile('dist/main.js').content.toContain('require("@angular/core")');
24+
harness.expectFile('dist/main.js').content.not.toContain('require("@angular/common")');
25+
});
26+
27+
it(`should bundle all dependencies when "externalDependencies" is unset`, async () => {
28+
harness.useTarget('server', {
29+
...BASE_OPTIONS,
30+
});
31+
32+
const { result } = await harness.executeOnce();
33+
expect(result?.success).toBe(true);
34+
harness.expectFile('dist/main.js').content.not.toContain('require("@angular/core")');
35+
harness.expectFile('dist/main.js').content.not.toContain('require("@angular/common")');
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)