Skip to content

Commit

Permalink
Merge branch 'master' into uglier-inline-snapshots
Browse files Browse the repository at this point in the history
* master:
  chore(docs): update TutorialReactNative.md (jestjs#10802)
  fix: console dir should respect options (jestjs#10638)
  docs: add missing "--roots" options (jestjs#10793)
  • Loading branch information
jeysal committed Nov 10, 2020
2 parents 81bc81e + bafb4eb commit be68e58
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions docs/CLI.md
Expand Up @@ -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.
Expand Down
26 changes: 14 additions & 12 deletions docs/TutorialReactNative.md
Expand Up @@ -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 (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
alignItems: 'center',
Expand All @@ -54,18 +67,7 @@ const styles = StyleSheet.create({
},
});

export default class Intro extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}
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:
Expand Down
7 changes: 4 additions & 3 deletions packages/jest-console/src/BufferedConsole.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -95,8 +95,9 @@ export default class BufferedConsole extends Console {
this._log('debug', format(firstArg, ...rest));
}

dir(firstArg: unknown, ...rest: Array<unknown>): 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<unknown>): void {
Expand Down
7 changes: 4 additions & 3 deletions packages/jest-console/src/CustomConsole.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -73,8 +73,9 @@ export default class CustomConsole extends Console {
this._log('debug', format(firstArg, ...args));
}

dir(firstArg: unknown, ...args: Array<unknown>): 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<unknown>): void {
Expand Down
10 changes: 10 additions & 0 deletions packages/jest-console/src/__tests__/CustomConsole.test.ts
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions packages/jest-console/src/__tests__/bufferedConsole.test.ts
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-22.x/CLI.md
Expand Up @@ -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.
Expand Down
26 changes: 14 additions & 12 deletions website/versioned_docs/version-22.x/TutorialReactNative.md
Expand Up @@ -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 (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
alignItems: 'center',
Expand All @@ -55,18 +68,7 @@ const styles = StyleSheet.create({
},
});

export default class Intro extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}
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:
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-23.x/CLI.md
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-24.x/CLI.md
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-25.x/CLI.md
Expand Up @@ -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.
Expand Down
26 changes: 14 additions & 12 deletions website/versioned_docs/version-25.x/TutorialReactNative.md
Expand Up @@ -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 (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
alignItems: 'center',
Expand All @@ -55,18 +68,7 @@ const styles = StyleSheet.create({
},
});

export default class Intro extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>
This is a React Native snapshot test.
</Text>
</View>
);
}
}
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:
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-26.0/CLI.md
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-26.2/CLI.md
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions website/versioned_docs/version-26.5/CLI.md
Expand Up @@ -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.
Expand Down

0 comments on commit be68e58

Please sign in to comment.