Skip to content

Commit

Permalink
Upgrade to Jest 27 (#139335)
Browse files Browse the repository at this point in the history
* Upgrade to Jest 27

* fix test
  • Loading branch information
jbudz authored Oct 25, 2022
1 parent 94fe004 commit be432c0
Show file tree
Hide file tree
Showing 226 changed files with 973 additions and 953 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ npm-debug.log*
## @cypress/snapshot from apm plugin
/snapshots.js

# transpiled cypress config
x-pack/plugins/fleet/cypress.config.d.ts
x-pack/plugins/fleet/cypress.config.js
x-pack/plugins/osquery/cypress.config.d.ts
x-pack/plugins/osquery/cypress.config.js

# release notes script output
report.csv
report.asciidoc
Expand Down
47 changes: 23 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@
"he": "^1.2.0",
"history": "^4.9.0",
"hjson": "3.2.1",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^5.0.0",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"i18n-iso-countries": "^4.3.1",
"icalendar": "0.7.1",
"immer": "^9.0.15",
Expand Down Expand Up @@ -705,9 +705,9 @@
"@emotion/jest": "^11.10.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@istanbuljs/schema": "^0.1.2",
"@jest/console": "^26.6.2",
"@jest/reporters": "^26.6.2",
"@jest/types": "^26",
"@jest/console": "^27.5.1",
"@jest/reporters": "^27.5.1",
"@jest/types": "^27",
"@kbn/ambient-storybook-types": "link:bazel-bin/packages/kbn-ambient-storybook-types",
"@kbn/ambient-ui-types": "link:bazel-bin/packages/kbn-ambient-ui-types",
"@kbn/apm-synthtrace": "link:bazel-bin/packages/kbn-apm-synthtrace",
Expand Down Expand Up @@ -790,10 +790,10 @@
"@storybook/react-docgen-typescript-plugin": "^1.0.1",
"@storybook/testing-react": "^1.3.0",
"@storybook/theming": "^6.5.12",
"@testing-library/dom": "^8.12.0",
"@testing-library/jest-dom": "^5.16.3",
"@testing-library/dom": "^8.17.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^13.5.0",
"@types/apidoc": "^0.22.3",
"@types/archiver": "^5.3.1",
Expand Down Expand Up @@ -843,10 +843,9 @@
"@types/history": "^4.7.9",
"@types/hjson": "^2.4.2",
"@types/http-proxy": "^1.17.4",
"@types/http-proxy-agent": "^2.0.2",
"@types/inquirer": "^7.3.1",
"@types/intl-relativeformat": "^2.1.0",
"@types/jest": "^26.0.22",
"@types/jest": "^27.4.1",
"@types/jest-axe": "^3.5.3",
"@types/joi": "^17.2.3",
"@types/jquery": "^3.3.31",
Expand Down Expand Up @@ -1297,7 +1296,7 @@
"argsplit": "^1.0.5",
"autoprefixer": "^10.4.7",
"axe-core": "^4.0.2",
"babel-jest": "^26.6.3",
"babel-jest": "^27.5.1",
"babel-loader": "^8.2.5",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-istanbul": "^6.1.1",
Expand Down Expand Up @@ -1332,7 +1331,7 @@
"dpdm": "3.5.0",
"ejs": "^3.1.8",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.1",
"enzyme-to-json": "^3.6.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-module-utils": "^2.6.2",
Expand Down Expand Up @@ -1370,21 +1369,21 @@
"html-loader": "^1.3.2",
"http-proxy": "^1.18.1",
"is-path-inside": "^3.0.2",
"jest": "^26.6.3",
"jest": "^27.5.1",
"jest-axe": "^5.0.0",
"jest-canvas-mock": "^2.3.1",
"jest-circus": "^26.6.3",
"jest-cli": "^26.6.3",
"jest-config": "^26",
"jest-diff": "^26.6.2",
"jest-environment-jsdom": "^26.6.2",
"jest-mock": "^26.6.2",
"jest-canvas-mock": "^2.4.0",
"jest-cli": "^27.5.1",
"jest-config": "^27.5.1",
"jest-diff": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jest-matcher-utils": "^27.5.1",
"jest-mock": "^27.5.1",
"jest-raw-loader": "^1.0.1",
"jest-runtime": "^26",
"jest-runtime": "^27.5.1",
"jest-silent-reporter": "^0.5.0",
"jest-snapshot": "^26.6.2",
"jest-specific-snapshot": "^4.0.0",
"jest-styled-components": "^7.0.3",
"jest-snapshot": "^27.5.1",
"jest-specific-snapshot": "^5.0.0",
"jest-styled-components": "7.0.3",
"jsdom": "^16.4.0",
"json-schema-typed": "^8.0.1",
"json5": "^1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('AnalyticsClient', () => {
let logger: MockedLogger;

beforeEach(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
logger = loggerMock.create();
analyticsClient = new AnalyticsClient({
logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ElasticV3BrowserShipper', () => {
let fetchMock: jest.Mock;

beforeEach(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');

fetchMock = jest.fn().mockResolvedValue({
status: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('ElasticV3ServerShipper', () => {
const setLastBatchSent = (ms: number) => (shipper['lastBatchSent'] = ms);

beforeEach(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');

shipper = new ElasticV3ServerShipper(
{ version: '1.2.3', channelName: 'test-channel', debug: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const requiredProps: TableListViewProps = {

describe('TableListView', () => {
beforeAll(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('MetaRewritePolicy', () => {
"error": Object {},
"tags": Array [
"0",
undefined,
,
],
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('MetricsService', () => {
let metricsService: MetricsService;

beforeEach(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');

const configService = configServiceMock.create({
atPath: { interval: moment.duration(testInterval) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('OverlayBannersService', () => {
});

it('dismisses banner after timeout', async () => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
startService('testing banner!');
expect(banners.remove).not.toHaveBeenCalled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Side Public License, v 1.
*/

import { setImmediate } from 'timers/promises';
import { join } from 'path';
import loadJsonFile from 'load-json-file';
import { setImmediate } from 'timers/promises';

import {
clientProviderInstanceMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Cache } from './cache';

describe('Cache', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ describe('ui settings', () => {
describe('caching', () => {
describe('read operations cache user config', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
});

afterEach(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-apm-synthtrace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ TYPES_DEPS = [
"@npm//p-limit",
"@npm//@types/node-fetch",
"@npm//@types/semver",
"@npm//@types/yargs",
]

jsts_transpiler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('palette panel', () => {
dataBounds: { min: 0, max: 100 },
};

jest.useFakeTimers();
jest.useFakeTimers('legacy');
});

function changePaletteIn(instance: ReactWrapper, newPaletteName: string) {
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-dev-cli-runner/src/run_with_commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { ToolingLog, ToolingLogCollectingWriter } from '@kbn/tooling-log';
import { ProcRunner } from '@kbn/dev-proc-runner';
jest.mock('./metrics');

import { FlagsReader } from './flags_reader';
import { RunWithCommands } from './run_with_commands';
Expand Down Expand Up @@ -48,7 +49,7 @@ it('extends the context using extendContext()', async () => {
flagsReader: expect.any(FlagsReader),
addCleanupTask: expect.any(Function),
procRunner: expect.any(ProcRunner),
statsMeta: expect.any(Map),
statsMeta: undefined,
extraContext: true,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/diff_strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import jestDiff from 'jest-diff';
import { diff as jestDiff } from 'jest-diff';
import stripAnsi from 'strip-ansi';
import Chalk from 'chalk';

Expand Down
7 changes: 3 additions & 4 deletions packages/kbn-monaco/src/painless/diagnostics_adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ const getMockWorker = async () => {
} as any;
};

function flushPromises() {
return new Promise((resolve) => setImmediate(resolve));
}
const flushPromises = () =>
new Promise((resolve) => jest.requireActual('timers').setImmediate(resolve));

describe('Painless DiagnosticAdapter', () => {
let diagnosticAdapter: DiagnosticsAdapter;
Expand All @@ -35,7 +34,7 @@ describe('Painless DiagnosticAdapter', () => {
let validation: LangValidation;

beforeAll(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
});

afterAll(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-optimizer/src/common/rxjs_helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fakeSchedulers } from 'rxjs-marbles/jest';

import { pipeClosure, debounceTimeBuffer, maybeMap, maybe } from './rxjs_helpers';

jest.useFakeTimers();
jest.useFakeTimers('legacy');

describe('pipeClosure()', () => {
it('calls closure on each subscription to setup unique state', async () => {
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('maybeMap()', () => {

describe('debounceTimeBuffer()', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const bundleCacheEvent$ = Rx.from(BUNDLES).pipe(
);

beforeEach(async () => {
jest.useFakeTimers();
jest.useFakeTimers('legacy');
});

afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jest.mock('@kbn/synthetic-package-map', () => {
jest.mock('../common/hashes', () => {
return {
Hashes: class MockHashes {
static ofFiles = jest.fn(() => {
static ofFiles: any = jest.fn(() => {
return new MockHashes();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-react-field/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ TYPES_DEPS = [
"@npm//@elastic/eui",
"@npm//@types/classnames",
"@npm//@types/jest",
"@npm//@types/prop-types",
"@npm//@types/node",
"@npm//@types/prop-types",
"@npm//@types/react",
]

Expand Down
3 changes: 0 additions & 3 deletions packages/kbn-test/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ module.exports = {
`integration_tests/`,
],

// This option allows use of a custom test runner
testRunner: 'jest-circus/runner',

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.(js|tsx?)$': '<rootDir>/node_modules/@kbn/test/target_node/src/jest/babel_transform.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
addSerializer,
} from 'jest-snapshot';
import path from 'path';
import prettier from 'prettier';
import babelTraverse from '@babel/traverse';
import { once } from 'lodash';
import { Lifecycle } from '../lifecycle';
import { Suite, Test } from '../../fake_mocha_types';
Expand Down Expand Up @@ -161,8 +159,8 @@ function getSnapshotState(file: string, updateSnapshot: SnapshotUpdateState) {
path.join(dirname + `/__snapshots__/` + filename.replace(path.extname(filename), '.snap')),
{
updateSnapshot,
getPrettier: () => prettier,
getBabelTraverse: () => babelTraverse,
prettierPath: require.resolve('prettier'),
snapshotFormat: { escapeString: true, printBasicPrototype: true },
}
);

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-test/src/jest/babel_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const babelJest = require('babel-jest');

module.exports = babelJest.createTransformer({
module.exports = babelJest.default.createTransformer({
presets: [
[
require.resolve('@kbn/babel-preset/node_preset'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import { readConfig } from 'jest-config';
import { createContext } from 'jest-runtime';
import { SearchSource } from 'jest';
import Runtime from 'jest-runtime';
import { asyncMapWithLimit } from '@kbn/std';

const EMPTY_ARGV = {
Expand All @@ -34,7 +34,7 @@ export async function getTestsForConfigPaths(
return await asyncMapWithLimit(configPaths, 60, async (path) => {
const config = await readConfig(EMPTY_ARGV, path);
const searchSource = new SearchSource(
await createContext(config.projectConfig, {
await Runtime.createContext(config.projectConfig, {
maxWorkers: 1,
watchman: false,
watch: false,
Expand Down
Loading

0 comments on commit be432c0

Please sign in to comment.