diff --git a/.eslintrc.cjs b/.eslintrc.cjs index c22fcecb4c0d..5a573f07e1cb 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -235,6 +235,15 @@ module.exports = { 'jest/prefer-to-have-length': 'off', }, }, + // snapshot in an example needs to keep escapes + { + files: [ + '**/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md/**', + ], + rules: { + 'no-useless-escape': 'off', + }, + }, // snapshots in examples plus inline snapshots need to keep backtick { diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index b9111207f03a..39abe409fe23 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -82,6 +82,8 @@ jobs: run: yarn lint - name: run prettier run: yarn lint:prettier:ci + - name: check changelog + run: yarn check-changelog - name: check copyright headers run: yarn check-copyright-headers diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fa90977d331..6aa5f81fd386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- `[@jest/core]` Instrument significant lifecycle events with [`performance.mark()`](https://nodejs.org/docs/latest-v16.x/api/perf_hooks.html#performancemarkname-options) ([#13859](https://github.com/facebook/jest/pull/13859)) + ### Fixes - `[expect, @jest/expect]` Provide type of `actual` as a generic argument to `Matchers` to allow better-typed extensions ([#13848](https://github.com/facebook/jest/pull/13848)) @@ -11,6 +13,7 @@ ### Chore & Maintenance - `[*]` make sure to exclude `.eslintcache` from published module ([#13832](https://github.com/facebook/jest/pull/13832)) +- `[docs]` Cleanup incorrect links in CHANGELOG.md ([#13857](https://github.com/facebook/jest/pull/13857)) ### Performance @@ -294,7 +297,7 @@ ### Fixes -- `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedMaps ([#12763](https://github.com/facebook/jest/pull/12899)) +- `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedMaps ([#12899](https://github.com/facebook/jest/pull/12899)) - `[jest-docblock]` Handle multiline comments in parseWithComments ([#12845](https://github.com/facebook/jest/pull/12845)) - `[jest-mock]` Improve `spyOn` error messages ([#12901](https://github.com/facebook/jest/pull/12901)) - `[jest-runtime]` Correctly report V8 coverage with `resetModules: true` ([#12912](https://github.com/facebook/jest/pull/12912)) @@ -772,7 +775,7 @@ ### Features -- `[@jest/fake-timers]` Flush callbacks scheduled with `requestAnimationFrame` every 16ms when using legacy timers. ([#11523](https://github.com/facebook/jest/pull/11567)) +- `[@jest/fake-timers]` Flush callbacks scheduled with `requestAnimationFrame` every 16ms when using legacy timers. ([#11567](https://github.com/facebook/jest/pull/11567)) - `[pretty-format]` Use `globalThis` (with polyfill if required) to bring support for esbuild's browser bundling mode ([#11569](https://github.com/facebook/jest/pull/11569)) ### Fixes @@ -859,7 +862,7 @@ - `[jest-runtime]` Detect reexports from CJS as named exports in ESM ([#10988](https://github.com/facebook/jest/pull/10988)) - `[jest-runtime]` Support for async code transformations ([#11191](https://github.com/facebook/jest/pull/11191) & [#11220](https://github.com/facebook/jest/pull/11220)) - `[jest-snapshot]` [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792) & [#11192](https://github.com/facebook/jest/pull/11192)) -- `[jest-snapshot]` [**BREAKING**] Run transforms over `snapshotResolver` ([#8751](https://github.com/facebook/jest/pull/8829)) +- `[jest-snapshot]` [**BREAKING**] Run transforms over `snapshotResolver` ([#8829](https://github.com/facebook/jest/pull/8829)) - `[jest-transform]` Pass config options defined in Jest's config to transformer's `process` and `getCacheKey` functions ([#10926](https://github.com/facebook/jest/pull/10926)) - `[jest-transform]` Add support for transformers written in ESM ([#11163](https://github.com/facebook/jest/pull/11163)) - `[jest-transform]` [**BREAKING**] Do not export `ScriptTransformer` class, instead export the async function `createScriptTransformer` ([#11163](https://github.com/facebook/jest/pull/11163)) @@ -1107,7 +1110,7 @@ - `[jest-core]` Don't report ELDHistogram as open handle ([#10417](https://github.com/facebook/jest/pull/10417)) - `[jest-matcher-utils]` Fix diffing object contain readonly symbol key object ([#10414](https://github.com/facebook/jest/pull/10414)) -- `[jest-reporters]` Fixes notify reporter on Linux (using notify-send) ([#10393](https://github.com/facebook/jest/pull/10400)) +- `[jest-reporters]` Fixes notify reporter on Linux (using notify-send) ([#10400](https://github.com/facebook/jest/pull/10400)) - `[jest-snapshot]` Correctly handles arrays and property matchers in snapshots ([#10404](https://github.com/facebook/jest/pull/10404)) ## 26.4.0 @@ -1156,7 +1159,7 @@ - `[jest-haste-map]` Watchman crawler now includes dotfiles ([#10075](https://github.com/facebook/jest/pull/10075)) - `[jest-worker]` Added support for workers to send custom messages to parent in jest-worker ([#10293](https://github.com/facebook/jest/pull/10293)) - `[jest-worker]` Support passing `resourceLimits` ([#10335](https://github.com/facebook/jest/pull/10335)) -- `[pretty-format]` Added support for serializing custom elements (web components) ([#10217](https://github.com/facebook/jest/pull/10237)) +- `[pretty-format]` Added support for serializing custom elements (web components) ([#10237](https://github.com/facebook/jest/pull/10237)) ### Fixes @@ -1573,7 +1576,7 @@ - `[expect]` Display equal values for ReturnedWith similar to CalledWith ([#8791](https://github.com/facebook/jest/pull/8791)) - `[expect, jest-snapshot]` Change color from green for some args in matcher hints ([#8812](https://github.com/facebook/jest/pull/8812)) - `[jest-snapshot]` Highlight substring differences when matcher fails, part 3 ([#8569](https://github.com/facebook/jest/pull/8569)) -- `[jest-core]` Improve report when snapshots are obsolete ([#8448](https://github.com/facebook/jest/pull/8665)) +- `[jest-core]` Improve report when snapshots are obsolete ([#8665](https://github.com/facebook/jest/pull/8665)) - `[jest-cli]` Improve chai support (with detailed output, to match jest exceptions) ([#8454](https://github.com/facebook/jest/pull/8454)) - `[*]` Manage the global timeout with `--testTimeout` command line argument. ([#8456](https://github.com/facebook/jest/pull/8456)) - `[pretty-format]` Render custom displayName of memoized components ([#8546](https://github.com/facebook/jest/pull/8546)) @@ -1862,7 +1865,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - `[jest-docblock]`: Migrate to TypeScript ([#7836](https://github.com/facebook/jest/pull/7836)) - `[jest-each]`: Migrate to Typescript ([#8007](https://github.com/facebook/jest/pull/8007)) - `[jest-each]`: Refactor into multiple files with better types ([#8018](https://github.com/facebook/jest/pull/8018)) -- `[jest-environment-jsdom]`: Migrate to TypeScript ([#7985](https://github.com/facebook/jest/pull/8003)) +- `[jest-environment-jsdom]`: Migrate to TypeScript ([#8003](https://github.com/facebook/jest/pull/8003)) - `[jest-environment-node]`: Migrate to TypeScript ([#7985](https://github.com/facebook/jest/pull/7985)) - `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818)) - `[jest-haste-map]`: Migrate to TypeScript ([#7854](https://github.com/facebook/jest/pull/7854), [#7951](https://github.com/facebook/jest/pull/7951)) @@ -1885,7 +1888,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - `[jest-watcher]`: Migrate to TypeScript ([#7843](https://github.com/facebook/jest/pull/7843)) - `[jest-worker]`: Migrate to TypeScript ([#7853](https://github.com/facebook/jest/pull/7853)) - `[jest]`: Migrate to TypeScript ([#8024](https://github.com/facebook/jest/pull/8024)) -- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809), [#7809](https://github.com/facebook/jest/pull/7972)) +- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809), [#7972](https://github.com/facebook/jest/pull/7972)) ### Performance @@ -2179,7 +2182,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - `[jest-jasmine2]` Use prettier through `require` instead of `localRequire`. Fixes `matchInlineSnapshot` where prettier dependencies like `path` and `fs` are mocked with `jest.mock`. ([#6776](https://github.com/facebook/jest/pull/6776)) - `[docs]` Fix contributors link ([#6711](https://github.com/facebook/jest/pull/6711)) - `[website]` Fix website versions page to link to correct language ([#6734](https://github.com/facebook/jest/pull/6734)) -- `[expect]` Update `toContain` suggestion to contain equal message ([#6792](https://github.com/facebook/jest/pull/6810)) +- `[expect]` Update `toContain` suggestion to contain equal message ([#6810](https://github.com/facebook/jest/pull/6810)) ## 23.4.1 @@ -2320,7 +2323,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - `[jest-runtime]` Prevent modules from marking themselves as their own parent ([#5235](https://github.com/facebook/jest/issues/5235)) - `[jest-mock]` Add support for auto-mocking generator functions ([#5983](https://github.com/facebook/jest/pull/5983)) - `[expect]` Add support for async matchers ([#5919](https://github.com/facebook/jest/pull/5919)) -- `[expect]` Suggest toContainEqual ([#5948](https://github.com/facebook/jest/pull/5953)) +- `[expect]` Suggest toContainEqual ([#5953](https://github.com/facebook/jest/pull/5953)) - `[jest-config]` Export Jest's default options ([#5948](https://github.com/facebook/jest/pull/5948)) - `[jest-editor-support]` Move `coverage` to `ProjectWorkspace.collectCoverage` ([#5929](https://github.com/facebook/jest/pull/5929)) - `[jest-editor-support]` Add `coverage` option to runner ([#5836](https://github.com/facebook/jest/pull/5836)) @@ -2398,7 +2401,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - `[docs]` Add explanation on how to mock methods not implemented in JSDOM - `[jest-jasmine2]` Simplify `Env.execute` and TreeProcessor to setup and clean resources for the top suite the same way as for all of the children suites ([#5885](https://github.com/facebook/jest/pull/5885)) - `[babel-jest]` [**BREAKING**] Always return object from transformer ([#5991](https://github.com/facebook/jest/pull/5991)) -- `[*]` Run Prettier on compiled output ([#5858](https://github.com/facebook/jest/pull/3497)) +- `[*]` Run Prettier on compiled output ([#5858](https://github.com/facebook/jest/pull/5858)) - `[jest-cli]` Add fileChange hook for plugins ([#5708](https://github.com/facebook/jest/pull/5708)) - `[docs]` Add docs on using `jest.mock(...)` ([#5648](https://github.com/facebook/jest/pull/5648)) - `[docs]` Mention Jest Puppeteer Preset ([#5722](https://github.com/facebook/jest/pull/5722)) @@ -2484,7 +2487,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 ### Fixes - `[babel-jest]` Revert "Remove retainLines from babel-jest" ([#5496](https://github.com/facebook/jest/pull/5496)) -- `[jest-docblock]` Support multiple of the same `@pragma`. ([#5154](https://github.com/facebook/jest/pull/5502)) +- `[jest-docblock]` Support multiple of the same `@pragma`. ([#5502](https://github.com/facebook/jest/pull/5502)) ### Features @@ -2668,7 +2671,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - `[pretty-format]` Fix errors when identity-obj-proxy mocks CSS Modules ([#4935](https://github.com/facebook/jest/pull/4935)) - `[babel-jest]` Fix support for namespaced babel version 7 ([#4918](https://github.com/facebook/jest/pull/4918)) - `[expect]` fix .toThrow for promises ([#4884](https://github.com/facebook/jest/pull/4884)) -- `[jest-docblock]` pragmas should preserve urls ([#4837](https://github.com/facebook/jest/pull/4629)) +- `[jest-docblock]` pragmas should preserve urls ([#4837](https://github.com/facebook/jest/pull/4837)) - `[jest-cli]` Check if `npm_lifecycle_script` calls Jest directly ([#4629](https://github.com/facebook/jest/pull/4629)) - `[jest-cli]` Fix --showConfig to show all configs ([#4494](https://github.com/facebook/jest/pull/4494)) - `[jest-cli]` Throw if `maxWorkers` doesn't have a value ([#4591](https://github.com/facebook/jest/pull/4591)) diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index 87aa7c37b0c3..4f206f5cf8bb 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -1262,7 +1262,7 @@ These helper functions and properties can be found on `this` inside a custom tes #### `this.equals(a, b, customTesters?)` -This is a deep-equality function that will return `true` if two objects have the same values (recursively). It optionally takes a list of custom equality testers to apply to the deep equality checks. If you use this function, pass through the custom testers your tester is given so further equality checks `equals` applies can also use custom testers the test author may have configured. See the example in the [Recursive custom equality testers][#recursivecustomequalitytesters] section for more details. +This is a deep-equality function that will return `true` if two objects have the same values (recursively). It optionally takes a list of custom equality testers to apply to the deep equality checks. If you use this function, pass through the custom testers your tester is given so further equality checks `equals` applies can also use custom testers the test author may have configured. See the example in the [Recursive custom equality testers](#recursive-custom-equality-testers) section for more details. #### Matchers vs Testers diff --git a/docs/Webpack.md b/docs/Webpack.md index 84b8944b7c4f..699ef4c9f805 100644 --- a/docs/Webpack.md +++ b/docs/Webpack.md @@ -202,7 +202,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json index c3053b6da00f..dba558ebe941 100644 --- a/e2e/tsconfig.json +++ b/e2e/tsconfig.json @@ -3,5 +3,6 @@ "compilerOptions": { "rootDir": "./" }, - "include": ["./**/*"] + "include": ["./**/*"], + "references": [{"path": "../packages/test-utils"}] } diff --git a/package.json b/package.json index 8caee36a19c3..bf5568503c6e 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "build:js": "node ./scripts/build.mjs", "build:ts": "node ./scripts/buildTs.mjs", "bundle:ts": "node ./scripts/bundleTs.mjs", + "check-changelog": "node ./scripts/checkChangelog.mjs", "check-copyright-headers": "node ./scripts/checkCopyrightHeaders.mjs", "clean-all": "yarn clean-e2e && yarn build-clean && rimraf './packages/*/node_modules' && rimraf './node_modules'", "clean-e2e": "node ./scripts/cleanE2e.mjs", diff --git a/packages/babel-jest/src/__tests__/tsconfig.json b/packages/babel-jest/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/babel-jest/src/__tests__/tsconfig.json +++ b/packages/babel-jest/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/babel-jest/tsconfig.json b/packages/babel-jest/tsconfig.json index a58a0880e8aa..3535b54c1d86 100644 --- a/packages/babel-jest/tsconfig.json +++ b/packages/babel-jest/tsconfig.json @@ -7,5 +7,5 @@ "include": ["./src/**/*"], "exclude": ["./**/__tests__/**/*"], // TODO: include `babel-preset-jest` if it's ever in TS even though we don't care about its types - "references": [{"path": "../jest-transform"}, {"path": "../test-utils"}] + "references": [{"path": "../jest-transform"}] } diff --git a/packages/expect/src/__tests__/tsconfig.json b/packages/expect/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/expect/src/__tests__/tsconfig.json +++ b/packages/expect/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/expect/tsconfig.json b/packages/expect/tsconfig.json index 330ff26d00c9..8d7a33c00c62 100644 --- a/packages/expect/tsconfig.json +++ b/packages/expect/tsconfig.json @@ -12,7 +12,6 @@ {"path": "../jest-get-type"}, {"path": "../jest-matcher-utils"}, {"path": "../jest-message-util"}, - {"path": "../jest-util"}, - {"path": "../test-utils"} + {"path": "../jest-util"} ] } diff --git a/packages/jest-console/src/__tests__/tsconfig.json b/packages/jest-console/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-console/src/__tests__/tsconfig.json +++ b/packages/jest-console/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-console/tsconfig.json b/packages/jest-console/tsconfig.json index 308e84ff26ee..735c691024a6 100644 --- a/packages/jest-console/tsconfig.json +++ b/packages/jest-console/tsconfig.json @@ -9,7 +9,6 @@ "references": [ {"path": "../jest-message-util"}, {"path": "../jest-types"}, - {"path": "../jest-util"}, - {"path": "../test-utils"} + {"path": "../jest-util"} ] } diff --git a/packages/jest-core/src/__tests__/tsconfig.json b/packages/jest-core/src/__tests__/tsconfig.json index 8ccc3083ffb0..d603a17f8dfe 100644 --- a/packages/jest-core/src/__tests__/tsconfig.json +++ b/packages/jest-core/src/__tests__/tsconfig.json @@ -1,7 +1,5 @@ { "extends": "../../../../tsconfig.test.json", - "compilerOptions": { - "rootDir": "../" - }, - "include": ["../**/*"] + "include": ["./**/*"], + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index b3e7df8c5e12..b9ac488c3278 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import {performance} from 'perf_hooks'; import chalk = require('chalk'); import exit = require('exit'); import * as fs from 'graceful-fs'; @@ -41,6 +42,7 @@ export async function runCLI( results: AggregatedResult; globalConfig: Config.GlobalConfig; }> { + performance.mark('jest/runCLI:start'); let results: AggregatedResult | undefined; // If we output a JSON object, we can't write anything to stdout, since @@ -133,6 +135,7 @@ export async function runCLI( console.error(message); } + performance.mark('jest/runCLI:end'); return {globalConfig, results}; } @@ -173,6 +176,12 @@ const _run10000 = async ( // Queries to hg/git can take a while, so we need to start the process // as soon as possible, so by the time we need the result it's already there. const changedFilesPromise = getChangedFilesPromise(globalConfig, configs); + if (changedFilesPromise) { + performance.mark('jest/getChangedFiles:start'); + changedFilesPromise.finally(() => { + performance.mark('jest/getChangedFiles:end'); + }); + } // Filter may need to do an HTTP call or something similar to setup. // We will wait on an async response from this before using the filter. @@ -204,11 +213,13 @@ const _run10000 = async ( }; } + performance.mark('jest/buildContextsAndHasteMaps:start'); const {contexts, hasteMapInstances} = await buildContextsAndHasteMaps( configs, globalConfig, outputStream, ); + performance.mark('jest/buildContextsAndHasteMaps:end'); globalConfig.watch || globalConfig.watchAll ? await runWatch( diff --git a/packages/jest-core/src/lib/__tests__/tsconfig.json b/packages/jest-core/src/lib/__tests__/tsconfig.json index facea41430cf..1bc42294775a 100644 --- a/packages/jest-core/src/lib/__tests__/tsconfig.json +++ b/packages/jest-core/src/lib/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../../"}] + "references": [{"path": "../../../"}, {"path": "../../../../test-utils"}] } diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index 9aa77a4346ec..640407a0f6b1 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -6,6 +6,7 @@ */ import * as path from 'path'; +import {performance} from 'perf_hooks'; import chalk = require('chalk'); import exit = require('exit'); import * as fs from 'graceful-fs'; @@ -179,6 +180,7 @@ export default async function runJest({ const searchSources = contexts.map(context => new SearchSource(context)); + performance.mark('jest/getTestPaths:start'); const testRunData: TestRunData = await Promise.all( contexts.map(async (context, index) => { const searchSource = searchSources[index]; @@ -195,6 +197,7 @@ export default async function runJest({ return {context, matches}; }), ); + performance.mark('jest/getTestPaths:end'); if (globalConfig.shard) { if (typeof sequencer.shard !== 'function') { @@ -260,7 +263,9 @@ export default async function runJest({ } if (hasTests) { + performance.mark('jest/globalSetup:start'); await runGlobalHook({allTests, globalConfig, moduleName: 'globalSetup'}); + performance.mark('jest/globalSetup:end'); } if (changedFilesPromise) { @@ -289,14 +294,24 @@ export default async function runJest({ ...testSchedulerContext, }); + // @ts-expect-error - second arg is unsupported (but harmless) in Node 14 + performance.mark('jest/scheduleAndRun:start', { + detail: {numTests: allTests.length}, + }); const results = await scheduler.scheduleTests(allTests, testWatcher); + performance.mark('jest/scheduleAndRun:start'); + performance.mark('jest/cacheResults:start'); sequencer.cacheResults(allTests, results); + performance.mark('jest/cacheResults:end'); if (hasTests) { + performance.mark('jest/globalTeardown:start'); await runGlobalHook({allTests, globalConfig, moduleName: 'globalTeardown'}); + performance.mark('jest/globalTeardown:end'); } + performance.mark('jest/processResults:start'); await processResults(results, { collectHandles, json: globalConfig.json, @@ -305,4 +320,5 @@ export default async function runJest({ outputStream, testResultsProcessor: globalConfig.testResultsProcessor, }); + performance.mark('jest/processResults:end'); } diff --git a/packages/jest-core/tsconfig.json b/packages/jest-core/tsconfig.json index 0a01ce3297dd..ac309da620f3 100644 --- a/packages/jest-core/tsconfig.json +++ b/packages/jest-core/tsconfig.json @@ -26,7 +26,6 @@ {"path": "../jest-util"}, {"path": "../jest-validate"}, {"path": "../jest-watcher"}, - {"path": "../pretty-format"}, - {"path": "../test-utils"} + {"path": "../pretty-format"} ] } diff --git a/packages/jest-diff/src/__tests__/tsconfig.json b/packages/jest-diff/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-diff/src/__tests__/tsconfig.json +++ b/packages/jest-diff/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-diff/tsconfig.json b/packages/jest-diff/tsconfig.json index e816b873f5ba..b286bcd0da96 100644 --- a/packages/jest-diff/tsconfig.json +++ b/packages/jest-diff/tsconfig.json @@ -9,7 +9,6 @@ "references": [ {"path": "../diff-sequences"}, {"path": "../jest-get-type"}, - {"path": "../pretty-format"}, - {"path": "../test-utils"} + {"path": "../pretty-format"} ] } diff --git a/packages/jest-environment-jsdom/src/__tests__/tsconfig.json b/packages/jest-environment-jsdom/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-environment-jsdom/src/__tests__/tsconfig.json +++ b/packages/jest-environment-jsdom/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-environment-jsdom/tsconfig.json b/packages/jest-environment-jsdom/tsconfig.json index 240880c13e8f..82e5be22db29 100644 --- a/packages/jest-environment-jsdom/tsconfig.json +++ b/packages/jest-environment-jsdom/tsconfig.json @@ -11,7 +11,6 @@ {"path": "../jest-fake-timers"}, {"path": "../jest-mock"}, {"path": "../jest-types"}, - {"path": "../jest-util"}, - {"path": "../test-utils"} + {"path": "../jest-util"} ] } diff --git a/packages/jest-environment-node/src/__tests__/tsconfig.json b/packages/jest-environment-node/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-environment-node/src/__tests__/tsconfig.json +++ b/packages/jest-environment-node/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-environment-node/tsconfig.json b/packages/jest-environment-node/tsconfig.json index 12bd3f484bcd..13971fdd663d 100644 --- a/packages/jest-environment-node/tsconfig.json +++ b/packages/jest-environment-node/tsconfig.json @@ -11,7 +11,6 @@ {"path": "../jest-fake-timers"}, {"path": "../jest-mock"}, {"path": "../jest-types"}, - {"path": "../jest-util"}, - {"path": "../test-utils"} + {"path": "../jest-util"} ] } diff --git a/packages/jest-fake-timers/src/__tests__/tsconfig.json b/packages/jest-fake-timers/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-fake-timers/src/__tests__/tsconfig.json +++ b/packages/jest-fake-timers/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-fake-timers/tsconfig.json b/packages/jest-fake-timers/tsconfig.json index 3c20004c2488..483142698671 100644 --- a/packages/jest-fake-timers/tsconfig.json +++ b/packages/jest-fake-timers/tsconfig.json @@ -11,7 +11,6 @@ {"path": "../jest-message-util"}, {"path": "../jest-mock"}, {"path": "../jest-types"}, - {"path": "../jest-util"}, - {"path": "../test-utils"} + {"path": "../jest-util"} ] } diff --git a/packages/jest-haste-map/package.json b/packages/jest-haste-map/package.json index d06359213809..fa4f5b8a7747 100644 --- a/packages/jest-haste-map/package.json +++ b/packages/jest-haste-map/package.json @@ -30,7 +30,6 @@ "walker": "^1.0.8" }, "devDependencies": { - "@jest/test-utils": "workspace:^", "@types/fb-watchman": "^2.0.0", "@types/micromatch": "^4.0.1", "slash": "^3.0.0" diff --git a/packages/jest-haste-map/tsconfig.json b/packages/jest-haste-map/tsconfig.json index 5fcbf9a63cd9..22b31f6d8eb1 100644 --- a/packages/jest-haste-map/tsconfig.json +++ b/packages/jest-haste-map/tsconfig.json @@ -10,7 +10,6 @@ {"path": "../jest-regex-util"}, {"path": "../jest-types"}, {"path": "../jest-util"}, - {"path": "../jest-worker"}, - {"path": "../test-utils"} + {"path": "../jest-worker"} ] } diff --git a/packages/jest-matcher-utils/src/__tests__/tsconfig.json b/packages/jest-matcher-utils/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-matcher-utils/src/__tests__/tsconfig.json +++ b/packages/jest-matcher-utils/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-matcher-utils/tsconfig.json b/packages/jest-matcher-utils/tsconfig.json index 3905821cea60..e59af10a490f 100644 --- a/packages/jest-matcher-utils/tsconfig.json +++ b/packages/jest-matcher-utils/tsconfig.json @@ -10,7 +10,6 @@ "references": [ {"path": "../jest-diff"}, {"path": "../jest-get-type"}, - {"path": "../pretty-format"}, - {"path": "../test-utils"} + {"path": "../pretty-format"} ] } diff --git a/packages/jest-reporters/src/__tests__/tsconfig.json b/packages/jest-reporters/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-reporters/src/__tests__/tsconfig.json +++ b/packages/jest-reporters/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-reporters/tsconfig.json b/packages/jest-reporters/tsconfig.json index 813ba257479e..86a51036fda6 100644 --- a/packages/jest-reporters/tsconfig.json +++ b/packages/jest-reporters/tsconfig.json @@ -14,7 +14,6 @@ {"path": "../jest-transform"}, {"path": "../jest-types"}, {"path": "../jest-util"}, - {"path": "../jest-worker"}, - {"path": "../test-utils"} + {"path": "../jest-worker"} ] } diff --git a/packages/jest-resolve-dependencies/src/__tests__/tsconfig.json b/packages/jest-resolve-dependencies/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-resolve-dependencies/src/__tests__/tsconfig.json +++ b/packages/jest-resolve-dependencies/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-resolve-dependencies/tsconfig.json b/packages/jest-resolve-dependencies/tsconfig.json index a1307345772a..503f05242ff2 100644 --- a/packages/jest-resolve-dependencies/tsconfig.json +++ b/packages/jest-resolve-dependencies/tsconfig.json @@ -12,7 +12,6 @@ {"path": "../jest-resolve"}, {"path": "../jest-runtime"}, {"path": "../jest-snapshot"}, - {"path": "../jest-types"}, - {"path": "../test-utils"} + {"path": "../jest-types"} ] } diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index c44fe957ced6..becf440e57f3 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -40,6 +40,7 @@ "source-map-support": "0.5.13" }, "devDependencies": { + "@jest/test-utils": "workspace:^", "@tsd/typescript": "^4.9.0", "@types/exit": "^0.1.30", "@types/graceful-fs": "^4.1.3", diff --git a/packages/jest-runner/src/__tests__/tsconfig.json b/packages/jest-runner/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-runner/src/__tests__/tsconfig.json +++ b/packages/jest-runner/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-runtime/src/__tests__/tsconfig.json b/packages/jest-runtime/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-runtime/src/__tests__/tsconfig.json +++ b/packages/jest-runtime/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-runtime/tsconfig.json b/packages/jest-runtime/tsconfig.json index 90a3eb84bddd..e62786852942 100644 --- a/packages/jest-runtime/tsconfig.json +++ b/packages/jest-runtime/tsconfig.json @@ -23,7 +23,6 @@ {"path": "../jest-test-result"}, {"path": "../jest-transform"}, {"path": "../jest-types"}, - {"path": "../jest-util"}, - {"path": "../test-utils"} + {"path": "../jest-util"} ] } diff --git a/packages/jest-snapshot/src/__tests__/tsconfig.json b/packages/jest-snapshot/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-snapshot/src/__tests__/tsconfig.json +++ b/packages/jest-snapshot/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-snapshot/tsconfig.json b/packages/jest-snapshot/tsconfig.json index 411a0f5a3a83..c9d79155bd00 100644 --- a/packages/jest-snapshot/tsconfig.json +++ b/packages/jest-snapshot/tsconfig.json @@ -17,7 +17,6 @@ {"path": "../jest-transform"}, {"path": "../jest-types"}, {"path": "../jest-util"}, - {"path": "../pretty-format"}, - {"path": "../test-utils"} + {"path": "../pretty-format"} ] } diff --git a/packages/jest-test-sequencer/src/__tests__/tsconfig.json b/packages/jest-test-sequencer/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-test-sequencer/src/__tests__/tsconfig.json +++ b/packages/jest-test-sequencer/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-test-sequencer/tsconfig.json b/packages/jest-test-sequencer/tsconfig.json index 7d3736031d3b..cdf9b3d35d19 100644 --- a/packages/jest-test-sequencer/tsconfig.json +++ b/packages/jest-test-sequencer/tsconfig.json @@ -6,9 +6,5 @@ }, "include": ["./src/**/*"], "exclude": ["./**/__tests__/**/*"], - "references": [ - {"path": "../jest-haste-map"}, - {"path": "../jest-test-result"}, - {"path": "../test-utils"} - ] + "references": [{"path": "../jest-haste-map"}, {"path": "../jest-test-result"}] } diff --git a/packages/jest-transform/src/__tests__/tsconfig.json b/packages/jest-transform/src/__tests__/tsconfig.json index dd1bca103251..d603a17f8dfe 100644 --- a/packages/jest-transform/src/__tests__/tsconfig.json +++ b/packages/jest-transform/src/__tests__/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../../../tsconfig.test.json", "include": ["./**/*"], - "references": [{"path": "../../"}] + "references": [{"path": "../../"}, {"path": "../../../test-utils"}] } diff --git a/packages/jest-transform/tsconfig.json b/packages/jest-transform/tsconfig.json index b663b58b48db..cd4148bc6954 100644 --- a/packages/jest-transform/tsconfig.json +++ b/packages/jest-transform/tsconfig.json @@ -10,7 +10,6 @@ {"path": "../jest-haste-map"}, {"path": "../jest-regex-util"}, {"path": "../jest-types"}, - {"path": "../jest-util"}, - {"path": "../test-utils"} + {"path": "../jest-util"} ] } diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index b064dd1ef7c8..4c090092b54e 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -12,6 +12,7 @@ "./package.json": "./package.json" }, "dependencies": { + "@jest/globals": "workspace:^", "@jest/types": "workspace:^", "@types/node": "*", "ansi-regex": "^5.0.1", diff --git a/packages/test-utils/src/ConditionalTest.ts b/packages/test-utils/src/ConditionalTest.ts index badcb0c10ada..879c95bf06fd 100644 --- a/packages/test-utils/src/ConditionalTest.ts +++ b/packages/test-utils/src/ConditionalTest.ts @@ -5,11 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import semver = require('semver'); -import type {Global} from '@jest/types'; +/* eslint-disable jest/no-focused-tests */ -declare const describe: Global.TestFrameworkGlobals['describe']; -declare const test: Global.TestFrameworkGlobals['test']; +import semver = require('semver'); +import {describe, test} from '@jest/globals'; export function isJestJasmineRun(): boolean { return process.env.JEST_JASMINE === '1'; diff --git a/packages/test-utils/tsconfig.json b/packages/test-utils/tsconfig.json index 110097eb7fef..bcc1e9b530ae 100644 --- a/packages/test-utils/tsconfig.json +++ b/packages/test-utils/tsconfig.json @@ -5,5 +5,9 @@ "outDir": "build" }, "include": ["./src/**/*"], - "references": [{"path": "../jest-types"}, {"path": "../pretty-format"}] + "references": [ + {"path": "../jest-globals"}, + {"path": "../jest-types"}, + {"path": "../pretty-format"} + ] } diff --git a/scripts/buildTs.mjs b/scripts/buildTs.mjs index 72dcdab405d9..29f50731bd6b 100644 --- a/scripts/buildTs.mjs +++ b/scripts/buildTs.mjs @@ -57,6 +57,12 @@ packagesWithTs.forEach(({packageDir, pkg}) => { } } + // only test files depend on '@jest/test-utils', i.e. it is always a dev dependency + // see additional checks below + if (dep === '@jest/test-utils') { + return false; + } + return true; }) .map(dep => @@ -84,6 +90,60 @@ packagesWithTs.forEach(({packageDir, pkg}) => { )}\nExpected:\n\n${jestDependenciesOfPackage.join('\n')}`, ); } + + let hasJestTestUtils = Object.keys(pkg.dependencies || {}).includes( + '@jest/test-utils', + ); + + if (hasJestTestUtils) { + throw new Error( + chalk.red( + `Package '${pkg.name}' declares '@jest/test-utils' as dependency, but it must be declared as dev dependency`, + ), + ); + } + + hasJestTestUtils = Object.keys(pkg.devDependencies || {}).includes( + '@jest/test-utils', + ); + + const tsConfigPaths = glob.sync('**/__tests__/tsconfig.json', { + absolute: true, + cwd: packageDir, + }); + + const testUtilsReferences = tsConfigPaths.filter(tsConfigPath => { + const tsConfig = JSON.parse( + stripJsonComments(fs.readFileSync(tsConfigPath, 'utf8')), + ); + const references = tsConfig.references.map(({path}) => path); + + return references.some(reference => /test-utils$/.test(reference)); + }); + + if (hasJestTestUtils && testUtilsReferences.length === 0) { + throw new Error( + chalk.red( + `Package '${ + pkg.name + }' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\n\n${tsConfigPaths.join( + '\n', + )}`, + ), + ); + } + + if (!hasJestTestUtils && testUtilsReferences.length > 0) { + throw new Error( + chalk.red( + `Package '${ + pkg.name + }' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\n\n${testUtilsReferences.join( + '\n', + )}`, + ), + ); + } }); const args = [ diff --git a/scripts/checkChangelog.mjs b/scripts/checkChangelog.mjs new file mode 100644 index 000000000000..85cc6d0119b7 --- /dev/null +++ b/scripts/checkChangelog.mjs @@ -0,0 +1,31 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import fs from 'graceful-fs'; + +const linkRegex = + /\[#(\d+)\]\(https:\/\/github.com\/facebook\/jest\/(issues|pull)\/(\d+)\)/g; + +const changelogPath = 'CHANGELOG.md'; +const data = fs.readFileSync(changelogPath, 'utf-8'); + +let error = false; +let lineNumber = 1; +for (const line of data.split('\n')) { + for (const match of line.matchAll(linkRegex)) + if (match[1] !== match[3]) { + const column = match.index + 1; + console.error( + `${changelogPath}:${lineNumber}:${column}: error: ` + + `Link is incorrect: ${match[0]}`, + ); + error = true; + } + ++lineNumber; +} + +process.exit(error ? 1 : 0); diff --git a/website/blog/2016-04-12-jest-11.md b/website/blog/2016-04-12-jest-11.md index af68f07cbc87..230e5f32c7ac 100644 --- a/website/blog/2016-04-12-jest-11.md +++ b/website/blog/2016-04-12-jest-11.md @@ -9,7 +9,7 @@ Today we're announcing a switch to major revisions for Jest with Jest 11.0 being If you are using Jest 0.9 or Jest 0.10 the upgrade should be seamless. All changes from the last few months were rolled into Jest 11.0. -### New in Jest 11.0. +### New in Jest 11.0 #### Babel Integration and Simplified Setup diff --git a/website/blog/2016-07-27-jest-14.md b/website/blog/2016-07-27-jest-14.md index 79babd8fd57c..77ddd42b622b 100644 --- a/website/blog/2016-07-27-jest-14.md +++ b/website/blog/2016-07-27-jest-14.md @@ -63,7 +63,11 @@ You can start using Jest with react-native by running `yarn add --dev jest-react - [Example project](https://github.com/facebook/jest/tree/main/examples/react-native) - [Example pull request for _snowflake_](https://github.com/bartonhammond/snowflake/pull/110), a popular react-native open source library. -_Note: the preset currently only implements the minimal set of configuration necessary to get started with React Native testing. We are hoping for community contributions to improve this project. Please try it and file [issues](https://github.com/facebook/jest/issues) or send pull requests!_ +:::info + +The preset currently only implements the minimal set of configuration necessary to get started with React Native testing. We are hoping for community contributions to improve this project. Please try it and file [issues](https://github.com/facebook/jest/issues) or send pull requests! + +::: ## Why snapshot testing? diff --git a/website/blog/2016-09-01-jest-15.md b/website/blog/2016-09-01-jest-15.md index 0fc020d7aae6..e7afc6369dd7 100644 --- a/website/blog/2016-09-01-jest-15.md +++ b/website/blog/2016-09-01-jest-15.md @@ -27,7 +27,7 @@ We completely rewrote `jest --watch` to be more interactive. It can now switch b Mocks for `ListView`, `TextInput`, `ActivityIndicator`, `ScrollView` and more were added. The existing mocks were updated to use the real implementations and existing snapshots likely have to be updated when upgrading to Jest 15. A `mockComponent` function was added to `jest-react-native` that can be used to mock native components: -``` +```js jest.mock('MyNativeComponent', () => { const jestReactNative = require('jest-react-native'); return jestReactNative.mockComponent('MyNativeComponent'); @@ -60,12 +60,12 @@ This has lead to numerous incompatibilities. We also noticed that at Facebook we Here is an example: -``` +```js const React1 = require('react'); jest.resetModules(); const React2 = require('react'); -React1 !== React2 // These two are separate copies of React. +React1 !== React2; // These two are separate copies of React. ``` The call to `resetModules` wipes away the require cache. A second call to require the same module will result in a new instantiation of the same module and all of its dependencies. This feature is especially useful when dealing with modules that have side effects, like [jest-haste-map](https://github.com/facebook/jest/blob/3bbf32a239fc4aad8cc6928a787f235bd86fecac/packages/jest-haste-map/src/__tests__/index-test.js#L64). diff --git a/website/blog/2016-12-15-2016-in-jest.md b/website/blog/2016-12-15-2016-in-jest.md index 19942581ab08..307c7319930a 100644 --- a/website/blog/2016-12-15-2016-in-jest.md +++ b/website/blog/2016-12-15-2016-in-jest.md @@ -61,20 +61,20 @@ Jest was initially created more than five years ago and as such an old framework - **Breaking:** Replaced `scriptPreprocessor` with the new `transform` option. - **Breaking:** The `testResultsProcessor` function is now required to return the modified results. - **Potentially Breaking:** Properly resolve `snapshotSerializers`, `setupFiles`, `transform`, `testRunner` and `testResultsProcessor` with a resolution algorithm instead of using `path.resolve`. This mainly means that `` is no longer needed for these options. -- **Added: **`pretty-format` and `jest-editor-support` were merged into Jest. +- **Added:** `pretty-format` and `jest-editor-support` were merged into Jest. - **Added:** `expect.any`, `expect.anything`, `expect.objectContaining`, `expect.arrayContaining`, `expect.stringMatching`. -- **Added: **`--testResultsProcessor` is now exposed through the cli. +- **Added:** `--testResultsProcessor` is now exposed through the cli. - **Added:** Implemented file watching in `jest-haste-map`. - **Added:** Usage of Jest in watch mode can be hidden through `JEST_HIDE_USAGE`. - **Added:** `expect.assertions(number)` which will ensure that a specified amount of assertions is made in one test. -- **Added: **`.toMatchSnapshot(?string)` feature to give snapshots a name. -- **Added: **`toMatchObject`, `toHaveProperty` , `toHaveLength` matchers. +- **Added:** `.toMatchSnapshot(?string)` feature to give snapshots a name. +- **Added:** `toMatchObject`, `toHaveProperty` , `toHaveLength` matchers. - **Added:** `expect.extend`. - **Added:** Added support for custom snapshots serializers. - **Added:** Big diffs are now collapsed by default in snapshots and assertions. Added `--expand` (or `-e`) to show the full diff. - **Added:** `jest.resetAllMocks` which replaces `jest.clearAllMocks`. -- **Added: **`--json` now includes information about individual tests inside a file. -- **Fixed: **`test.concurrent` unhandled promise rejections. +- **Added:** `--json` now includes information about individual tests inside a file. +- **Fixed:** `test.concurrent` unhandled promise rejections. - **Fixed:** `babel-plugin-jest-hoist` when using `jest.mock` with three arguments. - **Fixed:** The `JSON` global in `jest-environment-node` now comes from the vm context instead of the parent context. - **Fixed:** Jest does not print stack traces from babel any longer. @@ -84,16 +84,16 @@ Jest was initially created more than five years ago and as such an old framework - **Fixed:** `NaN% Failed` in the OS notification when using `--notify`. - **Fixed:** The first test run without cached timings will now use separate processes instead of running in band. - **Fixed:** `Map`/`Set` comparisons. -- **Fixed: **`test.concurrent` now works with `--testNamePattern`. +- **Fixed:** `test.concurrent` now works with `--testNamePattern`. - **Fixed:** Improved `.toContain` matcher. - **Fixed:** Properly resolve modules with platform extensions on react-native. - **Fixed:** global built in objects in `jest-environment-node` now work properly. - **Fixed:** Create mock objects in the vm context instead of the parent context. -- **Fixed: **`.babelrc` is now part of the transform cache key in `babel-jest`. +- **Fixed:** `.babelrc` is now part of the transform cache key in `babel-jest`. - **Fixed:** docblock parsing with haste modules. - **Fixed:** Exit with the proper code when the coverage threshold is not reached. -- **Fixed: **Jest now clears the entire scrollback in watch mode. -- **Deprecated: **`jest-react-native` was deprecated and now forwards `react-native`. +- **Fixed:** Jest now clears the entire scrollback in watch mode. +- **Deprecated:** `jest-react-native` was deprecated and now forwards `react-native`. ## Plans for Jest in H1 2017 @@ -102,7 +102,7 @@ Six months ago [we shared our plans for Jest](/blog/2016/07/27/jest-14#what-s-ne - **Instant feedback:** [Nuclide](https://nuclide.io/) integration and an improved and [faster watch mode](https://github.com/facebook/jest/pull/2324#issuecomment-267149669). - **Improved developer experience:** new mocking APIs and improved assertions. - **Better performance and memory usage:** analyze Jest and be more conscious about efficiency. -- **Snapshot Improvements: **snapshot approval mode, syntax highlighting and improved `react-test-renderer` APIs. +- **Snapshot Improvements:** snapshot approval mode, syntax highlighting and improved `react-test-renderer` APIs. - **Website:** We'll overhaul the website and documentation and add a Jest cheat sheet. We won't be providing timelines or estimates for these features and we may not actually get to all of these things. If you'd like to help make these things a reality, send us issues and pull requests with your ideas and let's work on improving Jest together in 2017. diff --git a/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md b/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md index b35b32016f50..372b43bfe026 100644 --- a/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md +++ b/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md @@ -23,7 +23,7 @@ We made a couple of changes to the snapshot format. We don't make changes like t Before: -``` +```js exports[`test snap 1`] = `

