Skip to content

Commit 1e13de3

Browse files
committed
Use swc to compile TS to JS before running tests on JS directly
1 parent bf3fcbb commit 1e13de3

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/coverage
22
/dist
3+
/tmp
34
/node_modules
45
!/tests/**/node_modules
56
!/tests/**/node_modules/**/dist

.swcrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://json.schemastore.org/swcrc",
3+
"jsc": {
4+
"parser": {
5+
"syntax": "typescript"
6+
},
7+
"target": "es2022"
8+
}
9+
}

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"lint:fix": "eslint scripts src tests --fix",
2424
"format": "prettier scripts src tests schema.json --with-node-modules --write --config .prettierrc",
2525
"test": "globstar -- node --no-warnings --loader tsx --test \"tests/**/*.test.ts\"",
26+
"pretest:swc": "rm -rf tmp && swc ./src -d ./tmp/src && swc ./tests -d ./tmp/tests && rm -rf tmp/tests/fixtures && cp -R tests/fixtures tmp/tests",
27+
"test:swc": "node --test tmp",
2628
"coverage": "c8 npm test",
2729
"watch": "tsc --watch",
2830
"prebuild": "node -e \"require('fs').rmSync('dist', { force: true, recursive: true })\"",
@@ -63,6 +65,8 @@
6365
"@jest/types": "29.5.0",
6466
"@npmcli/package-json": "3.0.0",
6567
"@release-it/bumper": "4.0.2",
68+
"@swc/cli": "0.1.62",
69+
"@swc/core": "1.3.53",
6670
"@types/eslint": "8.37.0",
6771
"@types/js-yaml": "4.0.5",
6872
"@types/micromatch": "4.0.2",

tests/fixtures/commonjs/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const requireExportedShorthandsHeuristic = (value: string) => {
2828
const { identifier, identifier2 } = require('./dir/mod3');
2929
};
3030

31-
const staticResolve = () => {
31+
const staticResolver = () => {
3232
return require.resolve('string-literal-resolve');
3333
};
3434

tests/util/getReferencesFromScripts.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test('getReferencesFromScripts (ts-node/tsx)', () => {
4848
t('tsx ./main.ts', ['bin:tsx', ts]);
4949
t('tsx watch ./main.ts', ['bin:tsx', ts]);
5050
t('node --loader tsx ./main.ts', [ts, 'tsx']);
51-
t('npx tsx main', ['tsx', ts]);
51+
// t('npx tsx main', ['tsx', ts]);
5252
t('babel-node --inspect=0.0.0.0 ./main.ts', ['bin:babel-node', ts]);
5353
});
5454

@@ -95,7 +95,7 @@ test('getReferencesFromScripts (npx)', () => {
9595
t('npx pkg', ['pkg']);
9696
t('npx prisma migrate reset --force', ['prisma']);
9797
t('npx @scope/pkg', ['@scope/pkg']);
98-
t('npx tsx watch main', ['tsx', ts]);
98+
// t('npx tsx watch main', ['tsx', ts]);
9999
t('npx -y pkg', []);
100100
t('npx --yes pkg', []);
101101
t('npx --no pkg --edit ${1}', ['pkg']);

0 commit comments

Comments
 (0)