-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathbuild-browser-features_spec.ts
195 lines (163 loc) · 5.73 KB
/
build-browser-features_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
* @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 { TestProjectHost } from '@angular-devkit/architect/testing';
import { getSystemPath, join } from '@angular-devkit/core';
import { ScriptTarget } from 'typescript';
import { BuildBrowserFeatures } from './build-browser-features';
const devkitRoot = (global as any)._DevKitRoot; // tslint:disable-line:no-any
const workspaceRoot = join(
devkitRoot,
'tests/angular_devkit/build_angular/hello-world-app/');
const host = new TestProjectHost(workspaceRoot);
describe('BuildBrowserFeatures', () => {
let workspaceRootSysPath = '';
beforeEach(async () => {
await host.initialize().toPromise();
workspaceRootSysPath = getSystemPath(host.root());
});
afterEach(async () => host.restore().toPromise());
describe('isDifferentialLoadingNeeded', () => {
it('should be true for for IE 9-11 and ES2015', () => {
host.writeMultipleFiles({
'browserslist': 'IE 9-11',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(true);
});
it('should be false for Chrome and ES2015', () => {
host.writeMultipleFiles({
'browserslist': 'last 1 chrome version',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
});
it('detects no need for differential loading for target is ES5', () => {
host.writeMultipleFiles({
'browserslist': 'last 1 chrome version',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES5,
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
});
it('should be false for Safari 10.1 when target is ES2015', () => {
host.writeMultipleFiles({
'browserslist': 'Safari 10.1',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
});
});
describe('isFeatureSupported', () => {
it('should be true for es6-module and Safari 10.1', () => {
host.writeMultipleFiles({
'browserslist': 'Safari 10.1',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
it('should be false for es6-module and IE9', () => {
host.writeMultipleFiles({
'browserslist': 'IE 9',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(false);
});
it('should be true for es6-module and last 1 chrome version', () => {
host.writeMultipleFiles({
'browserslist': 'last 1 chrome version',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
it('should be true for es6-module and Edge 18', () => {
host.writeMultipleFiles({
'browserslist': 'Edge 18',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
});
describe('isNoModulePolyfillNeeded', () => {
it('should be false for Safari 10.1 when target is ES5', () => {
host.writeMultipleFiles({
'browserslist': 'Safari 10.1',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES5,
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);
});
it('should be false for Safari 10.1 when target is ES2015', () => {
host.writeMultipleFiles({
'browserslist': 'Safari 10.1',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);
});
it('should be true for Safari 9+ when target is ES2015', () => {
host.writeMultipleFiles({
'browserslist': 'Safari >= 9',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(true);
});
it('should be false for Safari 9+ when target is ES5', () => {
host.writeMultipleFiles({
'browserslist': 'Safari >= 9',
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES5,
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);
});
it('should be false when not supporting Safari 10.1 target is ES2015', () => {
host.writeMultipleFiles({
'browserslist': `
Edge 18
IE 9
`,
});
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
ScriptTarget.ES2015,
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);
});
});
});