From e9515ca454a9d544d1f48eacc1bdc25e6da490b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Rodrigues=20de=20Alc=C3=A2ntara?= Date: Sun, 2 Jun 2024 23:21:48 -0300 Subject: [PATCH] chore(tests): Convert jest config to js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Which seems to speed up the tests execution. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 1.417s ± 0.053s [User: 0.887s, System: 0.113s] Range (min … max): 1.368s … 1.775s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 2.110s ± 0.021s [User: 2.571s, System: 0.216s] Range (min … max): 2.078s … 2.193s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.493s ± 0.010s [User: 0.787s, System: 0.134s] Range (min … max): 1.460s … 1.540s 100 runs --- apps/app/jest.config.js | 25 +++++++++++++++++++++++++ apps/app/jest.config.ts | 11 ----------- apps/app/tsconfig.app.json | 2 +- apps/app/tsconfig.spec.json | 2 +- jest.config.js | 7 +++++++ jest.config.ts | 5 ----- 6 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 apps/app/jest.config.js delete mode 100644 apps/app/jest.config.ts create mode 100644 jest.config.js delete mode 100644 jest.config.ts diff --git a/apps/app/jest.config.js b/apps/app/jest.config.js new file mode 100644 index 0000000..83e5516 --- /dev/null +++ b/apps/app/jest.config.js @@ -0,0 +1,25 @@ +let jestConfigObject = { + displayName: 'app', + preset: '../../jest.preset.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }] + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/apps/app' +} + +if (process.env.NODE_ENV === 'CI' || process.env.CI === 'true') { + jestConfigObject.transform = { + '^.+\\.[tj]s$': [ + 'ts-jest', + { + tsconfig: '/tsconfig.spec.json', + isolatedModules: true, + diagnostics: false + } + ] + } +} + +module.exports = jestConfigObject diff --git a/apps/app/jest.config.ts b/apps/app/jest.config.ts deleted file mode 100644 index 644717d..0000000 --- a/apps/app/jest.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable */ -export default { - displayName: 'app', - preset: '../../jest.preset.js', - testEnvironment: 'node', - transform: { - '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], - }, - moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../coverage/apps/app', -}; diff --git a/apps/app/tsconfig.app.json b/apps/app/tsconfig.app.json index a2ce765..2ebd6ce 100644 --- a/apps/app/tsconfig.app.json +++ b/apps/app/tsconfig.app.json @@ -7,6 +7,6 @@ "emitDecoratorMetadata": true, "target": "es2021" }, - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], + "exclude": ["jest.config.js", "src/**/*.spec.ts", "src/**/*.test.ts"], "include": ["src/**/*.ts"] } diff --git a/apps/app/tsconfig.spec.json b/apps/app/tsconfig.spec.json index 9b2a121..c49cfea 100644 --- a/apps/app/tsconfig.spec.json +++ b/apps/app/tsconfig.spec.json @@ -6,7 +6,7 @@ "types": ["jest", "node"] }, "include": [ - "jest.config.ts", + "jest.config.js", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts" diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..cd9828a --- /dev/null +++ b/jest.config.js @@ -0,0 +1,7 @@ +process.env.TZ = 'UTC' + +const { getJestProjectsAsync } = require('@nx/jest') + +module.exports = { + projects: await getJestProjectsAsync() +} diff --git a/jest.config.ts b/jest.config.ts deleted file mode 100644 index 6b3f2d6..0000000 --- a/jest.config.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { getJestProjectsAsync } from '@nx/jest'; - -export default async () => ({ - projects: await getJestProjectsAsync(), -});