diff --git a/CHANGELOG.md b/CHANGELOG.md index e582b9ff33db..21d825c9c92e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixes +- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638)) - `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708)) - `[jest-resolve]` Replace read-pkg-up with escalade package ([#10781](https://github.com/facebook/jest/pull/10781)) - `[jest-runtime]` [**BREAKING**] Do not inject `global` variable into module wrapper ([#10644](https://github.com/facebook/jest/pull/10644)) diff --git a/docs/CLI.md b/docs/CLI.md index a2ca1f24b41a..08438abc085d 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -266,6 +266,10 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. diff --git a/docs/TutorialReactNative.md b/docs/TutorialReactNative.md index d0e1d4fc428a..fdebb6f84867 100644 --- a/docs/TutorialReactNative.md +++ b/docs/TutorialReactNative.md @@ -35,6 +35,19 @@ Let's create a [snapshot test](SnapshotTesting.md) for a small intro component w import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; +class Intro extends Component { + render() { + return ( + + Welcome to React Native! + + This is a React Native snapshot test. + + + ); + } +} + const styles = StyleSheet.create({ container: { alignItems: 'center', @@ -54,18 +67,7 @@ const styles = StyleSheet.create({ }, }); -export default class Intro extends Component { - render() { - return ( - - Welcome to React Native! - - This is a React Native snapshot test. - - - ); - } -} +export default Intro; ``` Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file: diff --git a/packages/jest-console/src/BufferedConsole.ts b/packages/jest-console/src/BufferedConsole.ts index 55c4e20ffc95..8d67c968dea7 100644 --- a/packages/jest-console/src/BufferedConsole.ts +++ b/packages/jest-console/src/BufferedConsole.ts @@ -7,7 +7,7 @@ import assert = require('assert'); import {Console} from 'console'; -import {format} from 'util'; +import {format, formatWithOptions, inspect} from 'util'; import chalk = require('chalk'); import {ErrorWithStack, formatTime} from 'jest-util'; import type { @@ -95,8 +95,9 @@ export default class BufferedConsole extends Console { this._log('debug', format(firstArg, ...rest)); } - dir(firstArg: unknown, ...rest: Array): void { - this._log('dir', format(firstArg, ...rest)); + dir(firstArg: unknown, options: NodeJS.InspectOptions = {}): void { + const representation = inspect(firstArg, options); + this._log('dir', formatWithOptions(options, representation)); } dirxml(firstArg: unknown, ...rest: Array): void { diff --git a/packages/jest-console/src/CustomConsole.ts b/packages/jest-console/src/CustomConsole.ts index 5c3ed54da576..cbf8cf768ee3 100644 --- a/packages/jest-console/src/CustomConsole.ts +++ b/packages/jest-console/src/CustomConsole.ts @@ -7,7 +7,7 @@ import assert = require('assert'); import {Console} from 'console'; -import {format} from 'util'; +import {format, formatWithOptions, inspect} from 'util'; import chalk = require('chalk'); import {clearLine, formatTime} from 'jest-util'; import type {LogCounters, LogMessage, LogTimers, LogType} from './types'; @@ -73,8 +73,9 @@ export default class CustomConsole extends Console { this._log('debug', format(firstArg, ...args)); } - dir(firstArg: unknown, ...args: Array): void { - this._log('dir', format(firstArg, ...args)); + dir(firstArg: unknown, options: NodeJS.InspectOptions = {}): void { + const representation = inspect(firstArg, options); + this._log('dir', formatWithOptions(options, representation)); } dirxml(firstArg: unknown, ...args: Array): void { diff --git a/packages/jest-console/src/__tests__/CustomConsole.test.ts b/packages/jest-console/src/__tests__/CustomConsole.test.ts index 07bb5cf4f888..b4c1b6d4e0d0 100644 --- a/packages/jest-console/src/__tests__/CustomConsole.test.ts +++ b/packages/jest-console/src/__tests__/CustomConsole.test.ts @@ -187,6 +187,16 @@ describe('CustomConsole', () => { }); }); + describe('dir', () => { + test('should print the deepest value', () => { + const deepObject = {1: {2: {3: {4: {5: {6: 'value'}}}}}}; + _console.dir(deepObject, {depth: 6}); + + expect(_stdout).toMatch('value'); + expect(_stdout).not.toMatch('depth'); + }); + }); + describe('timeLog', () => { test('should return the time between time() and timeEnd() on default timer', () => { _console.time(); diff --git a/packages/jest-console/src/__tests__/bufferedConsole.test.ts b/packages/jest-console/src/__tests__/bufferedConsole.test.ts index 8b0ee9f98439..59e37ebfd116 100644 --- a/packages/jest-console/src/__tests__/bufferedConsole.test.ts +++ b/packages/jest-console/src/__tests__/bufferedConsole.test.ts @@ -147,6 +147,16 @@ describe('CustomConsole', () => { }); }); + describe('dir', () => { + test('should print the deepest value', () => { + const deepObject = {1: {2: {3: {4: {5: {6: 'value'}}}}}}; + _console.dir(deepObject, {depth: 6}); + + expect(stdout()).toMatch('value'); + expect(stdout()).not.toMatch('depth'); + }); + }); + describe('timeLog', () => { test('should return the time between time() and timeEnd() on default timer', () => { _console.time(); diff --git a/website/versioned_docs/version-22.x/CLI.md b/website/versioned_docs/version-22.x/CLI.md index 380117bbbe7d..13780a978282 100644 --- a/website/versioned_docs/version-22.x/CLI.md +++ b/website/versioned_docs/version-22.x/CLI.md @@ -212,6 +212,10 @@ Run tests with specified reporters. Run tests with specified reporters. Example `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. diff --git a/website/versioned_docs/version-22.x/TutorialReactNative.md b/website/versioned_docs/version-22.x/TutorialReactNative.md index 0a1fd3b51f94..8b4b8e4330b3 100644 --- a/website/versioned_docs/version-22.x/TutorialReactNative.md +++ b/website/versioned_docs/version-22.x/TutorialReactNative.md @@ -36,6 +36,19 @@ Let's create a [snapshot test](SnapshotTesting.md) for a small intro component w import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; +class Intro extends Component { + render() { + return ( + + Welcome to React Native! + + This is a React Native snapshot test. + + + ); + } +} + const styles = StyleSheet.create({ container: { alignItems: 'center', @@ -55,18 +68,7 @@ const styles = StyleSheet.create({ }, }); -export default class Intro extends Component { - render() { - return ( - - Welcome to React Native! - - This is a React Native snapshot test. - - - ); - } -} +export default Intro; ``` Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file: diff --git a/website/versioned_docs/version-23.x/CLI.md b/website/versioned_docs/version-23.x/CLI.md index eb563214d8ad..b24a5bb6c9b0 100644 --- a/website/versioned_docs/version-23.x/CLI.md +++ b/website/versioned_docs/version-23.x/CLI.md @@ -224,6 +224,10 @@ Run tests with specified reporters. Example with multiple reporters: `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. diff --git a/website/versioned_docs/version-24.x/CLI.md b/website/versioned_docs/version-24.x/CLI.md index fff26f1b8d0b..e109d35d8585 100644 --- a/website/versioned_docs/version-24.x/CLI.md +++ b/website/versioned_docs/version-24.x/CLI.md @@ -245,6 +245,10 @@ Run tests with specified reporters. Example with multiple reporters: `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. diff --git a/website/versioned_docs/version-25.x/CLI.md b/website/versioned_docs/version-25.x/CLI.md index b534059d9860..72ee068ee2fb 100644 --- a/website/versioned_docs/version-25.x/CLI.md +++ b/website/versioned_docs/version-25.x/CLI.md @@ -255,6 +255,10 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. diff --git a/website/versioned_docs/version-25.x/TutorialReactNative.md b/website/versioned_docs/version-25.x/TutorialReactNative.md index 7ad8f4d6e3f7..712cdd72946b 100644 --- a/website/versioned_docs/version-25.x/TutorialReactNative.md +++ b/website/versioned_docs/version-25.x/TutorialReactNative.md @@ -36,6 +36,19 @@ Let's create a [snapshot test](SnapshotTesting.md) for a small intro component w import React, {Component} from 'react'; import {StyleSheet, Text, View} from 'react-native'; +class Intro extends Component { + render() { + return ( + + Welcome to React Native! + + This is a React Native snapshot test. + + + ); + } +} + const styles = StyleSheet.create({ container: { alignItems: 'center', @@ -55,18 +68,7 @@ const styles = StyleSheet.create({ }, }); -export default class Intro extends Component { - render() { - return ( - - Welcome to React Native! - - This is a React Native snapshot test. - - - ); - } -} +export default Intro; ``` Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file: diff --git a/website/versioned_docs/version-26.0/CLI.md b/website/versioned_docs/version-26.0/CLI.md index 11d24b2e56cf..9fae38c31c2c 100644 --- a/website/versioned_docs/version-26.0/CLI.md +++ b/website/versioned_docs/version-26.0/CLI.md @@ -251,6 +251,10 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. diff --git a/website/versioned_docs/version-26.2/CLI.md b/website/versioned_docs/version-26.2/CLI.md index ff9c719814cd..4311717eef53 100644 --- a/website/versioned_docs/version-26.2/CLI.md +++ b/website/versioned_docs/version-26.2/CLI.md @@ -251,6 +251,10 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. diff --git a/website/versioned_docs/version-26.5/CLI.md b/website/versioned_docs/version-26.5/CLI.md index 64968b991597..d0496ccf4cb0 100644 --- a/website/versioned_docs/version-26.5/CLI.md +++ b/website/versioned_docs/version-26.5/CLI.md @@ -267,6 +267,10 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a `jest --reporters="default" --reporters="jest-junit"` +### `--roots` + +A list of paths to directories that Jest should use to search for files in. + ### `--runInBand` Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.