Skip to content

Commit

Permalink
Upgrade to Jest 23.5.0 (#22791)
Browse files Browse the repository at this point in the history
I'd really like to upgrade to Typescript 3 for its `unknown` type, but we need to upgrade to `jest@23` to support a recent version of `ts-jest@23`. 

The [jest changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md) breaks down the breaking changes in 23.x, but I found it to be slightly incomplete so I've broken down the changes that actually caused breaks for us here, and addressed each in individual commits to make review a little easier:

- the `testURL` config default was changed from `about:blank` to `http://localhost`
    - this cause some XHR requests powered by JSdom to start failing. It seems these requests just do nothing in master but start to fail when JSdom is initialized with an actual URL... I think we would ideally stop sending meaningless XHR requests in the tests, but it was a lot easier to just set the config to `about:blank` for now, and we can worry about cleanup later if necessary
- `expect(...).toThrow()` only passes if an actual error was thrown.
     - In two places in the index pattern code we were throwing strings, which broke the assertions. Fortunately/Unfortunately the errors are not being consumed by anything, so I was able to wrap them in `new Error()` without causing any issues.
- snapshots of mock functions now include a `results` array, detailing the return values of the function
- React fragments are now serialized as `<React.Fragment>` instead of `<UNDEFINED>`
- undefined props in React components are now stripped from snapshots
- minor changes to the ordering of mocks, imports resolution, and before hooks caused the uiSettings API tests to start breaking, but I'm replacing them with totally new tests in #22694 so I just deleted them here
- mocks created with `jest.spyOn()` that are restored now have their `mock.calls` reset, so some of the kbn-pm tests stated failing. This was fixed by restoring them with `jest.restoreAllMocks()` rather than trying to do it before the assertions
  • Loading branch information
Spencer committed Sep 8, 2018
1 parent c9b1d7a commit 7e94ecc
Show file tree
Hide file tree
Showing 29 changed files with 940 additions and 1,083 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
"@types/glob": "^5.0.35",
"@types/hapi-latest": "npm:@types/hapi@17.0.12",
"@types/has-ansi": "^3.0.0",
"@types/jest": "^22.2.3",
"@types/jest": "^23.3.1",
"@types/joi": "^10.4.4",
"@types/jquery": "3.3.1",
"@types/js-yaml": "^3.11.1",
Expand All @@ -244,7 +244,7 @@
"@types/type-detect": "^4.0.1",
"angular-mocks": "1.4.7",
"babel-eslint": "8.1.2",
"babel-jest": "^22.4.3",
"babel-jest": "^23.4.2",
"backport": "4.4.1",
"chai": "3.5.0",
"chance": "1.0.10",
Expand All @@ -260,7 +260,7 @@
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-babel": "4.1.2",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jest": "^21.6.2",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-mocha": "4.11.0",
"eslint-plugin-no-unsanitized": "^3.0.2",
"eslint-plugin-prefer-object-spread": "1.2.1",
Expand All @@ -285,8 +285,8 @@
"husky": "0.8.1",
"image-diff": "1.6.0",
"istanbul-instrumenter-loader": "3.0.0",
"jest": "^22.4.3",
"jest-cli": "^22.4.3",
"jest": "^23.5.0",
"jest-cli": "^23.5.0",
"jest-raw-loader": "^1.0.1",
"jimp": "0.2.28",
"jsdom": "9.9.1",
Expand Down Expand Up @@ -322,7 +322,7 @@
"supertest": "^3.1.0",
"supertest-as-promised": "^4.0.2",
"tree-kill": "^1.1.0",
"ts-jest": "^22.4.6",
"ts-jest": "^23.1.4",
"ts-loader": "^3.5.0",
"ts-node": "^6.0.3",
"tslint": "^5.10.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-kibana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"eslint": "^4.1.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-jest": "^21.0.0",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-mocha": "^4.9.0",
"eslint-plugin-no-unsanitized": "^3.0.2",
"eslint-plugin-prefer-object-spread": "^1.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint": "^4.11.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jest": "^21.3.2",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-mocha": "^4.9.0",
"eslint-plugin-no-unsanitized": "^3.0.2",
"eslint-plugin-prefer-object-spread": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-pm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/globby": "^6.1.0",
"@types/has-ansi": "^3.0.0",
"@types/indent-string": "^3.0.0",
"@types/jest": "^22.1.3",
"@types/jest": "^23.3.1",
"@types/lodash.clonedeepwith": "^4.5.3",
"@types/log-symbols": "^2.0.0",
"@types/mkdirp": "^0.5.2",
Expand Down
13 changes: 3 additions & 10 deletions packages/kbn-pm/src/commands/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const noop = () => {

afterEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
});

