Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Don Schrimsher committed Jan 22, 2019
2 parents a1e1e40 + 71b47cf commit 3018bc8
Show file tree
Hide file tree
Showing 256 changed files with 3,060 additions and 3,458 deletions.
68 changes: 34 additions & 34 deletions .azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
#
# Steps for building and testing Jest. See jobs defined in .azure-pipelines.yml
#
#

# Clones the repo
steps:
- checkout: self
- checkout: self

# Ensure Node.js 10 is active
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Use Node.js 10'
# Ensure Node.js 10 is active
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Use Node.js 10'

# Ensure Python 2.7 is active
- task: UsePythonVersion@0
inputs:
versionSpec: '2.7'
displayName: 'Use Python 2.7'
# Ensure Python 2.7 is active
- task: UsePythonVersion@0
inputs:
versionSpec: '2.7'
displayName: 'Use Python 2.7'

# Workaround to move source files under a "jest" folder (see .azure-pipelines.yml for details)
- script: |
cd /
mv $(Build.Repository.LocalPath) $(JEST_DIR)
mkdir $(Build.Repository.LocalPath)
displayName: 'Move source into jest folder'
# Workaround to move source files under a "jest" folder (see .azure-pipelines.yml for details)
- script: |
cd /
mv $(Build.Repository.LocalPath) $(JEST_DIR)
mkdir $(Build.Repository.LocalPath)
displayName: 'Move source into jest folder'
# Run yarn to install dependencies and build
- script: yarn
workingDirectory: $(JEST_DIR)
displayName: 'Install dependencies and build'
# Run yarn to install dependencies and build
- script: yarn
workingDirectory: $(JEST_DIR)
displayName: 'Install dependencies and build'

# Run test-ci-partial
- script: yarn run test-ci-partial
workingDirectory: $(JEST_DIR)
displayName: 'Run tests'
# Run test-ci-partial
- script: yarn run test-ci-partial
workingDirectory: $(JEST_DIR)
displayName: 'Run tests'

