From df3a9424b19f66426be6cfe69165f27194431f83 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sat, 19 Oct 2024 15:28:41 -0700 Subject: [PATCH] fix(test): fix javascript tests not running --- web/.knip.json | 4 +++- web/jest.config.js | 21 ++++++++++++++++++++- web/package-lock.json | 11 +++++++++++ web/package.json | 4 +++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/web/.knip.json b/web/.knip.json index e0783372c..41d2e141d 100644 --- a/web/.knip.json +++ b/web/.knip.json @@ -44,6 +44,8 @@ "@storybook/cli", "@storybook/mdx2-csf", "@commitlint/cli", - "@commitlint/config-conventional" + "@commitlint/config-conventional", + "babel-plugin-dynamic-import-node", + "@babel/preset-react" ] } \ No newline at end of file diff --git a/web/jest.config.js b/web/jest.config.js index 8ffa537be..5ee7c50ce 100644 --- a/web/jest.config.js +++ b/web/jest.config.js @@ -1,5 +1,24 @@ module.exports = { - transform: { '^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }] }, + transform: { + '^.+\\.(js|jsx|ts|tsx)$': [ + 'babel-jest', + { + presets: [ + [ + '@babel/preset-env', + { + targets: { + node: 'current', + }, + }, + ], + '@babel/preset-react', + '@babel/preset-typescript', + ], + plugins: ['dynamic-import-node'], + }, + ], + }, testEnvironment: 'node', testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], diff --git a/web/package-lock.json b/web/package-lock.json index a66f44091..2883afa0d 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -22,6 +22,7 @@ "@xstate/react": "3.2.2", "antd": "4.24.16", "autoprefixer": "^10.4.14", + "babel-plugin-dynamic-import-node": "^2.3.3", "chart.js": "^4.2.0", "classnames": "2.5.1", "date-fns": "^3.0.0", @@ -55,6 +56,7 @@ }, "devDependencies": { "@babel/core": "7.25.8", + "@babel/preset-react": "^7.25.7", "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", "@mdx-js/react": "3.0.1", @@ -13471,6 +13473,15 @@ "dev": true, "license": "MIT" }, + "node_modules/babel-plugin-dynamic-import-node": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz", + "integrity": "sha512-jZVI+s9Zg3IqA/kdi0i6UDCybUI3aSBLnglhYbSSjKlV7yF1F/5LWv8MakQmvYpnbJDS6fcBL2KzHSxNCMtWSQ==", + "license": "MIT", + "dependencies": { + "object.assign": "^4.1.0" + } + }, "node_modules/babel-plugin-istanbul": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-6.1.1.tgz", diff --git a/web/package.json b/web/package.json index ccaa5cadc..d428e817e 100644 --- a/web/package.json +++ b/web/package.json @@ -31,6 +31,7 @@ "@xstate/react": "3.2.2", "antd": "4.24.16", "autoprefixer": "^10.4.14", + "babel-plugin-dynamic-import-node": "^2.3.3", "chart.js": "^4.2.0", "classnames": "2.5.1", "date-fns": "^3.0.0", @@ -64,6 +65,7 @@ }, "devDependencies": { "@babel/core": "7.25.8", + "@babel/preset-react": "^7.25.7", "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", "@mdx-js/react": "3.0.1", @@ -135,4 +137,4 @@ "ts-jest": "^29.1.0", "typescript": "5.6.3" } -} \ No newline at end of file +}