From 5c512b68613def02b56015c5d92cf210c0425e5c Mon Sep 17 00:00:00 2001 From: Julien Date: Mon, 19 Sep 2022 18:26:12 +0200 Subject: [PATCH] refactor: simplify jest config --- jest.config.ts | 38 +++++++++++--------------------------- package.json | 3 +-- tests/file-mock.js | 1 - tests/jest-preprocess.js | 5 ----- tests/loadershim.js | 13 ------------- 5 files changed, 12 insertions(+), 48 deletions(-) delete mode 100644 tests/file-mock.js delete mode 100644 tests/jest-preprocess.js delete mode 100644 tests/loadershim.js diff --git a/jest.config.ts b/jest.config.ts index babdc236..e49568cc 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,44 +1,28 @@ -import type { Config } from '@jest/types' -import glob from 'glob' - -const packages = glob.sync(`./src`).map(p => p.replace(/^\./, ``)) +import type { Config } from 'jest' const ignoreDirs = [ - 'build/', 'dist/', 'node_modules/', - `\\.cache`, 'scripts/', - 'public/', - 'generators/', 'generated/', 'website/', 'tests/', + 'packages/', ] -const config: Config.InitialOptions = { +export default async (): Promise => ({ + preset: 'ts-jest', testEnvironment: 'jsdom', - testEnvironmentOptions: { - url: `http://localhost`, - }, - roots: packages, + verbose: false, + silent: true, + roots: ['./src'], transform: { - '^.+\\.[jt]sx?$': `/tests/jest-preprocess.js`, - }, - moduleNameMapper: { - '.+\\.(css|styl|less|sass|scss)$': `identity-obj-proxy`, - '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `/tests/file-mock.js`, + '^.+\\.[t]sx?$': `ts-jest`, }, + transformIgnorePatterns: ['/node_modules/'], testPathIgnorePatterns: ignoreDirs, - transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`], coveragePathIgnorePatterns: ignoreDirs, coverageDirectory: '/coverage/', - globals: { - __PATH_PREFIX__: ``, - }, - setupFiles: [`/tests/loadershim.js`], - testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$', + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([t]sx?)$', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], -} - -export default config +}) diff --git a/package.json b/package.json index d66e6da2..c6a925d1 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "devDependencies": { "@testing-library/react": "^12.1.2", "@testing-library/react-hooks": "^7.0.2", - "@types/glob": "^8.0.0", "@types/jest": "^29.0.3", "@types/node": "^18.7.18", "@types/react": "^17.0.38", @@ -60,11 +59,11 @@ "eslint-plugin-tree-shaking": "^1.10.0", "jest": "^29.0.3", "jest-environment-jsdom": "^29.0.3", - "jest-preset-gatsby": "^1.0.134", "netlify-cli": "^11.8.0", "plop": "^3.0.5", "prettier": "^2.5.1", "rimraf": "^3.0.2", + "ts-jest": "^29.0.1", "ts-node": "^10.2.1", "typescript": "^4.5.5" }, diff --git a/tests/file-mock.js b/tests/file-mock.js deleted file mode 100644 index 0e56c5b5..00000000 --- a/tests/file-mock.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'test-file-stub' diff --git a/tests/jest-preprocess.js b/tests/jest-preprocess.js deleted file mode 100644 index ef6b675d..00000000 --- a/tests/jest-preprocess.js +++ /dev/null @@ -1,5 +0,0 @@ -const babelOptions = { - presets: ['babel-preset-gatsby', '@babel/preset-typescript'], -} - -module.exports = require('babel-jest').default.createTransformer(babelOptions) diff --git a/tests/loadershim.js b/tests/loadershim.js deleted file mode 100644 index a1347d9d..00000000 --- a/tests/loadershim.js +++ /dev/null @@ -1,13 +0,0 @@ -global.___loader = { - enqueue: jest.fn(), -} - -global.console = { - warn: jest.fn(), - - // Keep native behaviour for other methods, use those to print out things in your own tests, not `console.log` - error: console.error, - info: console.info, - debug: console.debug, - log: console.log, -}