/
exclude-jest-config-swcrc.spec.ts
89 lines (82 loc) · 2.27 KB
/
exclude-jest-config-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
import {
addProjectConfiguration,
readJson,
Tree,
updateJson,
} from '@nrwl/devkit';
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing';
import { excludeJestConfigSwcrc } from './exclude-jest-config-swcrc';
import { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';
const projectConfig: ProjectConfiguration = {
root: 'libs/swc-lib',
sourceRoot: 'libs/swc-lib/src',
targets: {
build: {
executor: '@nrwl/js:swc',
outputs: ['{options.outputPath}'],
options: {
outputPath: 'dist/libs/swc-lib',
main: 'libs/swc-lib/src/index.ts',
tsConfig: 'libs/swc-lib/tsconfig.lib.json',
assets: ['libs/swc-lib/*.md'],
},
},
},
};
const oldSwcRc = {
jsc: {
target: 'es2017',
parser: {
syntax: 'typescript',
decorators: true,
dynamicImport: true,
},
transform: {
decoratorMetadata: true,
legacyDecorator: true,
},
keepClassNames: true,
externalHelpers: true,
loose: true,
},
module: {
type: 'commonjs',
strict: true,
noInterop: true,
},
sourceMaps: true,
exclude: [
'.*\\.spec.tsx?$',
'.*\\.test.tsx?$',
'./src/jest-setup.ts$',
'./**/jest-setup.ts$',
'.*.js$',
],
};
describe('JS Migration (v14.0.0)', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyV1Workspace();
addProjectConfiguration(tree, 'swc-lib', projectConfig);
tree.write('libs/swc-lib/.lib.swcrc', JSON.stringify(oldSwcRc));
});
it('should update the exclude pattern', () => {
excludeJestConfigSwcrc(tree);
expect(tree.read('libs/swc-lib/.lib.swcrc', 'utf-8')).toMatchSnapshot();
});
it('should NOT update the exclude pattern if not present', () => {
updateJson(tree, 'libs/swc-lib/.lib.swcrc', (json) => {
delete json.exclude;
return json;
});
const before = readJson(tree, 'libs/swc-lib/.lib.swcrc');
excludeJestConfigSwcrc(tree);
const after = readJson(tree, 'libs/swc-lib/.lib.swcrc');
expect(after.exclude).toBeFalsy();
expect(after).toEqual(before);
});
it('should do nothing if .lib.swcrc doest not exist', () => {
tree.delete('libs/swc-lib/.lib-swcrc');
expect(() => excludeJestConfigSwcrc(tree)).not.toThrowError();
});
});