Skip to content

Instantly share code, notes, and snippets.

@rafa-thayto
Created March 6, 2024 20:05
Show Gist options
  • Select an option

  • Save rafa-thayto/2d8d58a66c0e6a94be30aacc3959383c to your computer and use it in GitHub Desktop.

Select an option

Save rafa-thayto/2d8d58a66c0e6a94be30aacc3959383c to your computer and use it in GitHub Desktop.
Jest config with swc and typescript
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"target": "es2020",
"baseUrl": ".",
"parser": {
"syntax": "typescript",
"tsx": false,
"dynamicImport": true
},
"paths": {
"@/*": ["./src/*"]
},
"minify": {
"compress": true,
"mangle": true
}
},
"minify": true,
"sourceMaps": true,
"module": {
"type": "es6"
}
}
const fs = require('fs');
const config = JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, 'utf-8'));
/** @type {import('jest').Config} */
module.exports = {
rootDir: process.cwd(),
verbose: true,
extensionsToTreatAsEsm: ['.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.(t|j)s?$': [
'@swc/jest',
{ ...config /* custom configuration in Jest */ },
],
},
collectCoverageFrom: ['src/**/*.[jt]s?', '!src/**/*.d.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};
{
"test:jest": "NODE_OPTIONS=--experimental-vm-modules jest",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
"coverage:jest": "NODE_OPTIONS=--experimental-vm-modules c8 jest --coverage",
"make-badges": "istanbul-badges-readme",
"quality": "jscpd"
}
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ESNext"],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"removeComments": true,
"sourceMap": true,
"noUnusedLocals": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"skipLibCheck": true,
"types": ["node", "jest"],
"strict": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment