/
remove-browserslist-config_spec.ts
84 lines (67 loc) · 3.3 KB
/
remove-browserslist-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
/**
* @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 { EmptyTree } from '@angular-devkit/schematics';
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import { DEFAULT_BROWSERS } from './remove-browserslist-config';
describe('Migration to delete Browserslist configurations', () => {
const schematicName = 'remove-browserslist-config';
const schematicRunner = new SchematicTestRunner(
'migrations',
require.resolve('../migration-collection.json'),
);
let tree: UnitTestTree;
beforeEach(() => {
tree = new UnitTestTree(new EmptyTree());
});
describe('given the Browserslist config matches the default', () => {
it('should delete ".browserslistrc" file', async () => {
tree.create('/src/app/.browserslistrc', DEFAULT_BROWSERS.join('\n'));
expect(tree.exists('/src/app/.browserslistrc')).toBeTrue();
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(newTree.exists('/src/app/.browserslistrc')).toBeFalse();
});
it(`should not delete "browserslist" in 'node_modules'`, async () => {
tree.create('/node_modules/browserslist', DEFAULT_BROWSERS.join('\n'));
tree.create('/node_modules/.browserslistrc', DEFAULT_BROWSERS.join('\n'));
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(newTree.exists('/node_modules/browserslist')).toBeTrue();
expect(newTree.exists('/node_modules/.browserslistrc')).toBeTrue();
});
});
describe('given the Browserslist config does not match the default', () => {
it('should not delete "browserslist"', async () => {
tree.create('/src/app/browserslist', 'last 1 Chrome version');
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(newTree.exists('/src/app/browserslist')).toBeTrue();
});
it('should not delete ".browserslistrc"', async () => {
tree.create('/src/app/.browserslistrc', 'last 1 Chrome version');
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(newTree.exists('/src/app/.browserslistrc')).toBeTrue();
});
it('should delete ".browserslistrc" file when it only includes non supported ES5 browsers', async () => {
tree.create('/src/app/.browserslistrc', [...DEFAULT_BROWSERS, 'IE 10'].join('\n'));
expect(tree.exists('/src/app/.browserslistrc')).toBeTrue();
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(newTree.exists('/src/app/.browserslistrc')).toBeFalse();
});
it('should not delete ".browserslistrc" file when it includes additional config sections', async () => {
tree.create(
'/src/app/.browserslistrc',
`
${DEFAULT_BROWSERS.join('\n')}
[modern]
last 1 chrome version
`,
);
expect(tree.exists('/src/app/.browserslistrc')).toBeTrue();
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
expect(newTree.exists('/src/app/.browserslistrc')).toBeTrue();
});
});
});