Created
March 6, 2024 20:05
-
-
Save rafa-thayto/2d8d58a66c0e6a94be30aacc3959383c to your computer and use it in GitHub Desktop.
Jest config with swc and typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
| { | |
| "$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" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | |
| }, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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