Skip to content

Commit

Permalink
fix: jsdom import (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparten11740 authored Oct 24, 2024
1 parent e154875 commit 0f09c08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 ."
Expand Down
5 changes: 4 additions & 1 deletion src/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
5 changes: 5 additions & 0 deletions tests/jest/jsdom/index.jsdom-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('jsdom', () => {
test('initializes jsdom', () => {
expect(window.document).toBeDefined()
})
})

0 comments on commit 0f09c08

Please sign in to comment.