-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Expand file tree
/
Copy pathcommon-js-warning_spec.ts
More file actions
82 lines (69 loc) · 2.74 KB
/
Copy pathcommon-js-warning_spec.ts
File metadata and controls
82 lines (69 loc) · 2.74 KB
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
/**
* @license
* Copyright Google Inc. 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 { logging } from '@angular-devkit/core';
import { createArchitect, host } from '../../test-utils';
describe('Browser Builder commonjs warning', () => {
const targetSpec = { project: 'app', target: 'build' };
let architect: Architect;
let logger: logging.Logger;
let logs: string[];
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
// Create logger
logger = new logging.Logger('');
logs = [];
logger.subscribe(e => logs.push(e.message));
});
afterEach(async () => host.restore().toPromise());
it('should show warning when depending on a Common JS bundle', async () => {
// Add a Common JS dependency
host.appendToFile('src/app/app.component.ts', `
import 'bootstrap';
`);
const run = await architect.scheduleTarget(targetSpec, undefined, { logger });
const output = await run.result;
expect(output.success).toBe(true);
const logMsg = logs.join();
expect(logMsg).toMatch(/WARNING in.+app\.component\.ts depends on 'bootstrap'\. CommonJS or AMD dependencies/);
expect(logMsg).not.toContain('jquery', 'Should not warn on transitive CommonJS packages which parent is also CommonJS.');
await run.stop();
});
it('should not show warning when depending on a Common JS bundle which is allowed', async () => {
// Add a Common JS dependency
host.appendToFile('src/app/app.component.ts', `
import 'bootstrap';
import 'zone.js/dist/zone-error';
`);
const overrides = {
allowedCommonJsDependencies: [
'bootstrap',
'zone.js',
],
};
const run = await architect.scheduleTarget(targetSpec, overrides, { logger });
const output = await run.result;
expect(output.success).toBe(true);
expect(logs.join()).not.toContain('WARNING');
await run.stop();
});
it(`should show warning when importing non global '@angular/common/locale' data`, async () => {
// Add a Common JS dependency
host.appendToFile('src/app/app.component.ts', `
import '@angular/common/locales/fr';
`);
const run = await architect.scheduleTarget(targetSpec, undefined, { logger });
const output = await run.result;
expect(output.success).toBe(true);
const logMsg = logs.join();
expect(logMsg).toMatch(/WARNING in.+app\.component\.ts depends on '@angular\/common\/locales\/fr'/);
expect(logMsg).toContain(`Did you mean to import '@angular/common/locales/global/fr'`);
await run.stop();
});
});