Skip to content

Commit

Permalink
Merge branch 'master' into fix-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Aftabnack committed Jan 16, 2018
2 parents ea3084d + 7743c09 commit 46e5ec5
Show file tree
Hide file tree
Showing 471 changed files with 1,384 additions and 623 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
},
},
{
files: ['scripts/**/*', 'integration_tests/**/*'],
files: ['scripts/**/*', 'integration-tests/**/*'],
rules: {
'babel/func-params-comma-dangle': 0,
'unicorn/filename-case': 0,
Expand Down Expand Up @@ -83,11 +83,11 @@ module.exports = {
},
},
{
excludedFiles: 'integration_tests/__tests__/**/*',
excludedFiles: 'integration-tests/__tests__/**/*',
files: [
'examples/**/*',
'scripts/**/*',
'integration_tests/*/**/*',
'integration-tests/*/**/*',
'website/*/**/*',
'eslint_import_resolver.js',
],
Expand All @@ -105,7 +105,7 @@ module.exports = {
},
{
files: [
'integration_tests/__tests__/**/*',
'integration-tests/__tests__/**/*',
'packages/babel-jest/**/*.test.js',
'packages/babel-plugin-jest-hoist/**/*.test.js',
'packages/babel-preset-jest/**/*.test.js',
Expand All @@ -127,7 +127,7 @@ module.exports = {
files: [
'website/**',
'**/__tests__/**',
'integration_tests/**',
'integration-tests/**',
'**/pretty-format/perf/**',
],
rules: {
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*~
/examples/*/node_modules/

/integration_tests/*/node_modules
/integration_tests/transform/*/coverage
/integration_tests/transform/*/node_modules
/integration-tests/*/node_modules
/integration-tests/transform/*/coverage
/integration-tests/transform/*/node_modules

/node_modules

Expand Down
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
## master

### Fixes

* `[jest-cli]` Fix `EISDIR` when a directory is passed as an argument to `jest`.
([#5317](https://github.com/facebook/jest/pull/5317))

## jest 22.1.0

### Features

* `[jest-cli]` Make Jest exit without an error when no tests are found in the
case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
having been passed to the CLI

### Fixes
* `[jest-cli]` Use `import-local` to support global Jest installations.
([#5304](https://github.com/facebook/jest/pull/5304))
* `[jest-runner]` Fix memory leak in coverage reporting
([#5289](https://github.com/facebook/jest/pull/5289))
* `[docs]` Update mention of the minimal version of node supported [#4947](https://github.com/facebook/jest/issues/4947)
* `[jest-cli]` Fix missing newline in console message ([#5308](https://github.com/facebook/jest/pull/5308))
* `[jest-cli]` `--lastCommit` and `--changedFilesWithAncestor` now take effect
even when `--onlyChanged` is not specified. ([#5307](https://github.com/facebook/jest/pull/5307))

### Chore & Maintenance

* `[filenames]` Standardize folder names under `integration-tests/`
([#5298](https://github.com/facebook/jest/pull/5298))

## jest 22.0.6

### Fixes

* `[jest-jasmine2]` Fix memory leak in snapshot reporting
([#5279](https://github.com/facebook/jest/pull/5279))
* `[jest-config]` Fix breaking change in `--testPathPattern`
([#5269](https://github.com/facebook/jest/pull/5269))

### Fixes

* `[docs]` Document caveat with mocks, Enzyme, snapshots and React 16
([#5258](https://github.com/facebook/jest/issues/5258))

## jest 22.0.5

### Fixes
Expand Down Expand Up @@ -32,6 +74,8 @@
([#5154](https://github.com/facebook/jest/pull/5154))
* `[jest-jasmine2]` Support generator functions as specs.
([#5166](https://github.com/facebook/jest/pull/5166))
* `[jest-jasmine2]` Allow `spyOn` with getters and setters.
([#5107](https://github.com/facebook/jest/pull/5107))
* `[jest-config]` Allow configuration objects inside `projects` array
([#5176](https://github.com/facebook/jest/pull/5176))
* `[expect]` Add support to `.toHaveProperty` matcher to accept the keyPath
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ accurately.
```sh
cd website # Only needed if you are not already in the website directory
yarn
yarn test
yarn start
```
2. You can run a development server to check if the changes you made are being
displayed accurately by running `yarn start` in the website directory.
Expand Down
112 changes: 68 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@

🃏 Delightful JavaScript Testing

- **👩🏻‍💻 Easy Setup**: Jest is a complete and easy to set up JavaScript testing solution. In fact, Jest works out of the box for any React project.
- **👩🏻‍💻 Easy Setup**: Complete and easy to set-up JavaScript testing solution. Works out of the box for any React project.

- **🏃🏽 Instant Feedback**: Failed tests run first. Fast interactive mode can switch between running all tests or only test files related to changed files.
- **🏃🏽 Instant Feedback**: Fast interactive watch mode runs only test files related to changed files and is optimized to give signal quickly.

- **📸 Snapshot Testing**: Jest can [capture snapshots](http://facebook.github.io/jest/docs/en/snapshot-testing.html) of React trees or other serializable values to simplify testing.
- **📸 Snapshot Testing**: Capture snapshots of React trees or other serializable values to simplify testing and to analyze how state changes over time.

## Getting Started

<!-- generated_getting_started_start -->
Install Jest using `npm`:

Install Jest using [`npm`](https://www.npmjs.com/):

```
npm install --save-dev jest
```

Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a `sum.js` file:
Or via [`yarn`](https://yarnpkg.com/en/package/jest):

```
yarn add --dev jest
```

Let's get started by writing a test for a hypothetical function that adds two
numbers. First, create a `sum.js` file:

```javascript
function sum(a, b) {
Expand Down Expand Up @@ -58,33 +66,51 @@ PASS ./sum.test.js

**You just successfully wrote your first test using Jest!**

This test used `expect` and `toBe` to test that two values were exactly identical. To learn about the other things that Jest can test, see [Using Matchers](https://facebook.github.io/jest/docs/en/using-matchers.html).
This test used `expect` and `toBe` to test that two values were exactly
identical. To learn about the other things that Jest can test, see
[Using Matchers](https://facebook.github.io/jest/docs/using-matchers.html).

## Running from command line

You can run Jest directly from the CLI (if it's globally available in your `PATH`, e.g. by `npm install -g jest`) with variety of useful options.
You can run Jest directly from the CLI (if it's globally available in your
`PATH`, e.g. by `npm install -g jest`) with variety of useful options.

Here's how to run Jest on files matching `my-test`, using `config.json` as a configuration file and display a native OS notification after the run:
Here's how to run Jest on files matching `my-test`, using `config.json` as a
configuration file and display a native OS notification after the run:

```bash
jest my-test --notify --config=config.json
```

If you'd like to learn more about running `jest` through the command line, take a look at the [Jest CLI Options](https://facebook.github.io/jest/docs/en/cli.html) page.
If you'd like to learn more about running `jest` through the command line, take
a look at the [Jest CLI Options](https://facebook.github.io/jest/docs/cli.html) page.

## Additional Configuration

### Using Babel

To use [Babel](http://babeljs.io/), install the `babel-jest` and `regenerator-runtime` packages:
To use [Babel](http://babeljs.io/), install the `babel-jest` and
`regenerator-runtime` packages:

```
npm install --save-dev jest babel-jest regenerator-runtime
npm install --save-dev babel-jest babel-core regenerator-runtime
```

*Note: Explicitly installing `regenerator-runtime` is not needed if you use `npm` 3 or 4 or Yarn*
> Note: If you are using a babel version 7 then you need to install `babel-jest`
> with the following command:
>
> ```
> npm install --save-dev babel-jest 'babel-core@^7.0.0-0' @babel/core regenerator-runtime
> ```
_Note: Explicitly installing `regenerator-runtime` is not needed if you use
`npm` 3 or 4 or Yarn_

Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file in your project's root folder. For example, if you are using ES6 and [React.js](https://facebook.github.io/react/) with the [`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file
in your project's root folder. For example, if you are using ES6 and
[React.js](https://facebook.github.io/react/) with the
[`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and
[`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:

```json
{
Expand All @@ -94,11 +120,30 @@ Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file

You are now set up to use all ES6 features and React specific syntax.

> Note: If you are using a more complicated Babel configuration, using Babel's `env` option,
keep in mind that Jest will automatically define `NODE_ENV` as `test`.
It will not use `development` section like Babel does by default when no `NODE_ENV` is set.
> Note: If you are using a more complicated Babel configuration, using Babel's
> `env` option, keep in mind that Jest will automatically define `NODE_ENV` as
> `test`. It will not use `development` section like Babel does by default when
> no `NODE_ENV` is set.
> Note: If you've turned off transpilation of ES2015 modules with the option
> `{ "modules": false }`, you have to make sure to turn this on in your test
> environment.
```json
{
"presets": [["es2015", {"modules": false}], "react"],
"env": {
"test": {
"presets": [["es2015"], "react"]
}
}
}
```

> Note: `babel-jest` is automatically installed when installing Jest and will automatically transform files if a babel configuration exists in your project. To avoid this behavior, you can explicitly reset the `transform` configuration option:
> Note: `babel-jest` is automatically installed when installing Jest and will
> automatically transform files if a babel configuration exists in your project.
> To avoid this behavior, you can explicitly reset the `transform` configuration
> option:
```json
// package.json
Expand All @@ -111,36 +156,15 @@ It will not use `development` section like Babel does by default when no `NODE_E

### Using webpack

Jest can be used in projects that use [webpack](https://webpack.github.io/) to manage assets, styles, and compilation. webpack does offer some unique challenges over other tools. Refer to the [webpack guide](https://facebook.github.io/jest/docs/en/webpack.html) to get started.
Jest can be used in projects that use [webpack](https://webpack.github.io/) to
manage assets, styles, and compilation. webpack does offer some unique
challenges over other tools. Refer to the [webpack guide](Webpack.md) to get
started.

### Using TypeScript

To use TypeScript in your tests, install the `ts-jest` package and the types for Jest.

```
npm install --save-dev jest ts-jest @types/jest
```

then modify your `package.json` so the `jest` section looks something like:

```json
{
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}
```
To use TypeScript in your tests you can use
[ts-jest](https://github.com/kulshekhar/ts-jest).
<!-- generated_getting_started_end -->

## Documentation
Expand Down
16 changes: 9 additions & 7 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ CLI options take precedence over values from the
When you run `jest` with an argument, that argument is treated as a regular
expression to match against files in your project. It is possible to run test
suites by providing a pattern. Only the files that the pattern matches will be
picked up and executed. Note: depending on your terminal, you may need to quote
this argument: `jest "my.*(complex)?pattern"`.
picked up and executed. Depending on your terminal, you may need to quote this
argument: `jest "my.*(complex)?pattern"`. On Windows, you will need to use `/`
as a path separator or escape `\` as `\\`.

### `--bail`

Expand All @@ -104,8 +105,8 @@ If you want to inspect the cache, use `--showConfig` and look at the

### `--changedFilesWithAncestor`

When used together with `--onlyChanged` or `--watch`, it runs tests related to
the current changes and the changes made in the last commit.
Runs tests related to the current changes and the changes made in the last
commit. Behaves similarly to `--onlyChanged`.

### `--ci`

Expand Down Expand Up @@ -187,8 +188,8 @@ Write test results to a file when the `--json` option is also specified.

### `--lastCommit`

When used together with `--onlyChanged`, it will run all tests affected by file
changes in the last commit made.
Run all tests affected by file changes in the last commit made. Behaves
similarly to `--onlyChanged`.

### `--listTests`

Expand Down Expand Up @@ -276,7 +277,8 @@ Note that `column` is 0-indexed while `line` is not.
### `--testPathPattern=<regex>`

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

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

Expand Down
6 changes: 4 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ For example, the following would create a global `__DEV__` variable set to

Note that, if you specify a global reference value (like an object or array)
here, and some code mutates that value in the midst of running a test, that
mutation will _not_ be persisted across test runs for other test files.
mutation will _not_ be persisted across test runs for other test files. In
addition the `globals` object must be json-serializable, so it can't be used
to specify global functions. For that you should use `setupFiles`.

### `globalSetup` [string]

Expand Down Expand Up @@ -330,7 +332,7 @@ Both inline source maps and source maps returned directly from a transformer are
supported. Source map URLs are not supported because Jest may not be able to
locate them. To return source maps from a transformer, the `process` function
can return an object like the following. The `map` property may either be the
source map object, or the source map object as a JSON string.
source map object, or the source map object as a string.

```js
return {
Expand Down
2 changes: 1 addition & 1 deletion docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Executes only the macro task queue (i.e. all tasks queued by `setTimeout()` or

When this API is called, all timers are advanced by `msToRun` milliseconds. All
pending "macro-tasks" that have been queued via `setTimeout()` or
`setInterval()`, and would be executed within this timeframe will be executed.
`setInterval()`, and would be executed within this time frame will be executed.
Additionally if those macro-tasks schedule new macro-tasks that would be
executed within the same time frame, those will be executed until there are no
more macro-tasks remaining in the queue, that should be run within `msToRun`
Expand Down
2 changes: 1 addition & 1 deletion docs/JestPlatform.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module.exports = {
async function main() {
const worker = new Worker(require.resolve('./heavy-task.js'));

// run 2 tasks in parellel with different arguments
// run 2 tasks in parallel with different arguments
const results = await Promise.all([
worker.myHeavyTask({foo: 'bar'}),
worker.myHeavyTask({bar: 'foo'}),
Expand Down
4 changes: 2 additions & 2 deletions docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ which reviewers can study your changes better.

### Does snapshot testing only work with React components?

[React](TutorialReacte.md) and [React Native](TutorialReactNative.md) components
[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components
are a good use case for snapshot testing. However, snapshots can capture any
serializable value and should be used anytime the goal is testing whether the
output is correct. The Jest repository contains many examples of testing the
output of Jest itself, the output of Jest's assertion library as well as log
messages from various parts of the Jest codebase. See an example of
[snapshotting CLI output](https://github.com/facebook/jest/blob/master/integration_tests/__tests__/console.test.js)
[snapshotting CLI output](https://github.com/facebook/jest/blob/master/integration-tests/__tests__/console.test.js)
in the Jest repo.

### What's the difference between snapshot testing and visual regression testing?
Expand Down
Loading

0 comments on commit 46e5ec5

Please sign in to comment.