-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathbuild-browser-features_spec.ts
101 lines (81 loc) · 3.52 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
/**
* @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 { TestProjectHost } from '@angular-devkit/architect/testing';
import { getSystemPath, join, normalize } from '@angular-devkit/core';
import { ScriptTarget } from 'typescript';
import { BuildBrowserFeatures } from './build-browser-features';
const workspaceRoot = join(normalize(__dirname), '../../test/build-browser-features/');
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 IE 9-11 and ES2017', () => {
host.writeMultipleFiles({
'.browserslistrc': 'IE 9-11',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES2017)).toBe(true);
});
it('should be false for Chrome and ES2017', () => {
host.writeMultipleFiles({
'.browserslistrc': 'last 1 chrome version',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES2017)).toBe(false);
});
it('detects no need for differential loading for target is ES5', () => {
host.writeMultipleFiles({
'.browserslistrc': 'last 1 chrome version',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES5)).toBe(false);
});
it('should be false for Safari 10.1 when target is ES2017', () => {
host.writeMultipleFiles({
'.browserslistrc': 'Safari 10.1',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded(ScriptTarget.ES2017)).toBe(false);
});
});
describe('isFeatureSupported', () => {
it('should be true for es6-module and Safari 10.1', () => {
host.writeMultipleFiles({
'.browserslistrc': 'Safari 10.1',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
it('should be false for es6-module and IE9', () => {
host.writeMultipleFiles({
'.browserslistrc': 'IE 9',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(false);
});
it('should be true for es6-module and last 1 chrome version', () => {
host.writeMultipleFiles({
'.browserslistrc': 'last 1 chrome version',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
it('should be true for es6-module and Edge 18', () => {
host.writeMultipleFiles({
'.browserslistrc': 'Edge 18',
});
const buildBrowserFeatures = new BuildBrowserFeatures(workspaceRootSysPath);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
});
});