# Publish CI test results
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/reports/junit/*.xml'
searchFolder: $(JEST_DIR)
testRunTitle: 'CI Tests $(Agent.OS)'
displayName: 'Publish test results'
condition: succeededOrFailed()
# Publish CI test results
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/reports/junit/*.xml'
searchFolder: $(JEST_DIR)
testRunTitle: 'CI Tests $(Agent.OS)'
displayName: 'Publish test results'
condition: succeededOrFailed()
46 changes: 23 additions & 23 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
#

jobs:
- job: Linux
pool:
vmImage: ubuntu-16.04
steps:
- template: .azure-pipelines-steps.yml
- job: Linux
pool:
vmImage: ubuntu-16.04
steps:
- template: .azure-pipelines-steps.yml

- job: Windows
pool:
vmImage: vs2017-win2016
steps:
- script: |
git config --global core.autocrlf false
git config --global core.symlinks true
displayName: 'Preserve LF endings and symbolic links on check out'
- template: .azure-pipelines-steps.yml
- job: Windows
pool:
vmImage: vs2017-win2016
steps:
- script: |
git config --global core.autocrlf false
git config --global core.symlinks true
displayName: 'Preserve LF endings and symbolic links on check out'
- template: .azure-pipelines-steps.yml

- job: macOS
pool:
vmImage: macos-10.13
steps:
# This step can be removed once Mercurial gets installed on the macOS image. See https://github.com/Microsoft/azure-pipelines-image-generation/issues/604
- script: HOMEBREW_NO_AUTO_UPDATE=1 brew install mercurial
displayName: 'Install Mercurial'
- template: .azure-pipelines-steps.yml
- job: macOS
pool:
vmImage: macos-10.13
steps:
# This step can be removed once Mercurial gets installed on the macOS image. See https://github.com/Microsoft/azure-pipelines-image-generation/issues/604
- script: HOMEBREW_NO_AUTO_UPDATE=1 brew install mercurial
displayName: 'Install Mercurial'
- template: .azure-pipelines-steps.yml

variables:
# Used by chalk. Ensures output from Jest includes ANSI escape characters that are needed to match test snapshots.
Expand All @@ -35,6 +35,6 @@ variables:
# By default, Azure Pipelines clones to an "s" directory, which causes tests to fail due to assumption of Jest being run from a "jest" directory.
# See packages/jest-message-util/src/index.js PATH_JEST_PACKAGES for more details.
JEST_DIR: $(Agent.BuildDirectory)/jest

# Ensures the handful of tests that should be skipped during CI are
CI: true
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

- `[jest-runtime]` Add `jest.isolateModules` for scoped module initialization ([#6701](https://github.com/facebook/jest/pull/6701))
- `[jest-diff]` [**BREAKING**] Support diffing numbers and booleans instead of returning null for different ones ([#7605](https://github.com/facebook/jest/pull/7605))
- `[jest-diff]` [**BREAKING**] Replace `diff` with `diff-sequences` package ([#6961](https://github.com/facebook/jest/pull/6961))
- `[jest-cli]` [**BREAKING**] Only set error process error codes when they are non-zero ([#7363](https://github.com/facebook/jest/pull/7363))
- `[jest-config]` [**BREAKING**] Deprecate `setupTestFrameworkScriptFile` in favor of new `setupFilesAfterEnv` ([#7119](https://github.com/facebook/jest/pull/7119))
Expand Down Expand Up @@ -50,9 +51,12 @@
- `[jest-config]` Allow % based configuration of `--max-workers` ([#7494](https://github.com/facebook/jest/pull/7494))
- `[jest-runner]` Instantiate the test environment class with the current `testPath` ([#7442](https://github.com/facebook/jest/pull/7442))
- `[jest-config]` Always resolve jest-environment-jsdom from jest-config ([#7476](https://github.com/facebook/jest/pull/7476))
- `[expect]` Improve report when assertion fails, part 6 ([#7621](https://github.com/facebook/jest/pull/7621))

### Fixes

- `[jest-diff]` Do not claim that `-0` and `0` have no visual difference ([#7605](https://github.com/facebook/jest/pull/7605))
- `[jest-mock]` Fix automock for numeric function names ([#7653](https://github.com/facebook/jest/pull/7653))
- `[jest-config]` Ensure `existsSync` is only called with a string parameter ([#7607](https://github.com/facebook/jest/pull/7607))
- `[expect]` `toStrictEqual` considers sparseness of arrays. ([#7591](https://github.com/facebook/jest/pull/7591))
- `[jest-cli]` Fix empty coverage data for untested files ([#7388](https://github.com/facebook/jest/pull/7388))
Expand Down Expand Up @@ -117,11 +121,15 @@
- `[jest-environment-node]` Fix buffer property is not ArrayBuffer issue. ([#7626](https://github.com/facebook/jest/pull/7626))
- `[babel-plugin-jest-hoist]` Ignore TS type annotations when looking for out-of-scope references ([#7641](https://github.com/facebook/jest/pull/7641))
- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652))
- `[jest-config]` Add name to project if one does not exist to pick correct resolver ([#5862](https://github.com/facebook/jest/pull/5862))
- `[jest-runtime]` Pass `watchPathIgnorePatterns` to Haste instance ([#7585](https://github.com/facebook/jest/pull/7585))

### Chore & Maintenance

- `[*]` [**BREAKING**] Require Node.js 6+ for all packages ([#7258](https://github.com/facebook/jest/pull/7258))
- `[jest-util]` [**BREAKING**] Remove long-deprecated globals for fake timers ([#7285](https://github.com/facebook/jest/pull/7285))
- `[*]` [**BREAKING**] Upgrade to Micromatch 3 ([#6650](https://github.com/facebook/jest/pull/6650))
- `[*]` [**BREAKING**] Remove regenerator-runtime injection ([#7595](https://github.com/facebook/jest/pull/7595))
- `[docs]` Fix message property in custom matcher example to return a function instead of a constant. ([#7426](https://github.com/facebook/jest/pull/7426))
- `[jest-circus]` Standardize file naming in `jest-circus` ([#7301](https://github.com/facebook/jest/pull/7301))
- `[docs]` Add synchronous test.each setup ([#7150](https://github.com/facebook/jest/pull/7150))
Expand Down Expand Up @@ -157,7 +165,8 @@
- `[*]` 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)), [#7471](https://github.com/facebook/jest/pull/7471))
- `[docs]` Add `testPathIgnorePatterns` in CLI documentation ([#7440](https://github.com/facebook/jest/pull/7440))
- `[docs]` Removed misleading text about `describe()` grouping together tests into a test suite ([#7434](https://github.com/facebook/jest/pull/7434))
- `[*]` Replace as many `Object.assign` with object spread as possible
- `[diff-sequences]` Add performance benchmark to package ([#7603](https://github.com/facebook/jest/pull/7603))
- `[*]` Replace as many `Object.assign` with object spread as possible ([#7627](https://github.com/facebook/jest/pull/7627))
- `[ci]` Initial support for Azure Pipelines ([#7556](https://github.com/facebook/jest/pull/7556))

### Performance
Expand Down
10 changes: 9 additions & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ _Note: A global setup module configured in a project (using multi-project runner

_Note: Any global variables that are defined through `globalSetup` can only be read in `globalTeardown`. You cannot retrieve globals defined here in your test suites._

_Note: While code transformation is applied to the linked setup-file, Jest will **not** transform any code in `node_modules`. This is due to the need to load the actual transformers (e.g. `babel` or `typescript`) to perform transformation._

Example:

```js
Expand All @@ -399,6 +401,8 @@ This option allows the use of a custom global teardown module which exports an a

_Note: A global teardown module configured in a project (using multi-project runner) will be triggered only when you run at least one test from this project._

_Node: The same caveat concerning transformation of `node_modules_ as for `globalSetup` applies to `globalTeardown`.

### `moduleDirectories` [array<string>]

Default: `["node_modules"]`
Expand All @@ -409,7 +413,9 @@ An array of directory names to be searched recursively up from the requiring mod

Default: `["js", "json", "jsx", "ts", "tsx", "node"]`

An array of file extensions your modules use. If you require modules without specifying a file extension, these are the extensions Jest will look for.
An array of file extensions your modules use. If you require modules without specifying a file extension, these are the extensions Jest will look for, in left-to-right order.

We recommend placing the extensions most commonly used in your project on the left, so if you are using TypeScript, you may want to consider moving "ts" and/or "tsx" to the beginning of the array.

### `moduleNameMapper` [object<string, string>]

Expand Down Expand Up @@ -865,6 +871,8 @@ beforeAll(() => {
});
```

_Note: Jest comes with JSDOM@11 by default. Due to JSDOM 12 and newer dropping support for Node 6, Jest is unable to upgrade for the time being. However, you can install a custom `testEnvironment` with whichever version of JSDOM you want. E.g. [jest-environment-jsdom-thirteen](https://www.npmjs.com/package/jest-environment-jsdom-thirteen), which has JSDOM@13._

### `testEnvironmentOptions` [Object]

Default: `{}`
Expand Down
10 changes: 9 additions & 1 deletion docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,14 @@ test('throws on octopus', () => {
});
```

If you want to test that a specific error gets thrown, you can provide an argument to `toThrow`. The argument can be a string that should be contained in the error message, a class for the error, or a regex that should match the error message. For example, let's say that `drinkFlavor` is coded like this:
To test that a specific error is thrown, you can provide an argument:

- regular expression: error message **matches** the pattern
- string: error message **includes** the substring
- error object: error message is **equal to** the message property of the object
- error class: error object is **instance of** class

For example, let's say that `drinkFlavor` is coded like this:

```js
function drinkFlavor(flavor) {
Expand All @@ -1193,6 +1200,7 @@ test('throws on octopus', () => {

// Test the exact error message
expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/);
expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor'));

// Test that we get a DisgustingFlavorError
expect(drinkOctopus).toThrowError(DisgustingFlavorError);
Expand Down
2 changes: 1 addition & 1 deletion docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Snapshot Testing

Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.

A typical snapshot test case for a mobile app renders a UI component, takes a screenshot, then compares it to a reference image stored alongside the test. The test will fail if the two images do not match: either the change is unexpected, or the screenshot needs to be updated to the new version of the UI component.
A typical snapshot test case for a mobile app renders a UI component, takes a snapshot, then compares it to a reference snapshot file stored alongside the test. The test will fail if the two snapshots do not match: either the change is unexpected, or the reference snapshot needs to be updated to the new version of the UI component.

## Snapshot Testing with Jest

Expand Down
5 changes: 4 additions & 1 deletion e2e/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ export const extractSummary = (stdout: string) => {
// remove all timestamps
.replace(/\s*\(\d*\.?\d+m?s\)$/gm, '');

return {rest, summary};
return {
rest: rest.trim(),
summary: summary.trim(),
};
};

const sortTests = (stdout: string) =>
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/beforeAllFiltered.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Correct BeforeAll run ensures the BeforeAll of ignored suite is not run 1`] = `
" console.log __tests__/beforeAllFiltered.test.js:5
console.log __tests__/beforeAllFiltered.test.js:5
beforeAll 1
console.log __tests__/beforeAllFiltered.test.js:8
Expand All @@ -15,5 +15,5 @@ exports[`Correct BeforeAll run ensures the BeforeAll of ignored suite is not run
console.log __tests__/beforeAllFiltered.test.js:14
afterAll 1
"
`;
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/beforeEachQueue.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Correct beforeEach order ensures the correct order for beforeEach 1`] = `
" console.log __tests__/beforeEachQueue.test.js:5
console.log __tests__/beforeEachQueue.test.js:5
BeforeEach
console.log __tests__/beforeEachQueue.test.js:9
Expand All @@ -15,5 +15,5 @@ exports[`Correct beforeEach order ensures the correct order for beforeEach 1`] =
console.log __tests__/beforeEachQueue.test.js:17
It Bar
"
`;
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI accepts exact file names if matchers matched 1`] = `
"PASS foo/bar.spec.js
PASS foo/bar.spec.js
✓ foo
Force exiting Jest
Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?"
Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?
`;

exports[`CLI accepts exact file names if matchers matched 2`] = `
"Test Suites: 1 passed, 1 total
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /.\\\\/foo\\\\/bar.spec.js/i."
Ran all test suites matching /.\\/foo\\/bar.spec.js/i.
`;
exports[`CLI accepts exact file names if matchers matched 3`] = `""`;
Loading

0 comments on commit 3018bc8

Please sign in to comment.