Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"scripts": {
"test:_bundle": "EXODUS_TEST_IGNORE='tests/{{vendor/jest-extended,inband}/**,vendor/jest-when/when.test.*,jest/jest.resetModules.*,jest/mock/jest.mock.mocks-dir.test.js}' npm run test --",
"test": "npm run test:jest --",
"test:all": "npm run test:simple && npm run test:jest && npm run test:tape && npm run test:native && npm run test:esbuild && npm run test:pure && npm run test:fetch && npm run test:jsdom && npm run test:bundle",
"test:all": "npm run test:simple && npm run test:jest && npm run test:tape && npm run test:native && npm run test:esbuild && npm run test:pure && npm run test:fetch && npm run test:jsdom && npm run test:global-setup && npm run test:bundle",
"test:native": "EXODUS_TEST_IGNORE='**/jest.transformed/**/*' ./bin/index.js --jest 'tests/**/*.test.{js,cjs,mjs}'",
"test:typescript": "node ./bin/index.js --jest --typescript tests/typescript.test.ts",
"test:jest": "node ./bin/index.js --jest --esbuild=ts,sum.test.js",
Expand Down Expand Up @@ -172,6 +172,7 @@
"test:jerryscript": "EXODUS_TEST_ENGINE=jerryscript:bundle npm run test:_bundle -- --bundle-entropy-size 128",
"test:fetch": "node ./bin/index.js --jest --drop-network --engine node:pure 'tests/replay/*.test.js'",
"test:jsdom": "EXODUS_TEST_JEST_CONFIG='{\"testMatch\":[\"**/*.jsdom-test.js\"],\"testEnvironment\":\"jsdom\", \"rootDir\": \".\"}' ./bin/index.js --jest",
"test:global-setup": "EXODUS_TEST_JEST_CONFIG='{\"testMatch\":[\"**/*.global-setup-test.js\"],\"globalSetup\":\"<rootDir>/tests/jest/global-setup/global-setup.cjs\",\"globalTeardown\":\"./tests/jest/global-setup/global-teardown.cjs\", \"rootDir\": \".\"}' ./bin/index.js --jest",
"coverage": "node ./bin/index.js --jest --esbuild --coverage",
"typedoc": "typedoc && mkdir -p doc/assets && cp -r theme/styles doc/assets/",
"playwright": "node ./bin/index.js --playwright",
Expand Down
7 changes: 6 additions & 1 deletion src/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ export async function loadJestConfig(...args) {

const cleanFile = (file) => file.replace(/^<rootDir>\//g, './') // require is already relative to rootDir
if (needPreset(rawConfig) || rawConfig?.globalSetup || rawConfig?.globalTeardown) {
rawConfig.preset = cleanFile(rawConfig.preset) // relative to root dir only at top level, presets shouldn't use <rootDir>
// relative to root dir only at top level, presets shouldn't use <rootDir>
// each is optional here, we could have entered this branch just because of one of them
for (const key of ['preset', 'globalSetup', 'globalTeardown']) {
if (rawConfig[key]) rawConfig[key] = cleanFile(rawConfig[key])
}

if (process.env.EXODUS_TEST_ENVIRONMENT === 'bundle') {
throw new Error('jest preset and globalSetup/Teardown not yet supported in bundles')
} else {
Expand Down
4 changes: 4 additions & 0 deletions tests/jest/global-setup/global-setup.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Used by `npm run test:global-setup`, intentionally without a jest preset
module.exports = async () => {
process.env.EXODUS_TEST_GLOBAL_SETUP_RAN = '1'
}
4 changes: 4 additions & 0 deletions tests/jest/global-setup/global-teardown.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Used by `npm run test:global-setup`, intentionally without a jest preset
module.exports = async () => {
if (process.env.EXODUS_TEST_GLOBAL_SETUP_RAN !== '1') throw new Error('globalSetup did not run')
}
4 changes: 4 additions & 0 deletions tests/jest/global-setup/index.global-setup-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Run with `npm run test:global-setup`
test('jest globalSetup without a preset ran before tests', () => {
expect(process.env.EXODUS_TEST_GLOBAL_SETUP_RAN).toBe('1')
})
Loading