"Fossies" - the Fresh Open Source Software Archive 
Member "angular-cli-15.2.4/packages/angular_devkit/build_angular/src/builders/browser/tests/options/allowed-common-js-dependencies_spec.ts" (16 Mar 2023, 4095 Bytes) of package /linux/www/angular-cli-15.2.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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 { logging } from '@angular-devkit/core';
10 import { buildWebpackBrowser } from '../../index';
11 import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
12
13 describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
14 describe('Option: "allowedCommonJsDependencies"', () => {
15 describe('given option is not set', () => {
16 for (const aot of [true, false]) {
17 it(`should show warning when depending on a Common JS bundle in ${
18 aot ? 'AOT' : 'JIT'
19 } Mode`, async () => {
20 // Add a Common JS dependency
21 await harness.appendToFile('src/app/app.component.ts', `import 'bootstrap';`);
22
23 harness.useTarget('build', {
24 ...BASE_OPTIONS,
25 allowedCommonJsDependencies: [],
26 aot,
27 });
28
29 const { result, logs } = await harness.executeOnce();
30
31 expect(result?.success).toBe(true);
32 expect(logs).toContain(
33 jasmine.objectContaining<logging.LogEntry>({
34 message: jasmine.stringMatching(
35 /Warning: .+app\.component\.ts depends on 'bootstrap'\. CommonJS or AMD dependencies/,
36 ),
37 }),
38 );
39 expect(logs).not.toContain(
40 jasmine.objectContaining<logging.LogEntry>({
41 message: jasmine.stringMatching('jquery'),
42 }),
43 'Should not warn on transitive CommonJS packages which parent is also CommonJS.',
44 );
45 });
46 }
47 });
48
49 it('should not show warning when depending on a Common JS bundle which is allowed', async () => {
50 // Add a Common JS dependency
51 await harness.appendToFile(
52 'src/app/app.component.ts',
53 `
54 import 'bootstrap';
55 import 'zone.js/dist/zone-error';
56 `,
57 );
58
59 harness.useTarget('build', {
60 ...BASE_OPTIONS,
61 allowedCommonJsDependencies: ['bootstrap', 'zone.js'],
62 });
63
64 const { result, logs } = await harness.executeOnce();
65
66 expect(result?.success).toBe(true);
67 expect(logs).not.toContain(
68 jasmine.objectContaining<logging.LogEntry>({
69 message: jasmine.stringMatching(/CommonJS or AMD dependencies/),
70 }),
71 );
72 });
73
74 it(`should not show warning when importing non global local data '@angular/common/locale/fr'`, async () => {
75 await harness.appendToFile(
76 'src/app/app.component.ts',
77 `import '@angular/common/locales/fr';`,
78 );
79
80 harness.useTarget('build', {
81 ...BASE_OPTIONS,
82 allowedCommonJsDependencies: [],
83 });
84
85 const { result, logs } = await harness.executeOnce();
86
87 expect(result?.success).toBe(true);
88 expect(logs).not.toContain(
89 jasmine.objectContaining<logging.LogEntry>({
90 message: jasmine.stringMatching(/CommonJS or AMD dependencies/),
91 }),
92 );
93 });
94
95 it('should not show warning in JIT for templateUrl and styleUrl when using paths', async () => {
96 await harness.modifyFile('tsconfig.json', (content) => {
97 return content.replace(
98 /"baseUrl": ".\/",/,
99 `
100 "baseUrl": "./",
101 "paths": {
102 "@app/*": [
103 "src/app/*"
104 ]
105 },
106 `,
107 );
108 });
109
110 await harness.modifyFile('src/app/app.module.ts', (content) =>
111 content.replace('./app.component', '@app/app.component'),
112 );
113
114 harness.useTarget('build', {
115 ...BASE_OPTIONS,
116 allowedCommonJsDependencies: [],
117 aot: false,
118 });
119
120 const { result, logs } = await harness.executeOnce();
121
122 expect(result?.success).toBe(true);
123 expect(logs).not.toContain(
124 jasmine.objectContaining<logging.LogEntry>({
125 message: jasmine.stringMatching(/CommonJS or AMD dependencies/),
126 }),
127 );
128 });
129 });
130 });