From abbd60d7e22d9685d794eda75b2ec4a54049ddd1 Mon Sep 17 00:00:00 2001 From: TheSparta Date: Thu, 26 Oct 2023 21:01:38 +0100 Subject: [PATCH] Switched from ts-jest to @swc/jest --- project/.swcrc | 4 +++- project/jest.config.ts | 14 +++++++------- project/package.json | 3 ++- project/tests/CustomEnvironment.ts | 9 +++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/project/.swcrc b/project/.swcrc index 466d5cfc..62bb0a3e 100644 --- a/project/.swcrc +++ b/project/.swcrc @@ -12,12 +12,14 @@ "target": "es2022", "loose": true, "externalHelpers": false, - // Requires v1.2.50 or upper and requires target to be es2016 or upper. "keepClassNames": true, "baseUrl": "./", "paths": { "@spt-aki/*": [ "src/*" + ], + "@tests/*": [ + "tests/*" ] } }, diff --git a/project/jest.config.ts b/project/jest.config.ts index 14e8c2b0..252cb7f8 100644 --- a/project/jest.config.ts +++ b/project/jest.config.ts @@ -1,15 +1,15 @@ -import type { JestConfigWithTsJest } from "ts-jest"; -import { pathsToModuleNameMapper } from "ts-jest"; -import { compilerOptions } from "./tsconfig.json"; +/* eslint-disable @typescript-eslint/naming-convention */ +import type { Config } from "jest"; +import fs from "fs"; -const config: JestConfigWithTsJest = { - preset: "ts-jest", +const config: Config = { testEnvironment: "./tests/CustomEnvironment.ts", roots: [ "./tests/" ], - modulePaths: [ compilerOptions.baseUrl ], - moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths) + transform: { + "^.+\\.ts$": [ "@swc/jest", JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, "utf-8")) ] + } }; export default config; diff --git a/project/package.json b/project/package.json index b101acf0..fbacf47d 100644 --- a/project/package.json +++ b/project/package.json @@ -44,6 +44,7 @@ "devDependencies": { "@babel/preset-env": "7.23.2", "@babel/preset-typescript": "7.23.2", + "@jest/environment": "^29.7.0", "@jest/globals": "29.7.0", "@pnpm/exe": "8.9.0", "@swc/cli": "0.1.62", @@ -63,12 +64,12 @@ "gulp-execa": "5.0.1", "gulp-rename": "2.0.0", "jest": "29.7.0", + "jest-environment-node": "^29.7.0", "madge": "6.1.0", "pkg": "5.8.1", "pkg-fetch": "3.5.2", "resedit": "2.0.0", "rome": "12.1.3", - "ts-jest": "29.1.1", "ts-node-dev": "2.0.0", "tsconfig-paths": "4.2.0", "typedoc": "0.25.2", diff --git a/project/tests/CustomEnvironment.ts b/project/tests/CustomEnvironment.ts index 6ab3b87d..da6ac070 100644 --- a/project/tests/CustomEnvironment.ts +++ b/project/tests/CustomEnvironment.ts @@ -1,13 +1,12 @@ import "reflect-metadata"; +import { container } from "tsyringe"; import NodeEnvironment from "jest-environment-node"; -import type {EnvironmentContext} from "@jest/environment"; -import type {JestEnvironmentConfig} from "@jest/environment"; +import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment"; -import { container } from "tsyringe"; import { Container } from "@spt-aki/di/Container"; -class CustomEnvironment extends NodeEnvironment +export default class CustomEnvironment extends NodeEnvironment { constructor(config: JestEnvironmentConfig, context: EnvironmentContext) { @@ -27,5 +26,3 @@ class CustomEnvironment extends NodeEnvironment await super.teardown(); } } - -module.exports = CustomEnvironment;