Skip to content

Commit

Permalink
test(@angular-devkit/build-angular): refactor server builder tests to…
Browse files Browse the repository at this point in the history
… use test harness

(cherry picked from commit 54c170b)
  • Loading branch information
alan-agius4 authored and filipesilva committed Jul 12, 2021
1 parent f6ab2e3 commit 1a5c592
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 295 deletions.
176 changes: 0 additions & 176 deletions packages/angular_devkit/build_angular/src/server/base_spec.ts

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @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 { execute } from '../../index';
import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';

describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
describe('Behavior: "Errors"', () => {
it('should not try to resolve web-workers', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
});

await harness.writeFiles({
'src/app/app.worker.ts': `
/// <reference lib="webworker" />
const foo: string = 'hello world';
addEventListener('message', ({ data }) => {
postMessage(foo);
});
`,
'src/main.server.ts': `
if (typeof Worker !== 'undefined') {
const worker = new Worker(new URL('./app/app.worker', import.meta.url), { type: 'module' });
worker.onmessage = ({ data }) => {
console.log('page got message:', data);
};
worker.postMessage('hello');
}
`,
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @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 { execute } from '../../index';
import { BASE_OPTIONS, SERVER_BUILDER_INFO, describeBuilder } from '../setup';

describeBuilder(execute, SERVER_BUILDER_INFO, (harness) => {
describe('Option: "externalDependencies"', () => {
it(`should not bundle dependency when set "externalDependencies" is set.`, async () => {
harness.useTarget('server', {
...BASE_OPTIONS,
externalDependencies: ['@angular/core'],
});

const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);

harness.expectFile('dist/main.js').content.toContain('require("@angular/core")');
harness.expectFile('dist/main.js').content.not.toContain('require("@angular/common")');
});

it(`should bundle all dependencies when "externalDependencies" is unset`, async () => {
harness.useTarget('server', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/main.js').content.not.toContain('require("@angular/core")');
harness.expectFile('dist/main.js').content.not.toContain('require("@angular/common")');
});
});
});
Loading

0 comments on commit 1a5c592

Please sign in to comment.