-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.config.spec.ts
169 lines (159 loc) · 4.24 KB
/
web.config.spec.ts
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { getWebConfig as getWebPartial } from './web.config';
jest.mock('tsconfig-paths-webpack-plugin');
import TsConfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import { createConsoleLogger } from '@angular-devkit/core/node';
import { Logger } from '@angular-devkit/core/src/logger';
import * as ts from 'typescript';
import { WebBuildBuilderOptions } from '../builders/build/build.impl';
import { join } from 'path';
describe('getWebConfig', () => {
let input: WebBuildBuilderOptions;
let logger: Logger;
let root: string;
let sourceRoot: string;
let mockCompilerOptions: any;
beforeEach(() => {
input = {
main: 'main.ts',
index: 'index.html',
budgets: [],
baseHref: '/',
deployUrl: '/',
sourceMap: {
scripts: true,
styles: true,
hidden: false,
vendors: false
},
optimization: {
scripts: false,
styles: false
},
styles: [],
scripts: [],
outputPath: 'dist',
tsConfig: 'tsconfig.json',
fileReplacements: []
};
root = join(__dirname, '../../../..');
sourceRoot = join(root, 'apps/app');
logger = createConsoleLogger();
mockCompilerOptions = {
target: 'es2015',
paths: { path: ['mapped/path'] }
};
(<any>TsConfigPathsPlugin).mockImplementation(
function MockPathsPlugin() {}
);
spyOn(ts, 'readConfigFile').and.callFake(() => ({
config: {
compilerOptions: mockCompilerOptions
}
}));
});
it('should resolve the browser main field', () => {
const result = getWebPartial(root, sourceRoot, input, logger, false, false);
expect(result.resolve.mainFields).toContain('browser');
});
describe('without differential loading', () => {
describe('polyfills', () => {
it('should set the polyfills entry', () => {
const result = getWebPartial(
root,
sourceRoot,
{
...input,
polyfills: 'polyfills.ts'
},
logger,
false,
false
);
expect(result.entry.polyfills).toEqual(['polyfills.ts']);
});
});
describe('es2015 polyfills', () => {
it('should set the es2015-polyfills', () => {
const result = getWebPartial(
root,
sourceRoot,
{
...input,
es2015Polyfills: 'polyfills.es2015.ts'
},
logger,
false,
false
);
expect(result.entry['polyfills-es5']).toEqual(['polyfills.es2015.ts']);
});
});
});
describe('with differential loading', () => {
describe('polyfills', () => {
it('should be in both polyfills', () => {
const es2015Config = getWebPartial(
root,
sourceRoot,
{
...input,
polyfills: 'polyfills.ts'
},
logger,
true,
true
);
expect(es2015Config.entry.polyfills).toContain('polyfills.ts');
const es5Config = getWebPartial(
root,
sourceRoot,
{
...input,
polyfills: 'polyfills.ts'
},
logger,
false,
true
);
expect(es5Config.entry.polyfills).toContain('polyfills.ts');
});
});
describe('es2015Polyfills', () => {
it('should be in es5 polyfills', () => {
const es5Config = getWebPartial(
root,
sourceRoot,
{
...input,
polyfills: 'polyfills.ts',
es2015Polyfills: 'polyfills.es2015.ts'
},
logger,
false,
true
);
expect(es5Config.entry.polyfills).toContain('polyfills.es2015.ts');
});
});
describe('safari polyfills', () => {
it('should be in es2015 polyfills', () => {
const es2015Config = getWebPartial(
root,
sourceRoot,
{
...input,
polyfills: 'polyfills.ts'
},
logger,
true,
true
);
expect(es2015Config.entry.polyfills).toContain(
require.resolve(
'@nrwl/web/src/utils/third-party/cli-files/models/safari-nomodule.js'
)
);
});
});
});
});