/
update-swcrc.spec.ts
95 lines (84 loc) · 2.56 KB
/
update-swcrc.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
import {
ProjectConfiguration,
readJson,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { libraryGenerator } from '@nrwl/workspace';
import { defaultExclude } from '../../utils/swc/add-swc-config';
import update from './update-swcrc';
describe('Migration: adjust .swcrc', () => {
let tree: Tree;
let projectConfiguration: ProjectConfiguration;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
libraryGenerator(tree, {
name: 'swc',
buildable: true,
linter: 'none',
unitTestRunner: 'none',
});
projectConfiguration = readProjectConfiguration(tree, 'swc');
updateProjectConfiguration(tree, 'swc', {
...projectConfiguration,
targets: {
...projectConfiguration.targets,
build: {
...projectConfiguration.targets['build'],
executor: '@nrwl/js:swc',
},
},
});
// re-read the project configuration
projectConfiguration = readProjectConfiguration(tree, 'swc');
});
it('should rename .swcrc to .lib.swcrc', async () => {
addSwcrc();
await update(tree);
expect(tree.exists('libs/swc/.swcrc')).toEqual(false);
expect(tree.exists('libs/swc/.lib.swcrc')).toEqual(true);
});
it('should assign default exclude if swcrc does not already have exclude', async () => {
addSwcrc();
await update(tree);
expect(readJson(tree, 'libs/swc/.lib.swcrc')['exclude']).toEqual(
defaultExclude
);
});
it('should use swcExclude (deprecated) to assign to exclude', async () => {
const swcExclude = ['./src/**/.*.spec.ts$'];
updateProjectConfiguration(tree, 'swc', {
...projectConfiguration,
targets: {
...projectConfiguration.targets,
build: {
...projectConfiguration.targets['build'],
options: {
...projectConfiguration.targets['build']['options'],
swcExclude,
},
},
},
});
addSwcrc();
await update(tree);
expect(readJson(tree, 'libs/swc/.lib.swcrc')['exclude']).toEqual(
swcExclude
);
});
it('should skip updating "exclude" if swcrc already has "exclude" field', async () => {
addSwcrc(true);
await update(tree);
expect(readJson(tree, 'libs/swc/.lib.swcrc')['exclude']).toEqual([
'./**/.*.spec.ts$',
]);
});
function addSwcrc(withExclude = false) {
tree.write(
'libs/swc/.swcrc',
JSON.stringify(withExclude ? { exclude: ['./**/.*.spec.ts$'] } : {})
);
}
});