-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
js-swc.test.ts
119 lines (100 loc) · 3.4 KB
/
js-swc.test.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
import { satisfies } from 'semver';
import {
checkFilesDoNotExist,
checkFilesExist,
cleanupProject,
detectPackageManager,
newProject,
packageManagerLockFile,
readJson,
runCLI,
runCLIAsync,
tmpProjPath,
uniq,
updateFile,
updateJson,
} from '../../utils';
describe('js e2e', () => {
let scope: string;
beforeEach(() => {
scope = newProject();
});
afterEach(() => cleanupProject());
it('should create libs with js executors (--compiler=swc)', async () => {
const lib = uniq('lib');
runCLI(
`generate @nrwl/js:lib ${lib} --buildable --compiler=swc --no-interactive`
);
const libPackageJson = readJson(`libs/${lib}/package.json`);
expect(libPackageJson.scripts).toBeUndefined();
expect(runCLI(`build ${lib}`)).toContain(
'Successfully compiled: 2 files with swc'
);
checkFilesExist(
`dist/libs/${lib}/package.json`,
`dist/libs/${lib}/src/index.js`,
`dist/libs/${lib}/src/lib/${lib}.js`,
`dist/libs/${lib}/src/index.d.ts`,
`dist/libs/${lib}/src/lib/${lib}.d.ts`
);
checkFilesDoNotExist(`libs/${lib}/.babelrc`);
const parentLib = uniq('parentlib');
runCLI(
`generate @nrwl/js:lib ${parentLib} --buildable --compiler=swc --no-interactive`
);
const parentLibPackageJson = readJson(`libs/${parentLib}/package.json`);
expect(parentLibPackageJson.scripts).toBeUndefined();
expect((await runCLIAsync(`test ${parentLib}`)).combinedOutput).toContain(
'Ran all test suites'
);
expect(runCLI(`build ${parentLib}`)).toContain(
'Successfully compiled: 2 files with swc'
);
checkFilesExist(
`dist/libs/${parentLib}/package.json`,
`dist/libs/${parentLib}/src/index.js`,
`dist/libs/${parentLib}/src/lib/${parentLib}.js`,
`dist/libs/${parentLib}/src/index.d.ts`,
`dist/libs/${parentLib}/src/lib/${parentLib}.d.ts`
);
const tsconfig = readJson(`tsconfig.base.json`);
expect(tsconfig.compilerOptions.paths).toEqual({
[`@${scope}/${lib}`]: [`libs/${lib}/src/index.ts`],
[`@${scope}/${parentLib}`]: [`libs/${parentLib}/src/index.ts`],
});
updateFile(`libs/${parentLib}/src/index.ts`, () => {
return `
import { ${lib} } from '@${scope}/${lib}';
export * from './lib/${parentLib}';
`;
});
const output = runCLI(`build ${parentLib}`);
expect(output).toContain('1 task it depends on');
expect(output).toContain('Successfully compiled: 2 files with swc');
runCLI(`build ${parentLib} --generateLockfile=true`);
checkFilesExist(
`dist/libs/${parentLib}/package.json`,
`dist/libs/${parentLib}/${
packageManagerLockFile[detectPackageManager(tmpProjPath())]
}`
);
updateJson(`libs/${lib}/.lib.swcrc`, (json) => {
json.jsc.externalHelpers = true;
return json;
});
runCLI(`build ${lib}`);
const swcHelpersFromRoot =
readJson(`package.json`).dependencies['@swc/helpers'];
const swcHelpersFromDist = readJson(`dist/libs/${lib}/package.json`)
.peerDependencies['@swc/helpers'];
expect(satisfies(swcHelpersFromDist, swcHelpersFromRoot)).toBeTruthy();
updateJson(`libs/${lib}/.lib.swcrc`, (json) => {
json.jsc.externalHelpers = false;
return json;
});
runCLI(`build ${lib}`);
expect(readJson(`dist/libs/${lib}/package.json`)).not.toHaveProperty(
'peerDependencies.@swc/helpers'
);
}, 240_000);
});