Skip to content

Commit

Permalink
[api] suppress top-level await diagnostic msg, bump @types/jest, remo…
Browse files Browse the repository at this point in the history
…ve esbuild, comment up jest config
  • Loading branch information
freemvmt committed Aug 16, 2024
1 parent d9f76ad commit 57484c9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1,117 deletions.
18 changes: 11 additions & 7 deletions api.planx.uk/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import type { JestConfigWithTsJest } from "ts-jest";

const config: JestConfigWithTsJest = {
// ts-jest presets are deprecated, so we prefer to give an explicit manual config
// for reference, closest ts-jest preset is constructed with createJsWithTsEsmPreset() util function
// but we prefer to give an explicit manual config
testEnvironment: "node",
transform: {
// esbuild-jest transformer is unmaintained and can't handle ts-with-esm, so we stick to ts-jest
// TODO: if tests are too slow, consider swapping out for @swc/jest
// note that we don't include 'c' or 'm' prefixes for file endings (denoting commonJS/ESM modules resp.)
"^.+\\.[jt]s$": [
"ts-jest",
{
useESM: true,
// we need to unset verbatimModuleSyntax for tests only (jest v30 may fix this)
// we need to unset verbatimModuleSyntax for tests only
tsconfig: "tsconfig.test.json",
diagnostics: {
ignoreCodes: [1343],
ignoreCodes: [
1343, // suppress import.meta warning
1378, // suppress top-level await warning
],
},
astTransformers: {
before: [
Expand All @@ -29,9 +33,9 @@ const config: JestConfigWithTsJest = {
transformIgnorePatterns: ["node_modules\\/.pnpm\\/(?!(mime))"],
testPathIgnorePatterns: ["dist/*"],
setupFilesAfterEnv: ["./jest.setup.js"],
// handle .ts files first, as ESM modules, and remove .js from imports for jest
moduleFileExtensions: ["ts", "js", "json"],
extensionsToTreatAsEsm: [".ts"],
moduleFileExtensions: ["ts", "js", "json"], // most modules are .ts files
extensionsToTreatAsEsm: [".ts"], // .js files treated as ESM by virtue of type: module in package.json
// remove .js from imports, which ts-with-esm requires but causes jest to fail module resolution
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
Expand Down
4 changes: 1 addition & 3 deletions api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@types/express": "^4.17.21",
"@types/express-pino-logger": "^4.0.5",
"@types/he": "^1.2.3",
"@types/jest": "^29.5.11",
"@types/jest": "^29.5.12",
"@types/jsdom": "^21.1.6",
"@types/jsonwebtoken": "^9.0.5",
"@types/lodash": "^4.17.0",
Expand All @@ -102,8 +102,6 @@
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"dotenv": "^16.4.5",
"esbuild": "^0.22.0",
"esbuild-jest": "^0.5.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.9.0",
Expand Down
Loading

0 comments on commit 57484c9

Please sign in to comment.