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

Rename jest-matchers to expect #4345

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration_tests/browser-support/browser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/* eslint-disable */
var expect = require('../../packages/jest-matchers/build-es5/index.js');
var expect = require('../../packages/expect/build-es5/index.js');
var mock = require('../../packages/jest-mock/build-es5/index.js');
var prettyFormat = require('../../packages/pretty-format/build-es5/index.js');

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jest-matchers",
"name": "expect",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the plan to use expect directly, not to replace it with the contents of jest-matchers? expect has lots of important tests and behaviors that jest-matchers may not be replicating, so semver-major or not, that could end up screwing over a lot of people.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any concrete features you can think of?

Mocking is provided by jest-mock, which will need docs of course, but I think there is feature parity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to go through all the tests.

I'm pretty sure more people use expect than jest-matchers; I'm not sure why the former wouldn't be the one that should survive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is happening @ljharb and @mjackson agreed on this almost a year back. It took us a long time to get everything in shape, and make jest-matchers work in browsers etc. @skovhus built an extensive codemod that gets you 90% of the way there: skovhus/jest-codemods#62

Your assumption about more people using expect than jest-matchers is not correct according to this chart: http://www.npmtrends.com/expect-vs-jest-matchers although I'm willing to believe many people use a single-file bundle of it in a web site; which also means they don't rely on the npm package being called expect and are not updating it through npm.

Either way, we'll publish expect with version 21. If people want to keep using the old expect, patches can be released to the 1.x version of the project.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb The plan was always to donate the expect package to the Jest team so they could run with it. They are doing an excellent job making an assertion library (jest-matchers) with very similar goals to expect, not to mention the syntax for most common assertions is practically identical, and I'd rather unite the community under one package than two.

As for "screwing over a lot of people" I don't think that's happening here. I've been very clear about my intentions for the expect project for a long time now and most people I talk to seem very supportive of the idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair; I suppose I was just under the wrong impression.

I'm supportive of a package remaining maintained; if it needs to be replaced with a different implementation to do so, that's fine; I just hope that the breaking changes will be minimal and clearly documented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a a codemod (skovhus/jest-codemods#62) which will port most of existent expect code. I don't think there's any breaking changes beyond that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codemods are great; but I don't think automated ones should be required to be able to have a smooth upgrade experience.

"version": "20.0.3",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Expected the function to throw an error of type:
<green>\\"Err2\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrow() error class threw, but should not have 1`] = `
Expand All @@ -25,7 +25,7 @@ Expected the function not to throw an error of type:
<green>\\"Err\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrow() invalid actual 1`] = `
Expand Down Expand Up @@ -58,7 +58,7 @@ Expected the function to throw an error matching:
<green>/banana/</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrow() regexp threw, but should not have 1`] = `
Expand All @@ -68,7 +68,7 @@ Expected the function not to throw an error matching:
<green>/apple/</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrow() strings did not throw at all 1`] = `
Expand All @@ -86,7 +86,7 @@ Expected the function to throw an error matching:
<green>\\"banana\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrow() strings threw, but should not have 1`] = `
Expand All @@ -96,7 +96,7 @@ Expected the function not to throw an error matching:
<green>\\"apple\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrowError() error class did not throw at all 1`] = `
Expand All @@ -114,7 +114,7 @@ Expected the function to throw an error of type:
<green>\\"Err2\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrowError() error class threw, but should not have 1`] = `
Expand All @@ -124,7 +124,7 @@ Expected the function not to throw an error of type:
<green>\\"Err\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrowError() invalid actual 1`] = `
Expand Down Expand Up @@ -157,7 +157,7 @@ Expected the function to throw an error matching:
<green>/banana/</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrowError() regexp threw, but should not have 1`] = `
Expand All @@ -167,7 +167,7 @@ Expected the function not to throw an error matching:
<green>/apple/</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrowError() strings did not throw at all 1`] = `
Expand All @@ -185,7 +185,7 @@ Expected the function to throw an error matching:
<green>\\"banana\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;

exports[`.toThrowError() strings threw, but should not have 1`] = `
Expand All @@ -195,5 +195,5 @@ Expected the function not to throw an error matching:
<green>\\"apple\\"</>
Instead, it threw:
<red> Error </>
<red> <dim>at jestExpect (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
<red> <dim>at jestExpect (packages/expect/src/__tests__/toThrowMatchers-test.js<dim>:24:74)</>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Error {
this.stack =
'Error\n' +
' at jestExpect' +
' (packages/jest-matchers/src/__tests__/toThrowMatchers-test.js:24:74)';
' (packages/expect/src/__tests__/toThrowMatchers-test.js:24:74)';
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"main": "build/index.js",
"dependencies": {
"chalk": "^2.0.1",
"expect": "^20.0.3",
"jest-snapshot": "^20.0.3",
"jest-matchers": "^20.0.3",
"jest-matcher-utils": "^20.0.3",
"jest-message-util": "^20.0.3",
"jest-diff": "^20.0.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import type {TestResult, Status} from 'types/TestResult';
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
import type {Event, TestEntry} from 'types/Circus';

import {
extractExpectedAssertionsErrors,
getState,
setState,
} from 'jest-matchers';
import {extractExpectedAssertionsErrors, getState, setState} from 'expect';
import {formatResultsErrors} from 'jest-message-util';
import {SnapshotState, addSerializer} from 'jest-snapshot';
import {addEventHandler, ROOT_DESCRIBE_BLOCK_NAME} from '../state';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import type {RawMatcherFn} from 'types/Matchers';

import expect from 'jest-matchers';
import expect from 'expect';

import {
addSerializer,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"main": "build/index.js",
"dependencies": {
"chalk": "^2.0.1",
"expect": "^20.0.3",
"graceful-fs": "^4.1.11",
"jest-diff": "^20.0.3",
"jest-matcher-utils": "^20.0.3",
"jest-matchers": "^20.0.3",
"jest-message-util": "^20.0.3",
"jest-snapshot": "^20.0.3"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`matchers proxies matchers to jest-matchers 1`] = `
exports[`matchers proxies matchers to expect 1`] = `
"<dim>expect(<red>received</><dim>).toBe(<green>expected</><dim>)

Expected value to be (using ===):
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

describe('matchers', () => {
it('proxies matchers to jest-matchers', () => {
it('proxies matchers to expect', () => {
expect(() => expect(1).toBe(2)).toThrowErrorMatchingSnapshot();
});
});
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/jest_expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import type {RawMatcherFn} from 'types/Matchers';

import expect from 'jest-matchers';
import expect from 'expect';
import {
addSerializer,
toMatchSnapshot,
Expand Down
6 changes: 1 addition & 5 deletions packages/jest-jasmine2/src/setup_jest_globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
import type {Plugin} from 'types/PrettyFormat';

import {
extractExpectedAssertionsErrors,
getState,
setState,
} from 'jest-matchers';
import {extractExpectedAssertionsErrors, getState, setState} from 'expect';
import {SnapshotState, addSerializer} from 'jest-snapshot';

export type SetupOptions = {|
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-matcher-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-matcher-utils",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably rename this package to something else too…

"description": "A set of utility functions for jest-matchers and related packages",
"description": "A set of utility functions for expect and related packages",
"version": "20.0.3",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const JS_FILES_PATTERN = '**/*.js';
const IGNORE_PATTERN = '**/__tests__/**';
const PACKAGES_DIR = path.resolve(__dirname, '../packages');

const INLINE_REQUIRE_BLACKLIST = /packages\/(jest-(circus|diff|get-type|jasmine2|matcher-utils|matchers|message-util|regex-util|snapshot))|pretty-format\//;
const INLINE_REQUIRE_BLACKLIST = /packages\/expect|(jest-(circus|diff|get-type|jasmine2|matcher-utils|message-util|regex-util|snapshot))|pretty-format\//;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though for a moment the Symbol bug was back before I remembered to change this... Gave me a scare!


const transformOptions = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '..', '.babelrc'), 'utf8')
Expand Down