Skip to content

Commit

Permalink
Move randomize option to jest.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrotoff committed Jul 6, 2023
1 parent 9557a60 commit 424dd51
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
11 changes: 7 additions & 4 deletions examples/node/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

/** @type {import('jest').Config} */
const config = {
testEnvironment: 'node',

setupFilesAfterEnv: ['./jest.setup.ts'],

// By default Jest allows for __tests__/*.js, *.spec.js and *.test.js
// https://jestjs.io/docs/en/26.5/configuration#testregex-string--arraystring
// Let's be strict and use *.test.js only
testRegex: '\\.test\\.ts$',

// https://github.com/jestjs/jest/issues/4386#issuecomment-586028628
randomize: true,

testEnvironment: 'node',

setupFilesAfterEnv: ['./jest.setup.ts'],

coverageThreshold: {
global: {
statements: 100,
Expand Down
4 changes: 2 additions & 2 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"clean": "rm -rf build coverage",
"clean:all": "npm run clean && rm -rf node_modules package-lock.json",
"start": "ts-node index.ts",
"test": "jest --randomize --verbose",
"test:coverage": "jest --randomize --coverage",
"test": "jest --verbose",
"test:coverage": "jest --coverage",
"tsc": "tsc",
"npm:update": "npm run clean:all && npx npm-check-updates --upgrade && npm install"
},
Expand Down
13 changes: 8 additions & 5 deletions examples/web/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

/** @type {import('jest').Config} */
const config = {
// By default Jest allows for __tests__/*.js, *.spec.js and *.test.js
// https://jestjs.io/docs/en/26.5/configuration#testregex-string--arraystring
// Let's be strict and use *.test.js only
testRegex: '\\.test\\.ts$',

// https://github.com/jestjs/jest/issues/4386#issuecomment-586028628
randomize: true,

// FIXME https://github.com/jsdom/jsdom/issues/3363
// FIXME https://github.com/jsdom/jsdom/issues/1724
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
testEnvironment: './FixJSDOMEnvironment.ts',

setupFilesAfterEnv: ['./jest.setup.ts'],

// By default Jest allows for __tests__/*.js, *.spec.js and *.test.js
// https://jestjs.io/docs/en/26.5/configuration#testregex-string--arraystring
// Let's be strict and use *.test.js only
testRegex: '\\.test\\.ts$',

coverageThreshold: {
global: {
statements: 100,
Expand Down
4 changes: 2 additions & 2 deletions examples/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"clean:all": "npm run clean && rm -rf node_modules package-lock.json",
"start": "webpack serve --mode=development --host 0.0.0.0",
"build": "webpack --mode=development",
"test": "jest --randomize --verbose",
"test:coverage": "jest --randomize --coverage",
"test": "jest --verbose",
"test:coverage": "jest --coverage",
"tsc": "tsc",
"npm:update": "npm run clean:all && npx npm-check-updates --upgrade && npm install"
},
Expand Down
7 changes: 5 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const esModules = ['node-fetch', 'data-uri-to-buffer', 'fetch-blob', 'formdata-p

/** @type {import('jest').Config} */
const config = {
setupFilesAfterEnv: ['./jest.setup.ts'],

// By default Jest allows for __tests__/*.js, *.spec.js and *.test.js
// https://jestjs.io/docs/en/26.5/configuration#testregex-string--arraystring
// Let's be strict and use *.test.js only
testRegex: '\\.test\\.ts$',

// https://github.com/jestjs/jest/issues/4386#issuecomment-586028628
randomize: true,

setupFilesAfterEnv: ['./jest.setup.ts'],

transformIgnorePatterns: [`/node_modules/(?!${esModules.join('|')})`],

testPathIgnorePatterns: [...defaults.testPathIgnorePatterns, '/examples/'],
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"start:example:node": "cd examples/node && npm run start",
"test": "npm run test:node-fetch",
"test:coverage": "npm run test:coverage:node-fetch",
"test:node-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=node-fetch jest --randomize --verbose",
"test:coverage:node-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=node-fetch jest --randomize --coverage",
"test:whatwg-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=whatwg-fetch jest --env=jsdom --randomize --verbose",
"test:undici": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=undici jest --randomize --verbose",
"test:coverage:whatwg-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=whatwg-fetch jest --env=jsdom --randomize --coverage",
"test:node-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=node-fetch jest --verbose",
"test:coverage:node-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=node-fetch jest --coverage",
"test:whatwg-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=whatwg-fetch jest --env=jsdom --verbose",
"test:undici": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=undici jest --verbose",
"test:coverage:whatwg-fetch": "NODE_EXTRA_CA_CERTS=./src/createTestServer/createTestServer.cert FETCH=whatwg-fetch jest --env=jsdom --coverage",
"test:e2e": "playwright test",
"test:e2e:debug": "playwright test --debug",
"test:coverage:examples": "npm run test:coverage:example:web && npm run test:coverage:example:node",
Expand Down

0 comments on commit 424dd51

Please sign in to comment.