@@ -37,7 +37,7 @@ exports[`test snap 1`] = ` After (no “test” prefix, better JSX rendering, version header): -``` +```js // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`snap 1`] = ` diff --git a/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md b/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md index a17f26439b59..aa7ed8bbe447 100644 --- a/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md +++ b/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md @@ -19,7 +19,7 @@ Jest is now collapsing the usage guide after the first test run to save vertical Further, we completely overhauled how the configuration system works inside of Jest. You can now pass any configuration option through the CLI to overwrite the ones specified in your configuration file. Along with that, we changed Jest to look for a `jest.config.js` file by default which means you are now able to define a Jest configuration using JavaScript as well as being able to configure it through `package.json` like before. Through the addition of all these new features, you are now able to combine Jest in more powerful ways than ever before. For example, if you would like to find out which tests Jest would run given a set of changed files from a commit across multiple projects in a monorepo, you can combine cli arguments like this now: -``` +```bash $ jest --projects projectA projectB --listTests --findRelatedTests projectA/banana.js projectB/kiwi.js [ "projectA/banana.test.js", diff --git a/website/blog/2018-06-27-supporting-jest-open-source.md b/website/blog/2018-06-27-supporting-jest-open-source.md index c3ec31ad6adb..b15d24a171ea 100644 --- a/website/blog/2018-06-27-supporting-jest-open-source.md +++ b/website/blog/2018-06-27-supporting-jest-open-source.md @@ -17,13 +17,13 @@ In this post we'll outline what the Jest Open Collective is, the structure, and -# The Jest Open Collective +## The Jest Open Collective ![Banner image for Jest Open Collective](/img/blog/collective.png) Open Collective is a platform to manage groups of people transparently. Jest joins projects like [webpack](https://opencollective.com/webpack), [Babel](https://opencollective.com/babel), [Mocha](https://opencollective.com/mochajs), [Preact](https://opencollective.com/preact), [Vue](https://opencollective.com/vuejs), and many more in supporting the open source community through the Open Collective platform. -## What is the Jest Open Collective +### What is the Jest Open Collective The Jest Open Collective is a group of open source contributors who operate in full transparency to: @@ -31,7 +31,7 @@ The Jest Open Collective is a group of open source contributors who operate in f - Approve expenses submitted by the community - Give everyone visibility on the budget -## What is the structure of the collective +### What is the structure of the collective The Jest Open Collective is currently managed by three non-Facebook core contributors from the open source community: @@ -43,15 +43,15 @@ Michal has been an active Jest contributor since September 2016, Simen joined th There are two levels of support for the collective: Backer and Sponsor. -### Backers +#### Backers Backers of the collective are individuals contributing at least \$2/month. We'll include a list of backers on the Jest homepage, README on github/yarn/npm, and Contributors page. -### Sponsors +#### Sponsors -Sponsors of the collective are individuals and organizations contributing at least \$100/month. We'll place sponsor logos with a link to their site on the Jest homepage, README on github/yarn/npm, and Contributors page. +Sponsors of the collective are individuals and organizations contributing at least $100/month. We'll place sponsor logos with a link to their site on the Jest homepage, README on github/yarn/npm, and Contributors page. -## What is the goal of the collective +### What is the goal of the collective The goal of the collective is to support the work of open source contributors to Jest in order to make testing delightful. @@ -64,7 +64,7 @@ To achieve that goal, we will use the funds to: This is just the beginning and we're committed to getting this right. If you have ideas on how else we can support the community, or feedback on the structure of the collective, please reach out to us on [twitter](https://twitter.com/fbjest)! -# Thank You +## Thank You Finally, thank you to everyone who contributes to the Jest community and open source in general. We are incredibly grateful that we get the opportunity to work on improving JavaScript testing together. diff --git a/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md b/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md index 21ff728b565e..2083a34edebe 100644 --- a/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md +++ b/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md @@ -27,7 +27,11 @@ If you want to run typechecks while you test, you should use [`ts-jest`](https:/ See [the docs](/docs/getting-started#using-typescript) for more details. -_Note that if you for whatever reason cannot upgrade to Babel 7, you can still use Jest 24 with `babel@6` as long as you keep `babel-jest` at version 23._ +:::tip + +If you for whatever reason cannot upgrade to Babel 7, you can still use Jest 24 with `babel@6` as long as you keep `babel-jest` at version 23. + +::: ## `test.todo` diff --git a/website/blog/2022-08-25-jest-29.md b/website/blog/2022-08-25-jest-29.md index e8014f818388..9ab4001bc644 100644 --- a/website/blog/2022-08-25-jest-29.md +++ b/website/blog/2022-08-25-jest-29.md @@ -9,7 +9,7 @@ Jest 29 is here, just a few short months after Jest 28. As mentioned in the [Jes -The only breaking changes that should be noticable are: +The only breaking changes that should be noticeable are: - Node versions 12 and 17 are dropped, both of which are EOL - The `snapshotFormat` property is changed to: diff --git a/website/static/img/logos/ibm.png b/website/static/img/logos/ibm.png new file mode 100644 index 000000000000..f8ddd46d8789 Binary files /dev/null and b/website/static/img/logos/ibm.png differ diff --git a/website/static/img/logos/paypal.png b/website/static/img/logos/paypal.png new file mode 100644 index 000000000000..532b2be40f1a Binary files /dev/null and b/website/static/img/logos/paypal.png differ diff --git a/website/static/img/logos/pinterest.png b/website/static/img/logos/pinterest.png new file mode 100644 index 000000000000..a45c216811a3 Binary files /dev/null and b/website/static/img/logos/pinterest.png differ diff --git a/website/versioned_docs/version-25.x/Webpack.md b/website/versioned_docs/version-25.x/Webpack.md index 95a7e0676a32..df81d1a0289f 100644 --- a/website/versioned_docs/version-25.x/Webpack.md +++ b/website/versioned_docs/version-25.x/Webpack.md @@ -201,7 +201,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-26.x/Webpack.md b/website/versioned_docs/version-26.x/Webpack.md index 95a7e0676a32..df81d1a0289f 100644 --- a/website/versioned_docs/version-26.x/Webpack.md +++ b/website/versioned_docs/version-26.x/Webpack.md @@ -201,7 +201,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-27.x/Webpack.md b/website/versioned_docs/version-27.x/Webpack.md index 95a7e0676a32..df81d1a0289f 100644 --- a/website/versioned_docs/version-27.x/Webpack.md +++ b/website/versioned_docs/version-27.x/Webpack.md @@ -201,7 +201,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-28.x/Webpack.md b/website/versioned_docs/version-28.x/Webpack.md index 95a7e0676a32..df81d1a0289f 100644 --- a/website/versioned_docs/version-28.x/Webpack.md +++ b/website/versioned_docs/version-28.x/Webpack.md @@ -201,7 +201,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-29.0/Webpack.md b/website/versioned_docs/version-29.0/Webpack.md index 95a7e0676a32..df81d1a0289f 100644 --- a/website/versioned_docs/version-29.0/Webpack.md +++ b/website/versioned_docs/version-29.0/Webpack.md @@ -201,7 +201,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-29.1/Webpack.md b/website/versioned_docs/version-29.1/Webpack.md index 95a7e0676a32..df81d1a0289f 100644 --- a/website/versioned_docs/version-29.1/Webpack.md +++ b/website/versioned_docs/version-29.1/Webpack.md @@ -201,7 +201,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-29.2/Webpack.md b/website/versioned_docs/version-29.2/Webpack.md index 95a7e0676a32..df81d1a0289f 100644 --- a/website/versioned_docs/version-29.2/Webpack.md +++ b/website/versioned_docs/version-29.2/Webpack.md @@ -201,7 +201,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-29.3/Webpack.md b/website/versioned_docs/version-29.3/Webpack.md index 84b8944b7c4f..699ef4c9f805 100644 --- a/website/versioned_docs/version-29.3/Webpack.md +++ b/website/versioned_docs/version-29.3/Webpack.md @@ -202,7 +202,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/website/versioned_docs/version-29.4/ExpectAPI.md b/website/versioned_docs/version-29.4/ExpectAPI.md index 87aa7c37b0c3..4f206f5cf8bb 100644 --- a/website/versioned_docs/version-29.4/ExpectAPI.md +++ b/website/versioned_docs/version-29.4/ExpectAPI.md @@ -1262,7 +1262,7 @@ These helper functions and properties can be found on `this` inside a custom tes #### `this.equals(a, b, customTesters?)` -This is a deep-equality function that will return `true` if two objects have the same values (recursively). It optionally takes a list of custom equality testers to apply to the deep equality checks. If you use this function, pass through the custom testers your tester is given so further equality checks `equals` applies can also use custom testers the test author may have configured. See the example in the [Recursive custom equality testers][#recursivecustomequalitytesters] section for more details. +This is a deep-equality function that will return `true` if two objects have the same values (recursively). It optionally takes a list of custom equality testers to apply to the deep equality checks. If you use this function, pass through the custom testers your tester is given so further equality checks `equals` applies can also use custom testers the test author may have configured. See the example in the [Recursive custom equality testers](#recursive-custom-equality-testers) section for more details. #### Matchers vs Testers diff --git a/website/versioned_docs/version-29.4/Webpack.md b/website/versioned_docs/version-29.4/Webpack.md index 84b8944b7c4f..699ef4c9f805 100644 --- a/website/versioned_docs/version-29.4/Webpack.md +++ b/website/versioned_docs/version-29.4/Webpack.md @@ -202,7 +202,7 @@ For more complex webpack configurations, you may also want to investigate projec In addition to installing `babel-jest` as described earlier, you'll need to add `@babel/preset-env` like so: ```bash npm2yarn - npm install --save-dev @babel/preset-env +npm install --save-dev @babel/preset-env ``` Then, you'll want to configure Babel as follows: diff --git a/yarn.lock b/yarn.lock index 6621ce616bd1..b25ad34476ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2970,6 +2970,7 @@ __metadata: version: 0.0.0-use.local resolution: "@jest/test-utils@workspace:packages/test-utils" dependencies: + "@jest/globals": "workspace:^" "@jest/types": "workspace:^" "@types/node": "*" "@types/semver": ^7.1.0 @@ -12768,7 +12769,6 @@ __metadata: version: 0.0.0-use.local resolution: "jest-haste-map@workspace:packages/jest-haste-map" dependencies: - "@jest/test-utils": "workspace:^" "@jest/types": "workspace:^" "@types/fb-watchman": ^2.0.0 "@types/graceful-fs": ^4.1.3 @@ -12996,6 +12996,7 @@ __metadata: "@jest/console": "workspace:^" "@jest/environment": "workspace:^" "@jest/test-result": "workspace:^" + "@jest/test-utils": "workspace:^" "@jest/transform": "workspace:^" "@jest/types": "workspace:^" "@tsd/typescript": ^4.9.0