test('handles dependencies of dependencies', async () => {
Expand Down Expand Up @@ -96,8 +97,6 @@ test('handles dependencies of dependencies', async () => {
rootPath: '',
});

logMock.mockRestore();

expect(mockInstallInDir.mock.calls).toMatchSnapshot('install in dir');
expect(logMock.mock.calls).toMatchSnapshot('logs');
});
Expand Down Expand Up @@ -127,8 +126,6 @@ test('does not run installer if no deps in package', async () => {
rootPath: '',
});

logMock.mockRestore();

expect(mockInstallInDir.mock.calls).toMatchSnapshot('install in dir');
expect(logMock.mock.calls).toMatchSnapshot('logs');
});
Expand All @@ -143,7 +140,7 @@ test('handles "frozen-lockfile"', async () => {
const projects = new Map([['kibana', kibana]]);
const projectGraph = buildProjectGraph(projects);

const logMock = jest.spyOn(console, 'log').mockImplementation(noop);
jest.spyOn(console, 'log').mockImplementation(noop);

await BootstrapCommand.run(projects, projectGraph, {
extraArgs: [],
Expand All @@ -153,8 +150,6 @@ test('handles "frozen-lockfile"', async () => {
rootPath: '',
});

logMock.mockRestore();

expect(mockInstallInDir.mock.calls).toMatchSnapshot('install in dir');
});

Expand All @@ -177,16 +172,14 @@ test('calls "kbn:bootstrap" scripts and links executables after installing deps'
const projects = new Map([['kibana', kibana], ['bar', bar]]);
const projectGraph = buildProjectGraph(projects);

const logMock = jest.spyOn(console, 'log').mockImplementation(noop);
jest.spyOn(console, 'log').mockImplementation(noop);

await BootstrapCommand.run(projects, projectGraph, {
extraArgs: [],
options: {},
rootPath: '',
});

logMock.mockRestore();

expect(mockLinkProjectExecutables.mock.calls).toMatchSnapshot('link bins');
expect(mockRunScriptInPackageStreaming.mock.calls).toMatchSnapshot('script');
});
2 changes: 1 addition & 1 deletion packages/kbn-pm/src/utils/link_project_executables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ expect.addSnapshotSerializer(stripAnsiSnapshotSerializer);

afterEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
});

describe('bin script points nowhere', () => {
Expand All @@ -102,7 +103,6 @@ describe('bin script points to a file', () => {
// noop
});
await linkProjectExecutables(projectsByName, projectGraph);
logMock.mockRestore();

expect(getFsMockCalls()).toMatchSnapshot('fs module calls');
expect(logMock.mock.calls).toMatchSnapshot('logs');
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-pm/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/indent-string/-/indent-string-3.0.0.tgz#9ebb391ceda548926f5819ad16405349641b999f"

"@types/jest@^22.1.3":
version "22.1.3"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-22.1.3.tgz#25da391935e6fac537551456f077ce03144ec168"
"@types/jest@^23.3.1":
version "23.3.1"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.1.tgz#a4319aedb071d478e6f407d1c4578ec8156829cf"

"@types/lodash.clonedeepwith@^4.5.3":
version "4.5.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-system-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"kbn:bootstrap": "yarn build"
},
"devDependencies": {
"@types/jest": "^22.2.2",
"@types/jest": "^23.3.1",
"typescript": "^2.9.2"
}
}
6 changes: 3 additions & 3 deletions packages/kbn-system-loader/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# yarn lockfile v1


"@types/jest@^22.2.2":
version "22.2.2"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-22.2.2.tgz#afe5dacbd00d65325f52da0ed3e76e259629ac9d"
"@types/jest@^23.3.1":
version "23.3.1"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.1.tgz#a4319aedb071d478e6f407d1c4578ec8156829cf"

typescript@^2.9.2:
version "2.9.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Array [
"starting legacy service",
],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
},
"error": [MockFunction],
"fatal": [MockFunction],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ exports[`Inspector Data View component should render empty state 1`] = `
>
<EuiEmptyPrompt
body={
<UNDEFINED>
<React.Fragment>
<p>
The element did not provide any data.
</p>
</UNDEFINED>
</React.Fragment>
}
iconColor="subdued"
title={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ exports[`after fetch renders call to action when no dashboards exist 1`] = `
</EuiButton>
}
body={
<UNDEFINED>
<React.Fragment>
<p>
You can combine data views from any Kibana app into one dashboard and see everything in one place.
</p>
Expand All @@ -227,7 +227,7 @@ exports[`after fetch renders call to action when no dashboards exist 1`] = `
</EuiLink>
to take a test drive.
</p>
</UNDEFINED>
</React.Fragment>
}
iconColor="subdued"
iconType="dashboardApp"
Expand Down
Loading

0 comments on commit 7e94ecc

Please sign in to comment.