From 0f09c08fda9f4d8b00291b673fd46a5e447404cb Mon Sep 17 00:00:00 2001 From: Jan W Date: Thu, 24 Oct 2024 20:59:19 +0200 Subject: [PATCH] fix: jsdom import (#15) --- package.json | 3 ++- src/jest.config.js | 5 ++++- tests/jest/jsdom/index.jsdom-test.js | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/jest/jsdom/index.jsdom-test.js diff --git a/package.json b/package.json index 182a6b7..60dd41c 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ ], "scripts": { "test": "npm run test:jest", - "test:all": "npm run test:jest && npm run test:tape && npm run test:native && npm run test:pure && npm run test:typescript && npm run test:fetch", + "test:all": "npm run test:jest && npm run test:tape && npm run test:native && npm run test:pure && npm run test:typescript && npm run test:fetch && npm run test:jsdom", "test:native": "EXODUS_TEST_IGNORE='{**/typescript/**,**/jest-repo/**/user.test.js}' ./bin/index.js --jest 'tests/**/*.test.{js,cjs,mjs}'", "test:typescript": "./bin/index.js --jest --typescript tests/typescript.test.ts", "test:jest": "./bin/index.js --jest --esbuild", @@ -95,6 +95,7 @@ "test:bun": "EXODUS_TEST_ENGINE=bun:pure EXODUS_TEST_IGNORE='tests/jest-extended/**' npm run test", "test:hermes": "EXODUS_TEST_ENGINE=hermes:bundle EXODUS_TEST_IGNORE='tests/{{jest-extended,inband}/**,jest-when/when.test.*,jest/jest.{mock,resetModules}.*}' npm run test", "test:fetch": "./bin/index.js --jest --drop-network --engine node:pure tests/fetch.test.js tests/websocket.test.js", + "test:jsdom": "EXODUS_TEST_JEST_CONFIG='{\"testMatch\":[\"**/*.jsdom-test.js\"],\"testEnvironment\":\"jsdom\", \"rootDir\": \".\"}' ./bin/index.js --jest", "coverage": "./bin/index.js --jest --esbuild --coverage", "lint": "prettier --list-different . && eslint .", "lint:fix": "prettier --write . && eslint --fix ." diff --git a/src/jest.config.js b/src/jest.config.js index 46792fb..0cf0d56 100644 --- a/src/jest.config.js +++ b/src/jest.config.js @@ -110,7 +110,10 @@ export async function installJestEnvironment(jestGlobals) { } } else if (config.rootDir) { const { resolve } = await import('node:path') - dynamicImport = (path) => import(resolve(config.rootDir, path)) + const { createRequire } = await import('node:module') + const require = createRequire(resolve(config.rootDir, 'package.json')) + + dynamicImport = (path) => import(require.resolve(path)) } else { dynamicImport = async () => assert.fail('Unreachable: importing plugins without a rootDir') } diff --git a/tests/jest/jsdom/index.jsdom-test.js b/tests/jest/jsdom/index.jsdom-test.js new file mode 100644 index 0000000..c135d6b --- /dev/null +++ b/tests/jest/jsdom/index.jsdom-test.js @@ -0,0 +1,5 @@ +describe('jsdom', () => { + test('initializes jsdom', () => { + expect(window.document).toBeDefined() + }) +})