From d7bd15b56daa686eaf4e01c13894f4907ea23719 Mon Sep 17 00:00:00 2001 From: Raanan Weber Date: Wed, 13 Nov 2024 11:44:30 +0100 Subject: [PATCH] Small changes to jest, including the recommended jest extension --- .vscode/extensions.json | 3 ++- jest.config.ts | 24 ++++++++++++------------ tsconfig.test.json | 4 +++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 1e743d6a223..32630fe8af2 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -6,6 +6,7 @@ "webhint.vscode-webhint", "IronGeek.vscode-env", "firsttris.vscode-jest-runner", - "ms-playwright.playwright" + "ms-playwright.playwright", + "orta.vscode-jest" ] } diff --git a/jest.config.ts b/jest.config.ts index 3ea3541bee3..99d6a0fd76f 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,7 +1,7 @@ import type { Config } from "@jest/types"; import * as fs from "fs"; import * as path from "path"; -import { pathsToModuleNameMapper } from "ts-jest"; +import { JestConfigWithTsJest, pathsToModuleNameMapper } from "ts-jest"; // const t = Object.assign(ts_preset, puppeteer_preset); @@ -14,7 +14,7 @@ const createProject = (type: string) => { const tsTestConfigPath = path.resolve(".", "tsconfig.test.json"); const globalSetup = fs.existsSync(setupFileLocation) ? setupFileLocation : undefined; const setupFilesAfterEnv = fs.existsSync(setupFilesAfterEnvLocation) ? [setupFilesAfterEnvLocation] : undefined; - const returnValue: Partial = { + const returnValue: Partial = { displayName: { name: type, color: "yellow", @@ -22,14 +22,17 @@ const createProject = (type: string) => { testRegex: [`/test/${type}/.*test\\.[tj]sx?$`], moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: "/packages/" }) as any, roots: [path.resolve(".")], - globals: { - "ts-jest": { - isolatedModules: true, - useESM: true, - tsconfig: fs.existsSync(tsTestConfigPath) ? tsTestConfigPath : fs.existsSync(tsConfigPath) ? tsConfigPath : path.resolve(__dirname, "tsconfig.json"), - }, - }, setupFilesAfterEnv: ["@alex_neo/jest-expect-message"], + transform: { + "^.+\\.tsx?$": [ + "ts-jest", + { + isolatedModules: true, + useESM: true, + tsconfig: fs.existsSync(tsTestConfigPath) ? tsTestConfigPath : fs.existsSync(tsConfigPath) ? tsConfigPath : path.resolve(__dirname, "tsconfig.json"), + }, + ], + }, }; if (globalSetup) { returnValue.globalSetup = globalSetup; @@ -59,9 +62,6 @@ const createProject = (type: string) => { globalTeardown: "jest-environment-puppeteer/teardown", testEnvironment: "jest-environment-puppeteer", preset: "jest-puppeteer", - transform: { - "^.+\\.ts$": "ts-jest", - }, extensionsToTreatAsEsm: [".ts"], }; } else if (type === "interactions") { diff --git a/tsconfig.test.json b/tsconfig.test.json index 584c93d0101..7d047eb49f4 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -1,5 +1,7 @@ { "extends": "./tsconfig.build.json", - "compilerOptions": {} + "compilerOptions": { + "esModuleInterop": true + } }