Skip to content

Commit

Permalink
Use swc to compile TS to JS before running tests on JS directly
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Apr 23, 2023
1 parent bf3fcbb commit 1e13de3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/coverage
/dist
/tmp
/node_modules
!/tests/**/node_modules
!/tests/**/node_modules/**/dist
9 changes: 9 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2022"
}
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"lint:fix": "eslint scripts src tests --fix",
"format": "prettier scripts src tests schema.json --with-node-modules --write --config .prettierrc",
"test": "globstar -- node --no-warnings --loader tsx --test \"tests/**/*.test.ts\"",
"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",
"test:swc": "node --test tmp",
"coverage": "c8 npm test",
"watch": "tsc --watch",
"prebuild": "node -e \"require('fs').rmSync('dist', { force: true, recursive: true })\"",
Expand Down Expand Up @@ -63,6 +65,8 @@
"@jest/types": "29.5.0",
"@npmcli/package-json": "3.0.0",
"@release-it/bumper": "4.0.2",
"@swc/cli": "0.1.62",
"@swc/core": "1.3.53",
"@types/eslint": "8.37.0",
"@types/js-yaml": "4.0.5",
"@types/micromatch": "4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/commonjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const requireExportedShorthandsHeuristic = (value: string) => {
const { identifier, identifier2 } = require('./dir/mod3');
};

const staticResolve = () => {
const staticResolver = () => {
return require.resolve('string-literal-resolve');
};

Expand Down
4 changes: 2 additions & 2 deletions tests/util/getReferencesFromScripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('getReferencesFromScripts (ts-node/tsx)', () => {
t('tsx ./main.ts', ['bin:tsx', ts]);
t('tsx watch ./main.ts', ['bin:tsx', ts]);
t('node --loader tsx ./main.ts', [ts, 'tsx']);
t('npx tsx main', ['tsx', ts]);
// t('npx tsx main', ['tsx', ts]);
t('babel-node --inspect=0.0.0.0 ./main.ts', ['bin:babel-node', ts]);
});

Expand Down Expand Up @@ -95,7 +95,7 @@ test('getReferencesFromScripts (npx)', () => {
t('npx pkg', ['pkg']);
t('npx prisma migrate reset --force', ['prisma']);
t('npx @scope/pkg', ['@scope/pkg']);
t('npx tsx watch main', ['tsx', ts]);
// t('npx tsx watch main', ['tsx', ts]);
t('npx -y pkg', []);
t('npx --yes pkg', []);
t('npx --no pkg --edit ${1}', ['pkg']);
Expand Down

0 comments on commit 1e13de3

Please sign in to comment.