Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7846/use property initializer syntax #8117

Merged
merged 17 commits into from Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@
### Chore & Maintenance

- `[*]` Make sure to include `d.ts` files in the tarball when building ([#8086](https://github.com/facebook/jest/pull/8086))
- `[*]` Use property initializer syntax in Jest codebase [#8117](https://github.com/facebook/jest/pull/8117)

### Performance

Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Expand Up @@ -21,6 +21,7 @@ module.exports = {
plugins: [
['@babel/plugin-transform-modules-commonjs', {allowTopLevelThis: true}],
'@babel/plugin-transform-strict-mode',
'@babel/plugin-proposal-class-properties',
],
presets: [
[
Expand Down
Expand Up @@ -15,6 +15,6 @@ PASS __tests__/console.test.js
15 | });
16 |

at BufferedConsole.log (../../packages/jest-console/build/BufferedConsole.js:180:10)
at BufferedConsole.log (../../packages/jest-console/build/BufferedConsole.js:199:10)
at log (__tests__/console.test.js:13:13)
`;
8 changes: 7 additions & 1 deletion e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap
Expand Up @@ -13,7 +13,13 @@ This usually means that there are asynchronous operations that weren't stopped i
`;

exports[`prints out info about open handlers 1`] = `
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
Jest has detected the following 2 open handles potentially keeping Jest from exiting:

● DNSCHANNEL

at dns.js:333:23
at Object.listen (server.js:9:5)
This conversation was marked as resolved.
Show resolved Hide resolved


● GETADDRINFOREQWRAP

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap
Expand Up @@ -30,6 +30,6 @@ FAIL __tests__/index.js
12 | module.exports = () => 'test';
13 |

at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:435:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:455:17)
at Object.require (index.js:10:1)
`;
Expand Up @@ -33,6 +33,6 @@ FAIL __tests__/test.js
| ^
4 |

at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:202:17)
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:222:17)
at Object.require (index.js:3:18)
`;
1 change: 1 addition & 0 deletions examples/enzyme/.babelrc.js
Expand Up @@ -2,4 +2,5 @@

module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-class-properties']
};
15 changes: 5 additions & 10 deletions examples/enzyme/CheckboxWithLabel.js
Expand Up @@ -3,18 +3,13 @@
import React from 'react';

export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};
state = {
isChecked: false,
};

// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
}

onChange() {
onChange = () => {
this.setState({isChecked: !this.state.isChecked});
}
};

render() {
return (
Expand Down
1 change: 1 addition & 0 deletions examples/enzyme/package.json
Expand Up @@ -8,6 +8,7 @@
},
"devDependencies": {
"@babel/core": "*",
"@babel/plugin-proposal-class-properties": "*",
"@babel/preset-env": "*",
"@babel/preset-react": "*",
"babel-jest": "*",
Expand Down
8 changes: 2 additions & 6 deletions examples/react-testing-library/CheckboxWithLabel.js
Expand Up @@ -6,15 +6,11 @@ export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};

// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
}

onChange() {
onChange = () => {
this.setState({isChecked: !this.state.isChecked});
}
};

render() {
return (
Expand Down
8 changes: 2 additions & 6 deletions examples/react/CheckboxWithLabel.js
Expand Up @@ -6,15 +6,11 @@ export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};

// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
}

onChange() {
onChange = () => {
this.setState({isChecked: !this.state.isChecked});
}
};

render() {
return (
Expand Down
1 change: 1 addition & 0 deletions examples/snapshot/.babelrc.js
Expand Up @@ -2,4 +2,5 @@

module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-class-properties']
};
6 changes: 1 addition & 5 deletions examples/snapshot/Clock.react.js
Expand Up @@ -3,11 +3,7 @@
import React from 'react';

export default class Clock extends React.Component {
constructor() {
super();

this.state = {seconds: Date.now() / 1000};
}
state = {seconds: Date.now() / 1000};

componentDidMount() {
this.timerID = setInterval(() => this.tick(), 1000);
Expand Down
21 changes: 7 additions & 14 deletions examples/snapshot/Link.react.js
Expand Up @@ -8,24 +8,17 @@ const STATUS = {
};

export default class Link extends React.Component {
constructor() {
super();
state = {
class: STATUS.NORMAL,
};

this._onMouseEnter = this._onMouseEnter.bind(this);
this._onMouseLeave = this._onMouseLeave.bind(this);

this.state = {
class: STATUS.NORMAL,
};
}

_onMouseEnter() {
_onMouseEnter = () => {
this.setState({class: STATUS.HOVERED});
}
};

_onMouseLeave() {
_onMouseLeave = () => {
this.setState({class: STATUS.NORMAL});
}
};

render() {
return (
Expand Down
1 change: 1 addition & 0 deletions examples/snapshot/package.json
Expand Up @@ -7,6 +7,7 @@
},
"devDependencies": {
"@babel/core": "*",
"@babel/plugin-proposal-class-properties": "*",
"@babel/preset-env": "*",
"@babel/preset-react": "*",
"babel-jest": "*",
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -2,6 +2,7 @@
"private": true,
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
"@babel/plugin-transform-strict-mode": "^7.0.0",
"@babel/preset-env": "^7.1.0",
Expand Down
Expand Up @@ -247,7 +247,7 @@ But the last call returned:
<red>\\"foo\\"</>"
`;

exports[`lastReturnedWith works with three calls 1`] = `
exports[`lastReturnedWith works with three calls (3rd) 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.lastReturnedWith(</><green>expected</><dim>)</>

Expected mock function to not have last returned:
Expand Down Expand Up @@ -426,23 +426,23 @@ Expected mock function \\"named-mock\\" first call to have returned with:
But it was <red>not called</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 1`] = `
exports[`nthReturnedWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function first call to have returned with:
<green>6</>
But the first call <red>has not returned yet</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 2`] = `
exports[`nthReturnedWith incomplete recursive calls are handled properly 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function second call to have returned with:
<green>3</>
But the second call <red>has not returned yet</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 3`] = `
exports[`nthReturnedWith incomplete recursive calls are handled properly 3`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function third call to not have returned with:
Expand All @@ -451,7 +451,7 @@ But the third call returned exactly:
<red>1</>"
`;

exports[`nthReturnedWith incomplete recursive calls are handled properly 4`] = `
exports[`nthReturnedWith incomplete recursive calls are handled properly 4`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.nthReturnedWith(</><green>expected</><dim>)</>

Expected mock function 4th call to not have returned with:
Expand Down Expand Up @@ -1625,7 +1625,7 @@ But the last call returned:
<red>\\"foo\\"</>"
`;

exports[`toHaveLastReturnedWith works with three calls 1`] = `
exports[`toHaveLastReturnedWith works with three calls (3rd) 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveLastReturnedWith(</><green>expected</><dim>)</>

Expected mock function to not have last returned:
Expand Down Expand Up @@ -1667,23 +1667,23 @@ Expected mock function \\"named-mock\\" first call to have returned with:
But it was <red>not called</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 1`] = `
exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function first call to have returned with:
<green>6</>
But the first call <red>has not returned yet</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 2`] = `
exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function second call to have returned with:
<green>3</>
But the second call <red>has not returned yet</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 3`] = `
exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 3`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function third call to not have returned with:
Expand All @@ -1692,7 +1692,7 @@ But the third call returned exactly:
<red>1</>"
`;

exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 4`] = `
exports[`toHaveNthReturnedWith incomplete recursive calls are handled properly 4`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveNthReturnedWith(</><green>expected</><dim>)</>

Expected mock function 4th call to not have returned with:
Expand Down Expand Up @@ -2009,7 +2009,7 @@ exports[`toHaveReturnedTimes includes the custom mock name in the error message
Expected mock function \\"named-mock\\" to have returned <green>one time</>, but it returned <red>two times</>."
`;

exports[`toHaveReturnedTimes incomplete recursive calls are handled properly 1`] = `
exports[`toHaveReturnedTimes incomplete recursive calls are handled properly (2nd) 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toHaveReturnedTimes(</><green>2</><dim>)</>

Expected mock function not to have returned <green>two times</>, but it returned exactly <red>two times</>."
Expand Down Expand Up @@ -2108,7 +2108,7 @@ Expected mock function \\"named-mock\\" to have returned:
But it did <red>not return</>."
`;

exports[`toHaveReturnedWith incomplete recursive calls are handled properly 1`] = `
exports[`toHaveReturnedWith incomplete recursive calls are handled properly (3rd) 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveReturnedWith(</><green>expected</><dim>)</>

Expected mock function to have returned:
Expand Down Expand Up @@ -2404,7 +2404,7 @@ exports[`toReturnTimes includes the custom mock name in the error message 1`] =
Expected mock function \\"named-mock\\" to have returned <green>one time</>, but it returned <red>two times</>."
`;

exports[`toReturnTimes incomplete recursive calls are handled properly 1`] = `
exports[`toReturnTimes incomplete recursive calls are handled properly (2nd) 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).not.toReturnTimes(</><green>2</><dim>)</>

Expected mock function not to have returned <green>two times</>, but it returned exactly <red>two times</>."
Expand Down Expand Up @@ -2503,7 +2503,7 @@ Expected mock function \\"named-mock\\" to have returned:
But it did <red>not return</>."
`;

exports[`toReturnWith incomplete recursive calls are handled properly 1`] = `
exports[`toReturnWith incomplete recursive calls are handled properly (3rd) 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toReturnWith(</><green>expected</><dim>)</>

Expected mock function to have returned:
Expand Down
8 changes: 4 additions & 4 deletions packages/expect/src/__tests__/spyMatchers.test.js
Expand Up @@ -661,7 +661,7 @@ const jestExpect = require('../');
).toThrowErrorMatchingSnapshot();
});

test(`incomplete recursive calls are handled properly`, () => {
test(`incomplete recursive calls are handled properly (2nd)`, () => {
// sums up all integers from 0 -> value, using recursion
const fn = jest.fn(value => {
if (value === 0) {
Expand Down Expand Up @@ -892,7 +892,7 @@ const jestExpect = require('../');
}).toThrowErrorMatchingSnapshot();
});

test(`incomplete recursive calls are handled properly`, () => {
test(`incomplete recursive calls are handled properly (3rd)`, () => {
// sums up all integers from 0 -> value, using recursion
const fn = jest.fn(value => {
if (value === 0) {
Expand Down Expand Up @@ -988,7 +988,7 @@ const jestExpect = require('../');
}).toThrowErrorMatchingSnapshot();
});

test(`incomplete recursive calls are handled properly`, () => {
test(`incomplete recursive calls are handled properly `, () => {
// sums up all integers from 0 -> value, using recursion
const fn = jest.fn(value => {
if (value === 0) {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ const jestExpect = require('../');

const lastReturnedWith = ['toHaveLastReturnedWith', 'lastReturnedWith'];
if (lastReturnedWith.indexOf(returnedWith) >= 0) {
test(`works with three calls`, () => {
test(`works with three calls (3rd)`, () => {
const fn = jest.fn();
fn.mockReturnValueOnce('foo1');
fn.mockReturnValueOnce('foo2');
Expand Down
6 changes: 1 addition & 5 deletions packages/jest-core/src/TestSequencer.ts
Expand Up @@ -32,11 +32,7 @@ type Cache = {
* is called to store/update this information on the cache map.
*/
export default class TestSequencer {
private _cache: Map<Context, Cache>;

constructor() {
this._cache = new Map();
}
private _cache: Map<Context, Cache> = new Map();

_getCachePath(context: Context) {
const {config} = context;
Expand Down
15 changes: 5 additions & 10 deletions packages/jest-core/src/plugins/update_snapshots_interactive.ts
Expand Up @@ -11,16 +11,11 @@ import {BaseWatchPlugin, JestHookSubscriber} from 'jest-watcher';
import SnapshotInteractiveMode from '../SnapshotInteractiveMode';

class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
private _snapshotInteractiveMode: SnapshotInteractiveMode;
private _failedSnapshotTestAssertions: Array<AssertionLocation>;
isInternal: true;

constructor(options: {stdin: NodeJS.ReadStream; stdout: NodeJS.WriteStream}) {
super(options);
this._failedSnapshotTestAssertions = [];
this._snapshotInteractiveMode = new SnapshotInteractiveMode(this._stdout);
this.isInternal = true;
}
private _snapshotInteractiveMode: SnapshotInteractiveMode = new SnapshotInteractiveMode(
this._stdout,
);
private _failedSnapshotTestAssertions: Array<AssertionLocation> = [];
isInternal: true = true;

getFailedSnapshotTestAssertions(
testResults: AggregatedResult,
Expand Down