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

Update jest to v24 #31825

Merged
merged 22 commits into from
Feb 28, 2019
Merged

Update jest to v24 #31825

merged 22 commits into from
Feb 28, 2019

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Feb 22, 2019

Summary

Update to v24

  • jest
  • jest-cli
  • @types/jest

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@mshustov mshustov changed the title Update jest Update jest to v24 Feb 22, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@epixa
Copy link
Contributor

epixa commented Feb 22, 2019

There's also jest inside x-pack/package.json that we'll need to update as well. I assume that's why the lock file changes had so many additions but none of the existing jest stuff was removed or changed.

],
"results": Array [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't make sense to test jest internals, so I removed part of snapshot test (yes, it had a conflict with new jest version)

@@ -22,7 +22,7 @@ import { LOCK_WINDOW, ReindexActions, reindexActionsFactory } from './reindex_ac

describe('ReindexActions', () => {
let client: jest.Mocked<any>;
let callCluster: jest.Mock<CallCluster>;
let callCluster: jest.Mock;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

had to delete declaration as mock doesn't implement full CallCluster contract

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, I'll fix this up to be complete after this is merged (I wrote this).

@@ -46,7 +46,7 @@
"@types/expect.js": "^0.3.29",
"@types/graphql": "^0.13.1",
"@types/history": "^4.6.2",
"@types/jest": "^23.3.1",
"@types/jest": "^24.0.6",
Copy link
Contributor Author

@mshustov mshustov Feb 24, 2019

Choose a reason for hiding this comment

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

@epixa why we need to have another package.json for x-pack?

@@ -202,6 +203,8 @@
"inline-style": "^2.0.0",
"intl": "^1.2.5",
"io-ts": "^1.4.2",
"jest": "^24.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why packages are duplicated in "devDependencies" and "dependencies"?

Copy link
Member

Choose a reason for hiding this comment

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

Probably a mistake. I would be surprised if we wanted to ship jest in the production build to users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes it happens. Contentful did it to run their functional tests 😅

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mshustov mshustov requested a review from a team February 24, 2019 18:22
@mshustov mshustov added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Feb 24, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

@mshustov mshustov added the non-issue Indicates to automation that a pull request should not appear in the release notes label Feb 24, 2019
@mshustov mshustov marked this pull request as ready for review February 25, 2019 13:07
@mshustov mshustov requested review from a team as code owners February 25, 2019 13:07
Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

LGTM from APM. Thanks for updating Jest!

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

A few notes, mostly about the tests themselves rather than your changes. Figured now is a good time to fix some of these issues since their aren't too many, but I'll leave some of the trickier cases at your discretion on whether or not they're worth fixing right now.

@@ -12,7 +12,7 @@ exports[`#start constructs UiSettingsClient and UiSettingsApi: UiSettingsApi arg
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
Copy link
Contributor

Choose a reason for hiding this comment

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

These snapshots look like they're testing more jest internals rather than just the call arguments themselves. Can we fix these too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mocked functions are inside JS objects that serialised for snapshot testing. I didn't find a cheap way to fix it and decided to keep it as is.
As an alternative solution, we can define custom serialiser for mocked functions https://jestjs.io/docs/en/configuration#snapshotserializers-array-string

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfectly good reason.

@@ -37,7 +37,7 @@ Array [
],
"results": Array [
Object {
"isThrow": false,
"type": "return",
Copy link
Contributor

Choose a reason for hiding this comment

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

Jest internals here as well, though this may be a bit hard to fix since it's an entire object. I'm not sure why we're testing such large snapshots like this though.

@@ -27,7 +27,7 @@ let appenderMocks: Appender[];
let logger: BaseLogger;

const timestamp = new Date(2012, 1, 1);
jest.spyOn(global, 'Date').mockImplementation(() => timestamp);
jest.spyOn<any, any>(global, 'Date').mockImplementation(() => timestamp);
Copy link
Contributor

Choose a reason for hiding this comment

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

This spy doesn't ever seem to be restored with mockRestore. We should make sure that happens explicitly after these tests run since we don't have the restoreMocks config option set to true.

As an aside: it'd be awesome if there was linter rule we could add for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will fix. don't know why but I was sure we use restoreMocks: true

@@ -27,10 +27,10 @@ const timestamp = new Date(Date.UTC(2012, 1, 1));
const mockConsoleLog = jest.spyOn(global.console, 'log').mockImplementation(() => {
// noop
});
jest.spyOn(global, 'Date').mockImplementation(() => timestamp);
jest.spyOn<any, any>(global, 'Date').mockImplementation(() => timestamp);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above about mockRestore

@@ -22,7 +22,7 @@ import { LOCK_WINDOW, ReindexActions, reindexActionsFactory } from './reindex_ac

describe('ReindexActions', () => {
let client: jest.Mocked<any>;
let callCluster: jest.Mock<CallCluster>;
let callCluster: jest.Mock;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, I'll fix this up to be complete after this is merged (I wrote this).

});
const mockProcessExit = jest
.spyOn(global.process, 'exit')
.mockImplementation(() => undefined as never);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also missing a restore.

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -281,7 +281,7 @@
"@types/has-ansi": "^3.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

question: how about updating babel-jest to 24.1.0 here and in x-pack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

babel-jest@v24 uses babel@v7 which require @kbn/babel-preset/node_preset update. seems like quite a bit task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be done in #32326

@@ -202,6 +202,7 @@
"inline-style": "^2.0.0",
"intl": "^1.2.5",
"io-ts": "^1.4.2",
"jest-cli": "^24.1.0",
Copy link
Member

Choose a reason for hiding this comment

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

question/issue: why do we need jest-cli in non-dev dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems like a mistake when updated version via yarn cli. will fix now

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mshustov mshustov merged commit 5fc7add into elastic:master Feb 28, 2019
@mshustov mshustov deleted the update-jest branch February 28, 2019 12:26
mshustov added a commit to mshustov/kibana that referenced this pull request Feb 28, 2019
* udpate jest, jest-cli, @types/jest to v24

* fix type error in kibana-i18n package

* return serivce explicitly to fix typings

* add explicit never

* suppress typings errors

* update jest versions in x-pack

* make tests in x-pack more robust and fix incompatibility

* suppress CallCluster mock typings

Mock interface doesn't match CallCluster. Requires
additional work

* x-pack. resolve other typing conflicts

* remove unused types/jest

* fix snapshots

* restore mocks after jest.spyOn

* remove outdated definitions for jest

* cleanup x-pack package.json and update @types/jest

* fix tests merged from master

* updated yarn.lock and log errors for scripts/type_check

* This commit fixes error in TS, which failed on parsing the file.

* suppress type errors from master

* jest-cli is devDep
mshustov added a commit to mshustov/kibana that referenced this pull request Feb 28, 2019
* udpate jest, jest-cli, @types/jest to v24

* fix type error in kibana-i18n package

* return serivce explicitly to fix typings

* add explicit never

* suppress typings errors

* update jest versions in x-pack

* make tests in x-pack more robust and fix incompatibility

* suppress CallCluster mock typings

Mock interface doesn't match CallCluster. Requires
additional work

* x-pack. resolve other typing conflicts

* remove unused types/jest

* fix snapshots

* restore mocks after jest.spyOn

* remove outdated definitions for jest

* cleanup x-pack package.json and update @types/jest

* fix tests merged from master

* updated yarn.lock and log errors for scripts/type_check

* This commit fixes error in TS, which failed on parsing the file.

* suppress type errors from master

* jest-cli is devDep

Removes sinon from saved objects unit tests. (elastic#32045) (elastic#32151)

* Removes sinon from saved objects unit tests.

* Uses mockResolvedValue for return values as promises.

temp
mshustov added a commit that referenced this pull request Feb 28, 2019
* udpate jest, jest-cli, @types/jest to v24

* fix type error in kibana-i18n package

* return serivce explicitly to fix typings

* add explicit never

* suppress typings errors

* update jest versions in x-pack

* make tests in x-pack more robust and fix incompatibility

* suppress CallCluster mock typings

Mock interface doesn't match CallCluster. Requires
additional work

* x-pack. resolve other typing conflicts

* remove unused types/jest

* fix snapshots

* restore mocks after jest.spyOn

* remove outdated definitions for jest

* cleanup x-pack package.json and update @types/jest

* fix tests merged from master

* updated yarn.lock and log errors for scripts/type_check

* This commit fixes error in TS, which failed on parsing the file.

* suppress type errors from master

* jest-cli is devDep

Removes sinon from saved objects unit tests. (#32045) (#32151)

* Removes sinon from saved objects unit tests.

* Uses mockResolvedValue for return values as promises.

temp
mshustov added a commit that referenced this pull request Feb 28, 2019
* Update jest to v24 (#31825)

* udpate jest, jest-cli, @types/jest to v24

* fix type error in kibana-i18n package

* return serivce explicitly to fix typings

* add explicit never

* suppress typings errors

* update jest versions in x-pack

* make tests in x-pack more robust and fix incompatibility

* suppress CallCluster mock typings

Mock interface doesn't match CallCluster. Requires
additional work

* x-pack. resolve other typing conflicts

* remove unused types/jest

* fix snapshots

* restore mocks after jest.spyOn

* remove outdated definitions for jest

* cleanup x-pack package.json and update @types/jest

* fix tests merged from master

* updated yarn.lock and log errors for scripts/type_check

* This commit fixes error in TS, which failed on parsing the file.

* suppress type errors from master

* jest-cli is devDep

* updated yarn.lock
@mshustov mshustov mentioned this pull request Mar 1, 2019
3 tasks
cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Mar 8, 2019
Fixes elastic#32619

With elastic#31825 the reporter contract changed slightly and this updates our custom reporter to fix our junit reports.
spalger pushed a commit to spalger/kibana that referenced this pull request Mar 8, 2019
Fixes elastic#32619

With elastic#31825 the reporter contract changed slightly and this updates our custom reporter to fix our junit reports.
spalger pushed a commit to spalger/kibana that referenced this pull request Mar 8, 2019
Fixes elastic#32619

With elastic#31825 the reporter contract changed slightly and this updates our custom reporter to fix our junit reports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported chore non-issue Indicates to automation that a pull request should not appear in the release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team v7.0.0 v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants