Skip to content

Commit

Permalink
test: add jsdom test
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Sep 14, 2023
1 parent e6f5855 commit 7b03ada
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
19 changes: 15 additions & 4 deletions packages/recorder/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const CI = require('is-ci');
const artifactsDir = path.join(__dirname, '../../artifacts');

const PRESET = process.env.PRESET || 'env-1';
const JEST_ENVIRONMENT = process.env.JEST_ENVIRONMENT || 'node';

if (CI) {
const logsDir = path.join(artifactsDir, PRESET, 'logs');
Expand All @@ -13,8 +14,8 @@ if (CI) {
}

const mixins = {
env: () => ({
testEnvironment: 'jest-metadata/environment-node',
env: (custom = false) => ({
testEnvironment: `${custom ? 'jest-metadata/environment-' : ''}${JEST_ENVIRONMENT}`,
}),
workers: (n) => ({
maxWorkers: n,
Expand All @@ -23,21 +24,24 @@ const mixins = {

const presets = {
'env-1': {
...mixins.env(),
...mixins.env(true),
...mixins.workers(1),
},
'env-N': {
...mixins.env(),
...mixins.env(true),
...mixins.workers(2),
},
'no-env-1': {
...mixins.env(false),
...mixins.workers(1),
},
'no-env-N': {
...mixins.env(false),
...mixins.workers(2),
},
};

/** @type {import('@jest/types').Config.InitialOptions}*/
module.exports = {
collectCoverage: CI,
coverageDirectory: path.join(artifactsDir, PRESET, 'coverage'),
Expand All @@ -47,5 +51,12 @@ module.exports = {
'<rootDir>/mockReporter'
],

testMatch: [
'<rootDir>/__tests__/*.js',
PRESET.startsWith('no-env')
? '<rootDir>/__tests__/no-env/*.js'
: '<rootDir>/__tests__/env-only/*.js',
],

...presets[PRESET],
};
3 changes: 3 additions & 0 deletions packages/recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
"cross-env": "^7.0.3",
"is-ci": "^3.0.1",
"jest": "latest",
"jest-environment-jsdom": "latest",
"jest-metadata": "^1.0.0-beta.17",
"semver": "^7.5.4"
},
"scripts": {
"build:dev": "npm run build --workspace=jest-metadata && npm run instrument --workspace=jest-metadata && npm run build",
"build:jsdom": "cross-env JEST_ENVIRONMENT=jsdom npm run build",
"build:node": "cross-env JEST_ENVIRONMENT=node npm run build",
"build": "npm run build:env-1 ; npm run build:env-N ; npm run build:no-env-1 ; npm run build:no-env-N ; true",
"build:env-1": "cross-env PRESET=env-1 jest",
"build:env-N": "cross-env PRESET=env-N jest",
Expand Down
5 changes: 4 additions & 1 deletion scripts/setup-fixture.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const recorderManifestPath = path.join(recorderRootDir, 'package.json');
const recorderManifest = JSON.parse(fs.readFileSync(recorderManifestPath, 'utf8'));
const jestVersion = process.env.JEST_VERSION || 'latest';
recorderManifest.devDependencies.jest = jestVersion;
fs.writeFileSync(recorderManifestPath, JSON.stringify(recorderManifest, null, 2) + '\n');
Object.assign({
"jest": jestVersion,
"jest-environment-jsdom": jestVersion,
});

console.log(`Setting jest@${jestVersion}\n`);

0 comments on commit 7b03ada

Please sign in to comment.