Skip to content

Commit

Permalink
chore(apps/app): Setup SWC tests compilation
Browse files Browse the repository at this point in the history
To speed up tests execution.

hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \
                    --runs 100 "nx run-many -t lint"
  Time (mean ± σ):    2.759s ±  0.027s  [User: 3.324s, System: 0.219s]
  Range (min … max):  2.690s …  2.870s  100 runs

hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \
                    --runs 100 "nx run-many -t build"
  Time (mean ± σ):    1.815s ±  0.018s  [User: 1.763s, System: 0.140s]
  Range (min … max):  1.775s …  1.904s  100 runs

hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \
                    --runs 100 "nx run-many -t test"
  Time (mean ± σ):    1.668s ±  0.008s  [User: 0.802s, System: 0.137s]
  Range (min … max):  1.643s …  1.689s  100 runs

More:
- https://docs.nestjs.com/recipes/swc#monorepo
- nrwl/nx#11289 (comment)
- jestjs/jest#9430
- https://npmjs.com/package/jest_workaround
  • Loading branch information
roalcantara committed Jun 3, 2024
1 parent 7175602 commit 2689c86
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
40 changes: 24 additions & 16 deletions apps/app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
let jestConfigObject = {
module.exports = {
displayName: 'app',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/my-nutri'
}

if (process.env.NODE_ENV === 'CI' || process.env.CI === 'true') {
jestConfigObject.transform = {
'^.+\\.[tj]s$': [
'ts-jest',
'@swc/jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
isolatedModules: true,
diagnostics: false
sourceMaps: true,
module: {
type: 'commonjs',
strict: true,
strictMode: true
},
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
dynamicImport: true
},
transform: {
legacyDecorator: true,
decoratorMetadata: true
},
target: 'es2021'
},
minify: false
}
]
}
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageDirectory: '../../coverage/apps/app'
}

module.exports = jestConfigObject
11 changes: 9 additions & 2 deletions apps/app/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"target": "es2021",
"lib": ["es2021"],
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": [
"jest.config.js",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@swc/cli": "^0.3.12",
"@swc/core": "^1.5.24",
"@swc/helpers": "^0.5.11",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"@types/node": "~20.14.0",
"@typescript-eslint/eslint-plugin": "^7.12.0",
Expand Down
18 changes: 17 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,13 @@
slash "^3.0.0"
strip-ansi "^6.0.0"

"@jest/create-cache-key-function@^29.7.0":
version "29.7.0"
resolved "https://registry.yarnpkg.com/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz#793be38148fab78e65f40ae30c36785f4ad859f0"
integrity sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==
dependencies:
"@jest/types" "^29.6.3"

"@jest/environment@^29.7.0":
version "29.7.0"
resolved "https://registry.yarnpkg.com/@jest/environment/-/environment-29.7.0.tgz#24d61f54ff1f786f3cd4073b4b94416383baf2a7"
Expand Down Expand Up @@ -2061,6 +2068,15 @@
dependencies:
tslib "^2.4.0"

"@swc/jest@^0.2.36":
version "0.2.36"
resolved "https://registry.yarnpkg.com/@swc/jest/-/jest-0.2.36.tgz#2797450a30d28b471997a17e901ccad946fe693e"
integrity sha512-8X80dp81ugxs4a11z1ka43FPhP+/e+mJNXJSxiNYk8gIX/jPBtY4gQTrKu/KIoco8bzKuPI5lUxjfLiGsfvnlw==
dependencies:
"@jest/create-cache-key-function" "^29.7.0"
"@swc/counter" "^0.1.3"
jsonc-parser "^3.2.0"

"@swc/types@^0.1.7":
version "0.1.7"
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.7.tgz#ea5d658cf460abff51507ca8d26e2d391bafb15e"
Expand Down Expand Up @@ -6235,7 +6251,7 @@ jsonc-parser@3.2.0:
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76"
integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==

jsonc-parser@3.2.1:
jsonc-parser@3.2.1, jsonc-parser@^3.2.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.1.tgz#031904571ccf929d7670ee8c547545081cb37f1a"
integrity sha512-AilxAyFOAcK5wA1+LeaySVBrHsGQvUFCDWXKpZjzaL0PqW+xfBOttn8GNtWKFWqneyMZj41MWF9Kl6iPWLwgOA==
Expand Down

0 comments on commit 2689c86

Please sign in to comment.