Skip to content

Commit

Permalink
Merge branch 'main' into SimenB-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jul 22, 2023
2 parents d9b0c68 + 7628207 commit 28ac110
Show file tree
Hide file tree
Showing 198 changed files with 1,754 additions and 1,704 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ aliases:
app-dir: ~/jest

orbs:
node: circleci/node@5.0.3
node: circleci/node@5.1.0

jobs:
test-node:
Expand Down Expand Up @@ -58,5 +58,6 @@ workflows:
name: test-node-partial-<< matrix.node-version >>
matrix:
parameters:
# For some reason, v20 fails to run yarn install…
node-version: ['14', '16', '18', '19']
- test-jest-jasmine
10 changes: 0 additions & 10 deletions .github/dependabot.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"lockFileMaintenance": {"enabled": true, "automerge": true},
"rangeStrategy": "replace",
"postUpdateOptions": ["yarnDedupeHighest"],
"packageRules": [
{
"matchPackageNames": ["@tsd/typescript", "typescript"],
"groupName": "typescript"
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/close-stale.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '*/10 * * * *'
- cron: '0 * * * *'

permissions:
issues: write # to close stale issues (actions/stale)
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
name: Questions
runs-on: ubuntu-latest
steps:
- name: Close Issue
uses: peter-evans/close-issue@v2
if: "${{ github.event.label.name == ':speech_balloon: Question' }}"
with:
comment: Please note this issue tracker is not a help forum. We recommend using [StackOverflow](https://stackoverflow.com/questions/tagged/jestjs) or our [discord channel](https://discord.gg/j6FKKQQrW9) for questions.
- if: "${{ github.event.label.name == ':speech_balloon: Question' }}"
run: gh issue close $ISSUE --comment "Please note this issue tracker is not a help forum. We recommend using [StackOverflow](https://stackoverflow.com/questions/tagged/jestjs) or our [discord channel](https://discord.gg/j6FKKQQrW9) for questions."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE: ${{ github.event.issue.html_url }}
bug-without-repro:
name: Bug reports without reproductions
runs-on: ubuntu-latest
steps:
- name: Close Issue
uses: peter-evans/close-issue@v2
if: "${{ github.event.label.name == 'Needs Reproduction' }}"
with:
comment: As noted in the [Bug Report template](https://github.com/facebook/jest/blob/main/.github/ISSUE_TEMPLATE/bug.yml), all bug reports requires a minimal reproduction. Please open up a new issue providing one. Read more at https://stackoverflow.com/help/minimal-reproducible-example.
- if: "${{ github.event.label.name == 'Needs Reproduction' }}"
run: gh issue close $ISSUE --comment "As noted in the [Bug Report template](https://github.com/jestjs/jest/blob/main/.github/ISSUE_TEMPLATE/bug.yml), all bug reports requires a minimal reproduction. Please open up a new issue providing one. Read more at https://stackoverflow.com/help/minimal-reproducible-example."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE: ${{ github.event.issue.html_url }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x, 18.x, 19.x]
node-version: [14.x, 16.x, 18.x, 19.x, 20.x]
shard: ['1/4', '2/4', '3/4', '4/4']
name: Node v${{ matrix.node-version }} on ${{ inputs.os }} (${{ matrix.shard }})
runs-on: ${{ inputs.os }}
Expand Down
222 changes: 111 additions & 111 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

559 changes: 280 additions & 279 deletions .yarn/releases/yarn-3.5.0.cjs → .yarn/releases/yarn-3.6.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.5.0.cjs
yarnPath: .yarn/releases/yarn-3.6.1.cjs
32 changes: 30 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,55 @@

### Features

### Fixes

- `[jest-circus]` Fix snapshot matchers in concurrent tests when nr of tests exceeds `maxConcurrency` ([#14335](https://github.com/jestjs/jest/pull/14335))
- `[jest-snapshot]` Move `@types/prettier` from `dependencies` to `devDependencies` ([#14328](https://github.com/jestjs/jest/pull/14328))

### Chore & Maintenance

- `[@jest/core]` Use `pluralize` from `jest-util` rather than own internal ([#14322](https://github.com/jestjs/jest/pull/14322))

### Performance

## 29.6.1

### Fixes

- `[jest-circus]` Revert [#14110](https://github.com/jestjs/jest/pull/14110) as it was a breaking change ([#14304](https://github.com/jestjs/jest/pull/14304))

## 29.6.0

### Features

- `[jest-circus, jest-snapshot]` Add support for snapshot matchers in concurrent tests ([#14139](https://github.com/jestjs/jest/pull/14139))
- `[jest-cli]` Include type definitions to generated config files ([#14078](https://github.com/facebook/jest/pull/14078))
- `[jest-snapshot]` Support arrays as property matchers ([#14025](https://github.com/facebook/jest/pull/14025))
- `[jest-core, jest-circus, jest-reporter, jest-runner]` Added support for reporting about start individual test cases using jest-circus ([#14174](https://github.com/jestjs/jest/pull/14174))

### Fixes

- `[jest-circus]` Prevent false test failures caused by promise rejections handled asynchronously ([#14110](https://github.com/jestjs/jest/pull/14110))
- `[jest-config]` Handle frozen config object ([#14054](https://github.com/facebook/jest/pull/14054))
- `[jest-config]` Allow `coverageDirectory` and `collectCoverageFrom` in project config ([#14180](https://github.com/jestjs/jest/pull/14180))
- `[jest-core]` Always use workers in watch mode to avoid crashes ([#14059](https://github.com/facebook/jest/pull/14059)).
- `[jest-environment-jsdom, jest-environment-node]` Fix assignment of `customExportConditions` via `testEnvironmentOptions` when custom env subclass defines a default value ([#13989](https://github.com/facebook/jest/pull/13989))
- `[jest-matcher-utils]` Fix copying value of inherited getters ([#14007](https://github.com/facebook/jest/pull/14007))
- `[jest-mock]` Tweak typings to allow `jest.replaceProperty()` replace methods ([#14008](https://github.com/facebook/jest/pull/14008))
- `[jest-mock]` Improve user input validation and error messages of `spyOn` and `replaceProperty` methods ([#14087](https://github.com/facebook/jest/pull/14087))
- `[jest-runtime]` Bind `jest.isolateModulesAsync` to `this` ([#14083](https://github.com/facebook/jest/pull/14083))
- `[jest-runtime]` Forward `wrapperLength` to the `Script` constructor as `columnOffset` for accurate debugging ([#14148](https://github.com/facebook/jest/pull/14148))
- `[jest-runtime]` Guard `_isMockFunction` access with `in` ([#14188](https://github.com/facebook/jest/pull/14188))
- `[jest-snapshot]` Fix a potential bug when not using prettier and improve performance ([#14036](https://github.com/facebook/jest/pull/14036))
- `[@jest/transform]` Do not instrument `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048))
- `[jest-worker]` Restart a shut down worker before sending it a task ([#14015](https://github.com/facebook/jest/pull/14015))

### Chore & Maintenance

- `[*]` Update `semver` dependency to get vulnerability fix ([#14262](https://github.com/jestjs/jest/pull/14262))
- `[docs]` Updated documentation for the `--runTestsByPath` CLI command ([#14004](https://github.com/facebook/jest/pull/14004))
- `[docs]` Updated documentation regarding the synchronous fallback when asynchronous code transforms are unavailable ([#14056](https://github.com/facebook/jest/pull/14056))

### Performance
- `[docs]` Update jest statistics of use and downloads in website Index.

## 29.5.0

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<a href="https://github.com/facebook/jest/blob/main/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Jest is released under the MIT license." />
</a>
<a href="https://twitter.com/intent/follow?screen_name=fbjest">
<img src="https://img.shields.io/twitter/follow/fbjest.svg?style=social&label=Follow%20@fbjest" alt="Follow on Twitter" />
<a href="https://twitter.com/intent/follow?screen_name=jestjs_">
<img src="https://img.shields.io/twitter/follow/jestjs_.svg?style=social&label=Follow%20@jestjs_" alt="Follow on Twitter" />
</a>
</p>
<p align="center">
Expand Down
2 changes: 1 addition & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ module.exports = config;
import type {Config} from 'jest';

const config: Config = {
setupFilesAfterEnv: ['<rootDir>/setup-matchers.js'],
setupFilesAfterEnv: ['<rootDir>/setup-jest.js'],
};

export default config;
Expand Down
1 change: 0 additions & 1 deletion docs/Es6ClassMocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ You can mock/spy on them easily, here is an example:
```javascript
// your jest test file below
import SoundPlayer from './sound-player';
import SoundPlayerConsumer from './sound-player-consumer';

const staticMethodMock = jest
.spyOn(SoundPlayer, 'brand')
Expand Down
2 changes: 1 addition & 1 deletion docs/MoreResources.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ You will find a number of example test cases in the [`examples`](https://github.

Ask questions and find answers from other Jest users like you. [Reactiflux](https://discord.gg/j6FKKQQrW9) is a Discord chat where a lot of Jest discussion happens. Check out the `#testing` channel.

Follow the [Jest Twitter account](https://twitter.com/fbjest) and [blog](/blog/) to find out what's happening in the world of Jest.
Follow the [Jest Twitter account](https://twitter.com/jestjs_) and [blog](/blog/) to find out what's happening in the world of Jest.
8 changes: 4 additions & 4 deletions docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Once you're finished, Jest will give you a summary before returning back to watc

Inline snapshots behave identically to external snapshots (`.snap` files), except the snapshot values are written automatically back into the source code. This means you can get the benefits of automatically generated snapshots without having to switch to an external file to make sure the correct value was written.

**Example:**
Example:

First, you write a test, calling `.toMatchInlineSnapshot()` with no arguments:

Expand Down Expand Up @@ -160,7 +160,7 @@ it('will fail every time', () => {

// Snapshot
exports[`will fail every time 1`] = `
Object {
{
"createdAt": 2018-05-19T23:36:09.816Z,
"id": 3,
"name": "LeBron James",
Expand All @@ -186,7 +186,7 @@ it('will check the matchers and pass', () => {

// Snapshot
exports[`will check the matchers and pass 1`] = `
Object {
{
"createdAt": Any<Date>,
"id": Any<Number>,
"name": "LeBron James",
Expand All @@ -211,7 +211,7 @@ it('will check the values and pass', () => {

// Snapshot
exports[`will check the values and pass 1`] = `
Object {
{
"createdAt": Any<Date>,
"name": 'Bond... James Bond',
}
Expand Down
35 changes: 2 additions & 33 deletions docs/TutorialReact.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ React 16 triggers these warnings due to how it checks element types, and the moc

### DOM Testing

If you'd like to assert, and manipulate your rendered components you can use [react-testing-library](https://github.com/kentcdodds/react-testing-library), [Enzyme](https://enzymejs.github.io/enzyme/), or React's [TestUtils](https://reactjs.org/docs/test-utils.html). The following two examples use react-testing-library and Enzyme.
If you'd like to assert, and manipulate your rendered components you can use [@testing-library/react](https://github.com/testing-library/react-testing-library), [Enzyme](https://enzymejs.github.io/enzyme/), or React's [TestUtils](https://reactjs.org/docs/test-utils.html). The following example use `@testing-library/react`.

#### react-testing-library
#### @testing-library/react

```bash npm2yarn
npm install --save-dev @testing-library/react
Expand Down Expand Up @@ -261,37 +261,6 @@ it('CheckboxWithLabel changes the text after click', () => {

The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/main/examples/react-testing-library).

#### Enzyme

```bash npm2yarn
npm install --save-dev enzyme
```

If you are using a React version below 15.5.0, you will also need to install `react-addons-test-utils`.

Let's rewrite the test from above using Enzyme instead of react-testing-library. We use Enzyme's [shallow renderer](https://enzymejs.github.io/enzyme/docs/api/shallow.html) in this example.

```tsx title="__tests__/CheckboxWithLabel-test.js"
import Enzyme, {shallow} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import CheckboxWithLabel from '../CheckboxWithLabel';

Enzyme.configure({adapter: new Adapter()});

it('CheckboxWithLabel changes the text after click', () => {
// Render a checkbox with label in the document
const checkbox = shallow(<CheckboxWithLabel labelOn="On" labelOff="Off" />);

expect(checkbox.text()).toBe('Off');

checkbox.find('input').simulate('change');

expect(checkbox.text()).toBe('On');
});
```

The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/main/examples/enzyme).

### Custom transformers

If you need more advanced functionality, you can also build your own transformer. Instead of using `babel-jest`, here is an example of using `@babel/core`:
Expand Down
4 changes: 2 additions & 2 deletions e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as path from 'path';
import * as util from 'util';
import dedent = require('dedent');
import dedent from 'dedent';
import {
ExecaSyncError,
SyncOptions as ExecaSyncOptions,
Expand Down Expand Up @@ -91,7 +91,7 @@ export const linkJestPackage = (packageName: string, cwd: string) => {
};

export const makeTemplate =
(str: string): ((values?: Array<unknown>) => string) =>
(str: string): ((values?: Array<string>) => string) =>
(values = []) =>
str.replace(/\$(\d+)/g, (_match, number) => {
if (!Array.isArray(values)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ exports[`Custom Reporters Integration on jest-circus push test case results for
"onTestCaseResult: sample, status: todo, numExpectations: 0
onTestFileResult testCaseResult 0: sample, status: todo, numExpectations: 0"
`;

exports[`Custom Reporters Integration on jest-circus push test case start 1`] = `
"onTestCaseStart: test 1, mode: undefined, ancestorTitles: Custom Reporters
onTestCaseStart: test 2, mode: undefined, ancestorTitles: Custom Reporters"
`;

exports[`Custom Reporters Integration on jest-circus doesn't push test case start for skip tests 1`] = `""`;

exports[`Custom Reporters Integration on jest-circus doesn't push test case start for todo tests 1`] = `""`;
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/globals.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ exports[`cannot have describe with no implementation 1`] = `
Missing second argument. It must be a callback function.
> 1 | describe('describe, no implementation');
| ^
| ^
at Object.<anonymous> (__tests__/onlyConstructs.test.js:1:10)"
at Object.<anonymous> (__tests__/onlyConstructs.test.js:1:40)"
`;
exports[`cannot have describe with no implementation 2`] = `
Expand Down
2 changes: 2 additions & 0 deletions e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
"cache": false,
"cacheDirectory": "/tmp/jest",
"clearMocks": false,
"collectCoverageFrom": [],
"coverageDirectory": "<<REPLACED_ROOT_DIR>>/coverage",
"coveragePathIgnorePatterns": [
"/node_modules/"
],
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FAIL __tests__/worksWithConcurrentMode.test.js
15 | });
16 |
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:176:11)
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:175:11)
at Suite.failing (__tests__/worksWithConcurrentMode.test.js:13:17)
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)
Expand Down Expand Up @@ -80,7 +80,7 @@ FAIL __tests__/worksWithConcurrentOnlyMode.test.js
15 | });
16 |
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:176:11)
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:175:11)
at Suite.failing (__tests__/worksWithConcurrentOnlyMode.test.js:13:22)
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)
Expand Down
36 changes: 36 additions & 0 deletions e2e/__tests__/customReportersOnCircus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,40 @@ describe('Custom Reporters Integration on jest-circus', () => {

expect(stdout).toMatchSnapshot();
});

test('push test case start', () => {
const {stdout} = runJest('custom-reporters', [
'--config',
JSON.stringify({
reporters: ['default', '<rootDir>/reporters/TestCaseStartReporter.js'],
}),
'just2Tests.test.js',
]);

expect(stdout).toMatchSnapshot();
});

test("doesn't push test case start for todo tests", () => {
const {stdout} = runJest('custom-reporters', [
'--config',
JSON.stringify({
reporters: ['default', '<rootDir>/reporters/TestCaseStartReporter.js'],
}),
'todo.test.js',
]);

expect(stdout).toMatchSnapshot();
});

test("doesn't push test case start for skip tests", () => {
const {stdout} = runJest('custom-reporters', [
'--config',
JSON.stringify({
reporters: ['default', '<rootDir>/reporters/TestCaseStartReporter.js'],
}),
'skip.test.js',
]);

expect(stdout).toMatchSnapshot();
});
});
16 changes: 16 additions & 0 deletions e2e/__tests__/snapshot-concurrent.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {skipSuiteOnJasmine} from '@jest/test-utils';
import runJest from '../runJest';

skipSuiteOnJasmine();

test('Snapshots get correct names in concurrent tests', () => {
const result = runJest('snapshot-concurrent', ['--ci']);
expect(result.exitCode).toBe(0);
});

0 comments on commit 28ac110

Please sign in to comment.