Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ddf5381

Browse files
committedJun 4, 2024
chore(apps/app): Setup SWC tests compilation
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.751s ± 0.040s [User: 3.329s, System: 0.220s] Range (min…max): 2.692s … 2.861s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.785s ± 0.017s [User: 1.751s, System: 0.139s] Range (min…max): 1.750s … 1.834s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.657s ± 0.006s [User: 0.800s, System: 0.139s] Range (min…max): 1.623s … 1.679s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
1 parent f62782c commit ddf5381

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed
 

‎apps/app/jest.config.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
let jestConfigObject = {
1+
module.exports = {
22
displayName: 'app',
33
preset: '../../jest.preset.js',
44
testEnvironment: 'node',
55
transform: {
6-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
7-
},
8-
moduleFileExtensions: ['ts', 'js', 'html'],
9-
coverageDirectory: '../../coverage/apps/app'
10-
}
11-
12-
if (process.env.NODE_ENV === 'CI' || process.env.CI === 'true') {
13-
jestConfigObject.transform = {
146
'^.+\\.[tj]s$': [
15-
'ts-jest',
7+
'@swc/jest',
168
{
17-
tsconfig: '<rootDir>/tsconfig.spec.json',
18-
isolatedModules: true,
19-
diagnostics: false
9+
sourceMaps: true,
10+
module: {
11+
type: 'commonjs',
12+
strict: true,
13+
strictMode: true
14+
},
15+
jsc: {
16+
parser: {
17+
syntax: 'typescript',
18+
decorators: true,
19+
dynamicImport: true
20+
},
21+
transform: {
22+
legacyDecorator: true,
23+
decoratorMetadata: true
24+
},
25+
target: 'es2021'
26+
},
27+
minify: false
2028
}
2129
]
22-
}
30+
},
31+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
32+
coverageDirectory: '../../coverage/apps/app'
2333
}
24-
25-
module.exports = jestConfigObject

‎apps/app/tsconfig.spec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"src/**/*.spec.ts",
1212
"src/**/*.d.ts"
1313
]
14-
}
14+
}

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@swc/cli": "^0.3.12",
3939
"@swc/core": "^1.5.24",
4040
"@swc/helpers": "^0.5.11",
41+
"@swc/jest": "^0.2.36",
4142
"@types/jest": "^29.5.12",
4243
"@types/node": "~20.14.1",
4344
"@typescript-eslint/eslint-plugin": "^7.12.0",

‎yarn.lock

+17-1
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,13 @@
12341234
slash "^3.0.0"
12351235
strip-ansi "^6.0.0"
12361236

1237+
"@jest/create-cache-key-function@^29.7.0":
1238+
version "29.7.0"
1239+
resolved "https://registry.yarnpkg.com/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz#793be38148fab78e65f40ae30c36785f4ad859f0"
1240+
integrity sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==
1241+
dependencies:
1242+
"@jest/types" "^29.6.3"
1243+
12371244
"@jest/environment@^29.7.0":
12381245
version "29.7.0"
12391246
resolved "https://registry.yarnpkg.com/@jest/environment/-/environment-29.7.0.tgz#24d61f54ff1f786f3cd4073b4b94416383baf2a7"
@@ -2061,6 +2068,15 @@
20612068
dependencies:
20622069
tslib "^2.4.0"
20632070

2071+
"@swc/jest@^0.2.36":
2072+
version "0.2.36"
2073+
resolved "https://registry.yarnpkg.com/@swc/jest/-/jest-0.2.36.tgz#2797450a30d28b471997a17e901ccad946fe693e"
2074+
integrity sha512-8X80dp81ugxs4a11z1ka43FPhP+/e+mJNXJSxiNYk8gIX/jPBtY4gQTrKu/KIoco8bzKuPI5lUxjfLiGsfvnlw==
2075+
dependencies:
2076+
"@jest/create-cache-key-function" "^29.7.0"
2077+
"@swc/counter" "^0.1.3"
2078+
jsonc-parser "^3.2.0"
2079+
20642080
"@swc/types@^0.1.7":
20652081
version "0.1.7"
20662082
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.7.tgz#ea5d658cf460abff51507ca8d26e2d391bafb15e"
@@ -6235,7 +6251,7 @@ jsonc-parser@3.2.0:
62356251
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76"
62366252
integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==
62376253

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

0 commit comments

Comments
 (0)
Please sign in to comment.