Skip to content

Commit

Permalink
Merge remote-tracking branch 'hulkish/support-dashed-args' into azure…
Browse files Browse the repository at this point in the history
…-pipelines
  • Loading branch information
kaylangan committed Dec 11, 2018
2 parents 56ee446 + a9999f6 commit b0e14fa
Show file tree
Hide file tree
Showing 72 changed files with 2,865 additions and 875 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: 🐛 Bug report
labels: ':bug: Bug'
about: Create a report to help us improve
---

Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: 🚀 Feature Proposal
labels: ':rocket: Feature Request'
about: Submit a proposal for a new feature
---

Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: 💬 Questions / Help
label: ':speech_balloon: Question'
about: If you have questions, please check our Discord or StackOverflow
---

Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/regression.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: 💥 Regression Report
labels: ':boom: Regression'
about: Report unexpected behavior that worked in previous versions
---

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.DS_STORE
.eslintcache
*.swp
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@
- `[jest-config]` Add `dependencyExtractor` option to use a custom module to extract dependencies from files ([#7313](https://github.com/facebook/jest/pull/7313), [#7349](https://github.com/facebook/jest/pull/7349), [#7350](https://github.com/facebook/jest/pull/7350))
- `[jest-haste-map]` Accept a `getCacheKey` method in `hasteImplModulePath` modules to reset the cache when the logic changes ([#7350](https://github.com/facebook/jest/pull/7350))
- `[jest-config]` Add `haste.computeSha1` option to compute the sha-1 of the files in the haste map ([#7345](https://github.com/facebook/jest/pull/7345))
- `[expect]` `expect(Infinity).toBeCloseTo(Infinity)` Treats `Infinity` as equal in toBeCloseTo matcher ([#7405](https://github.com/facebook/jest/pull/7405))
- `[jest-worker]` Add node worker-thread support to jest-worker ([#7408](https://github.com/facebook/jest/pull/7408))
- `[jest-config]` Allow `bail` setting to be configured with a number allowing tests to abort after `n` of failures ([#7335](https://github.com/facebook/jest/pull/7335))

### Fixes

- `[jest-cli]` Support dashed args ([#7497](https://github.com/facebook/jest/pull/7497))
- `[jest-cli]` [**BREAKING**] Do not use `text-summary` coverage reporter by default if other reporters are configured ([#7058](https://github.com/facebook/jest/pull/7058))
- `[jest-mock]` [**BREAKING**] Fix bugs with mock/spy result tracking of recursive functions ([#6381](https://github.com/facebook/jest/pull/6381))
- `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329))
- `[pretty-format]` [**BREAKING**] Omit non-enumerable symbol properties ([#7448](https://github.com/facebook/jest/pull/7448))
- `[expect]` Standardize file naming in `expect` ([#7306](https://github.com/facebook/jest/pull/7306))
- `[jest-each]` Add empty array validation check ([#7249](https://github.com/facebook/jest/pull/7249))
- `[jest-cli]` Interrupt tests if interactive watch plugin key is pressed ([#7222](https://github.com/facebook/jest/pull/7222))
Expand Down Expand Up @@ -110,8 +115,10 @@
- `[docs]` Remove duplicate code in `MockFunctions` ([#7297](https://github.com/facebook/jest/pull/7297))
- `[*]` Add check for Facebook copyright headers on CI ([#7370](https://github.com/facebook/jest/pull/7370))
- `[jest-haste-map]` Refactor `dependencyExtractor` and tests ([#7385](https://github.com/facebook/jest/pull/7385))
- `[docs]` Clearify conditional setting of `NODE_ENV` ([#7369](https://github.com/facebook/jest/pull/7369))
- `[docs]` Clarify conditional setting of `NODE_ENV` ([#7369](https://github.com/facebook/jest/pull/7369))
- `[*]` Standardize file names ([#7316](https://github.com/facebook/jest/pull/7316), [#7266](https://github.com/facebook/jest/pull/7266), [#7238](https://github.com/facebook/jest/pull/7238), [#7314](https://github.com/facebook/jest/pull/7314))
- `[*]` Standardize file names ([#7316](https://github.com/facebook/jest/pull/7316), [#7266](https://github.com/facebook/jest/pull/7266), [#7238](https://github.com/facebook/jest/pull/7238), [#7314](https://github.com/facebook/jest/pull/7314), [#7467](https://github.com/facebook/jest/pull/7467), [#7464](https://github.com/facebook/jest/pull/7464))
- `[docs]` Add `testPathIgnorePatterns` in CLI documentation ([#7440](https://github.com/facebook/jest/pull/7440))

### Performance

Expand Down
2 changes: 1 addition & 1 deletion TestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import type {GlobalConfig, ProjectConfig} from 'types/Config';

const DEFAULT_GLOBAL_CONFIG: GlobalConfig = {
bail: false,
bail: 0,
changedFilesWithAncestor: false,
changedSince: '',
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
environment:
matrix:
- nodejs_version: '8'
- nodejs_version: '10'

init:
# debugging Appveyor build. More info:
Expand Down
8 changes: 8 additions & 0 deletions docs/Architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
id: architecture
title: Architecture
---

If you are interested in learning more about how Jest works, what the architecture behind the framework is, and how Jest is split up into individual reusable packages, check out this video:

<iframe width="560" height="315" src="https://www.youtube.com/embed/3YDiloj8_d0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
21 changes: 20 additions & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ you can use:
npm test -- -u -t="ColorPicker"
```

## Camelcase & dashed args support

Jest supports both camelcase and dashed arg formats. Which means the following examples will have equal result:

```bash
jest --collect-coverage
jest --collectCoverage
```

They can also be mixed:

```bash
jest --update-snapshot --detectOpenHandles
```

## Options

_Note: CLI options take precedence over values from the [Configuration](Configuration.md)._
Expand All @@ -97,7 +112,7 @@ When you run `jest` with an argument, that argument is treated as a regular expr

### `--bail`

Alias: `-b`. Exit the test suite immediately upon the first failing test suite.
Alias: `-b`. Exit the test suite immediately upon `n` number of failing test suite. Defaults to `1`.

### `--cache`

Expand Down Expand Up @@ -268,6 +283,10 @@ Note that `column` is 0-indexed while `line` is not.

A regexp pattern string that is matched against all tests paths before executing the test. On Windows, you will need to use `/` as a path separator or escape `\` as `\\`.

### `--testPathIgnorePatterns=[array]`

An array of regexp pattern strings that is tested against all tests paths before executing the test. Contrary to `--testPathPattern`, it will only run those test with a path that does not match with the provided regexp expressions.

### `--testRunner=<path>`

Lets you specify a custom test runner.
Expand Down
8 changes: 4 additions & 4 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ When using the `--config` option, the JSON file must not contain a "jest" key:

```json
{
"bail": true,
"bail": 1,
"verbose": true
}
```
Expand Down Expand Up @@ -99,11 +99,11 @@ _Note: Core modules, like `fs`, are not mocked by default. They can be mocked ex

_Note: Automocking has a performance cost most noticeable in large projects. See [here](troubleshooting.html#tests-are-slow-when-leveraging-automocking) for details and a workaround._

### `bail` [boolean]
### `bail` [number | boolean]

Default: `false`
Default: `0`

By default, Jest runs all tests and produces all errors into the console upon completion. The bail config option can be used here to have Jest stop running tests after the first failure.
By default, Jest runs all tests and produces all errors into the console upon completion. The bail config option can be used here to have Jest stop running tests after `n` failures. Setting bail to `true` is the same as setting bail to `1`.

### `browser` [boolean]

Expand Down
3 changes: 1 addition & 2 deletions docs/WatchPlugins.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
id: watch-plugins
title: Watch Plugins
original_id: watch-plugins
---

The Jest watch plugin system provides a way to hook into specific parts of Jest and to define watch mode menu prompts that execute code on key press. Combined, these features allow you to develop interactive experiences custom for your workflow.
Expand Down Expand Up @@ -155,7 +154,7 @@ class MyWatchPlugin {

For stability and safety reasons, only part of the global configuration keys can be updated with `updateConfigAndRun`. The current white list is as follows:

- [`bail`](configuration.html#bail-boolean)
- [`bail`](configuration.html#bail-number-boolean)
- [`collectCoverage`](configuration.html#collectcoverage-boolean)
- [`collectCoverageFrom`](configuration.html#collectcoveragefrom-array)
- [`collectCoverageOnlyFrom`](configuration.html#collectcoverageonlyfrom-array)
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/show_config.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
}
],
\\"globalConfig\\": {
\\"bail\\": false,
\\"bail\\": 0,
\\"changedFilesWithAncestor\\": false,
\\"collectCoverage\\": false,
\\"collectCoverageFrom\\": null,
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/failures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('works with node assert', () => {

// Node 9 started to include the error for `doesNotThrow`
// https://github.com/nodejs/node/pull/12167
if (nodeMajorVersion >= 9) {
if (nodeMajorVersion >= 8) {
expect(summary).toContain(`
assert.doesNotThrow(function)
Expand Down Expand Up @@ -71,7 +71,7 @@ test('works with node assert', () => {
Got unwanted exception.
`;

if (nodeMajorVersion === 9) {
if (nodeMajorVersion === 8 || nodeMajorVersion === 9) {
const specificErrorMessage = `Message:
Got unwanted exception.
err!
Expand Down
52 changes: 52 additions & 0 deletions e2e/__tests__/supports-dashed-args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2018-present, Facebook, Inc. 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.
*
* @flow
*/

'use strict';

import path from 'path';
import runJest from '../runJest';

const consoleDir = path.resolve(__dirname, '../console');
const eachDir = path.resolve(__dirname, '../each');

expect.addSnapshotSerializer({
print: value => value,
test: received => typeof received === 'string',
});

test('works with passing tests', () => {
const result = runJest(eachDir, [
'success.test.js',
'--runInBand',
'--collect-coverage',
'--coverageReporters',
'text-summary',
'--detect-open-handles',
]);
expect(result.status).toBe(0);
});

test('throws error for unknown dashed & camelcase args', () => {
const result = runJest(consoleDir, [
'--doesNotExist',
'--also-does-not-exist',
]);
expect(result.status).toBe(1);
expect(result.stderr).toMatchInlineSnapshot(`
● Unrecognized CLI Parameters:
Following options were not recognized:
["doesNotExist", "also-does-not-exist"]
CLI Options Documentation:
https://jestjs.io/docs/en/cli.html
`);
});
6 changes: 3 additions & 3 deletions e2e/babel-plugin-jest-hoist/__tests__/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import b from '../__test_modules__/b';
import c from '../__test_modules__/c';
import d from '../__test_modules__/d';
import e from '../__test_modules__/e';
import jestBackticks from '../__test_modules__/jest-backticks';
import jestBackticks from '../__test_modules__/jestBackticks';

// The virtual mock call below will be hoisted above this `require` call.
const virtualModule = require('virtual-module');
Expand All @@ -45,7 +45,7 @@ jest.mock('../__test_modules__/e', () => {
},
};
});
jest.mock(`../__test_modules__/jest-backticks`);
jest.mock(`../__test_modules__/jestBackticks`);
jest.mock('virtual-module', () => 'kiwi', {virtual: true});
// This has types that should be ignored by the out-of-scope variables check.
jest.mock('has-flow-types', () => (props: {children: mixed}) => 3, {
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('babel-plugin-jest-hoist', () => {
});

it('requires modules that also call jest.mock', () => {
require('../mock-file');
require('../mockFile');
const mock = require('../banana');
expect(mock).toEqual('apple');
});
Expand Down
File renamed without changes.
Empty file added jest-worker
Empty file.
40 changes: 40 additions & 0 deletions packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,38 @@ Expected: <green>false</>
Received: <red>true</>"
`;

exports[`.toBeCloseTo() {pass: false} expect(-Infinity)toBeCloseTo( -1.23) 1`] = `
"<dim>expect(</><red>received</><dim>).toBeCloseTo(</><green>expected</><dim>)</>

Precision: <green>2</>-digit
Expected: <green>-1.23</>
Received: <red>-Infinity</>"
`;

exports[`.toBeCloseTo() {pass: false} expect(Infinity)toBeCloseTo( -Infinity) 1`] = `
"<dim>expect(</><red>received</><dim>).toBeCloseTo(</><green>expected</><dim>)</>

Precision: <green>2</>-digit
Expected: <green>-Infinity</>
Received: <red>Infinity</>"
`;

exports[`.toBeCloseTo() {pass: false} expect(Infinity)toBeCloseTo( 1.23) 1`] = `
"<dim>expect(</><red>received</><dim>).toBeCloseTo(</><green>expected</><dim>)</>

Precision: <green>2</>-digit
Expected: <green>1.23</>
Received: <red>Infinity</>"
`;

exports[`.toBeCloseTo() {pass: true} expect(-Infinity)toBeCloseTo( -Infinity) 1`] = `
"<dim>expect(</><red>received</><dim>).</>not<dim>.toBeCloseTo(</><green>expected</><dim>)</>

Precision: <green>2</>-digit
Expected: <green>-Infinity</>
Received: <red>-Infinity</>"
`;

exports[`.toBeCloseTo() {pass: true} expect(0)toBeCloseTo( 0) 1`] = `
"<dim>expect(</><red>received</><dim>).</>not<dim>.toBeCloseTo(</><green>expected</><dim>)</>

Expand Down Expand Up @@ -416,6 +448,14 @@ Expected: <green>1.234</>
Received: <red>1.23</>"
`;

exports[`.toBeCloseTo() {pass: true} expect(Infinity)toBeCloseTo( Infinity) 1`] = `
"<dim>expect(</><red>received</><dim>).</>not<dim>.toBeCloseTo(</><green>expected</><dim>)</>

Precision: <green>2</>-digit
Expected: <green>Infinity</>
Received: <red>Infinity</>"
`;

exports[`.toBeCloseTo() accepts an optional precision argument: [0, 0.000004, 5] 1`] = `
"<dim>expect(</><red>received</><dim>).</>not<dim>.toBeCloseTo(</><green>expected</><dim>, </><green>precision</><dim>)</>

Expand Down
22 changes: 22 additions & 0 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,28 @@ describe('.toBeCloseTo()', () => {
});
});

[[Infinity, Infinity], [-Infinity, -Infinity]].forEach(([n1, n2]) => {
it(`{pass: true} expect(${n1})toBeCloseTo( ${n2})`, () => {
jestExpect(n1).toBeCloseTo(n2);

expect(() =>
jestExpect(n1).not.toBeCloseTo(n2),
).toThrowErrorMatchingSnapshot();
});
});

[[Infinity, -Infinity], [Infinity, 1.23], [-Infinity, -1.23]].forEach(
([n1, n2]) => {
it(`{pass: false} expect(${n1})toBeCloseTo( ${n2})`, () => {
jestExpect(n1).not.toBeCloseTo(n2);

expect(() =>
jestExpect(n1).toBeCloseTo(n2),
).toThrowErrorMatchingSnapshot();
});
},
);

[[0, 0.1, 0], [0, 0.0001, 3], [0, 0.000004, 5]].forEach(([n1, n2, p]) => {
it(`accepts an optional precision argument: [${n1}, ${n2}, ${p}]`, () => {
jestExpect(n1).toBeCloseTo(n2, p);
Expand Down
8 changes: 7 additions & 1 deletion packages/expect/src/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ const matchers: MatchersObject = {
toBeCloseTo(actual: number, expected: number, precision?: number = 2) {
const secondArgument = arguments.length === 3 ? 'precision' : null;
ensureNumbers(actual, expected, '.toBeCloseTo');
const pass = Math.abs(expected - actual) < Math.pow(10, -precision) / 2;

let pass = false;

if (actual == Infinity && expected == Infinity) pass = true;
else if (actual == -Infinity && expected == -Infinity) pass = true;
else pass = Math.abs(expected - actual) < Math.pow(10, -precision) / 2;

const message = () =>
matcherHint('.toBeCloseTo', undefined, undefined, {
isNot: this.isNot,
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-cli/src/TestScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ export default class TestScheduler {
aggregatedResults: AggregatedResult,
watcher: TestWatcher,
): Promise<void> {
if (this._globalConfig.bail && aggregatedResults.numFailedTests !== 0) {
if (
this._globalConfig.bail !== 0 &&
aggregatedResults.numFailedTests >= this._globalConfig.bail
) {
if (watcher.isWatchMode()) {
watcher.setState({interrupted: true});
} else {
Expand Down
Loading

0 comments on commit b0e14fa

Please sign in to comment.