Skip to content
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
50 changes: 34 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,27 @@
},
"resolutions": {
"**/@babel/runtime": "^7.16.3",
"**/@jest/console": "29.3.1",
"**/@jest/reporters": "29.3.1",
"**/@types/node": "16.11.7",
"**/@types/react-dom": "^16.9.8",
"**/babel-jest": "29.3.1",
"**/chokidar": "^3.4.3",
"**/expect": "29.3.1",
"**/globule/minimatch": "^3.1.2",
"**/hoist-non-react-statics": "^3.3.2",
"**/html-minifier/uglify-js": "^3.14.3",
"**/isomorphic-fetch/node-fetch": "^2.6.7",
"**/istanbul-instrumenter-loader/schema-utils": "1.0.0",
"**/jest": "29.3.1",
"**/jest-cli": "29.3.1",
"**/jest-config": "29.3.1",
"**/jest-diff": "29.3.1",
"**/jest-environment-jsdom": "29.3.1",
"**/jest-matcher-utils": "29.3.1",
"**/jest-mock": "29.3.1",
"**/jest-runtime": "29.3.1",
"**/jest-snapshot": "29.3.1",
"**/json-schema": "^0.4.0",
"**/pdfkit/crypto-js": "4.0.0",
"**/react-syntax-highlighter": "^15.3.1",
Expand Down Expand Up @@ -440,8 +454,9 @@
"@emotion/babel-preset-css-prop": "^11.2.0",
"@emotion/jest": "^11.3.0",
"@istanbuljs/schema": "^0.1.2",
"@jest/console": "^27.5.1",
"@jest/reporters": "^27.5.1",
"@jest/console": "29.3.1",
"@jest/reporters": "29.3.1",
"@jest/types": "29.3.1",
"@kbn/babel-code-parser": "link:bazel-bin/packages/kbn-babel-code-parser",
"@kbn/babel-preset": "link:bazel-bin/packages/kbn-babel-preset",
"@kbn/babel-register": "link:bazel-bin/packages/kbn-babel-register",
Expand Down Expand Up @@ -484,9 +499,9 @@
"@storybook/react": "^6.3.12",
"@storybook/testing-react": "^0.0.22",
"@storybook/theming": "^6.3.12",
"@testing-library/dom": "^7.30.3",
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^5.1.1",
"@testing-library/user-event": "^13.1.1",
"@types/archiver": "^5.1.0",
Expand Down Expand Up @@ -541,7 +556,7 @@
"@types/http-proxy": "^1.17.4",
"@types/inquirer": "^7.3.1",
"@types/intl-relativeformat": "^2.1.0",
"@types/jest": "^27.4.1",
"@types/jest": "29.2.0",
"@types/jest-specific-snapshot": "^0.5.5",
"@types/jest-when": "^2.7.2",
"@types/jquery": "^3.3.31",
Expand Down Expand Up @@ -617,7 +632,7 @@
"@types/tar": "^4.0.5",
"@types/tar-fs": "^1.16.1",
"@types/tempy": "^0.2.0",
"@types/testing-library__jest-dom": "^5.9.5",
"@types/testing-library__jest-dom": "5.14.5",
"@types/testing-library__react-hooks": "^4.0.0",
"@types/tinycolor2": "^1.4.1",
"@types/tough-cookie": "^4.0.2",
Expand Down Expand Up @@ -648,7 +663,7 @@
"argsplit": "^1.0.5",
"autoprefixer": "^10.4.7",
"axe-core": "^4.0.2",
"babel-jest": "^27.5.1",
"babel-jest": "29.3.1",
"babel-loader": "^8.2.2",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-istanbul": "^6.1.1",
Expand Down Expand Up @@ -730,18 +745,21 @@
"is-glob": "^4.0.1",
"is-path-inside": "^3.0.2",
"istanbul-instrumenter-loader": "^3.0.1",
"jest": "^27.5.1",
"jest": "29.3.1",
"jest-canvas-mock": "^2.3.1",
"jest-cli": "^27.5.1",
"jest-diff": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jest-cli": "29.3.1",
"jest-config": "29.3.1",
"jest-diff": "29.3.1",
"jest-environment-jsdom": "29.3.1",
"jest-environment-jsdom-thirteen": "^1.0.1",
"jest-raw-loader": "^1.0.1",
"jest-matcher-utils": "29.3.1",
"jest-mock": "29.3.1",
"jest-runtime": "29.3.1",
"jest-silent-reporter": "^0.5.0",
"jest-snapshot": "^27.5.1",
"jest-snapshot": "29.3.1",
"jest-specific-snapshot": "^5.0.0",
"jest-styled-components": "7.0.3",
"jest-when": "^3.2.1",
"jest-when": "3.4.1",
"jsdom": "13.1.0",
"json-schema-typed": "^8.0.1",
"json5": "^2.2.3",
Expand Down Expand Up @@ -778,7 +796,7 @@
"postcss-loader": "^4.2.0",
"postcss-prefix-selector": "^1.16.0",
"prettier": "^2.7.1",
"pretty-format": "^27.5.1",
"pretty-format": "29.3.1",
"pretty-ms": "^5.0.0",
"proxy": "^2.1.1",
"q": "^1.5.1",
Expand Down Expand Up @@ -810,7 +828,7 @@
"tough-cookie": "^4.1.2",
"ts-loader": "^7.0.5",
"ts-morph": "^11.0.0",
"tsd": "^0.13.1",
"tsd": "^0.20.0",
"typescript": "4.5.3",
"unlazy-loader": "^0.1.3",
"url-loader": "^2.2.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/elastic-datemath/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('dateMath', function () {
let now;

beforeEach(function () {
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(unix);
now = moment();
mmnt = moment(anchor);
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('dateMath', function () {
let anchored;

beforeEach(function () {
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(unix);
now = moment();
anchored = moment(anchor);
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('dateMath', function () {
let anchored;

beforeEach(function () {
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(unix);
now = moment();
anchored = moment(anchor);
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('dateMath', function () {
let anchored;

beforeEach(function () {
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(unix);
now = moment();
anchored = moment(anchor);
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('dateMath', function () {
let anchored;

beforeEach(function () {
jest.useFakeTimers('modern');
jest.useFakeTimers();
jest.setSystemTime(unix);
now = moment();
anchored = moment(anchor);
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-cli-dev-mode/src/dev_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { extendedEnvSerializer } from './test_helpers';
import { DevServer, Options } from './dev_server';
import { TestLog } from './log';

jest.useFakeTimers('modern');
jest.useFakeTimers();

class MockProc extends EventEmitter {
public readonly signalsSent: string[] = [];
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-i18n/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-i18n'],
testRunner: 'jasmine2',
};
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('LogRotator', () => {
});

it('rotates log file service correctly fallback to usePolling true after defined timeout', async () => {
jest.useFakeTimers('legacy');
jest.useFakeTimers({ legacyFakeTimers: true });
writeBytesToFile(testFilePath, 1);

const logRotator = new LogRotator(createLogRotatorConfig(testFilePath), mockServer);
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 @@ -12,7 +12,7 @@ import { lastValueFrom } from '@kbn/std';

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

jest.useFakeTimers('legacy');
jest.useFakeTimers({ legacyFakeTimers: true });

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

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

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('legacy');
jest.useFakeTimers({ legacyFakeTimers: true });
});

afterEach(async () => {
Expand Down
11 changes: 6 additions & 5 deletions packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ jest.mock('./focus_bundles');
jest.mock('../limits.ts');

jest.mock('os', () => {
const realOs = jest.requireActual('os');
jest.spyOn(realOs, 'cpus').mockImplementation(() => {
return ['foo'] as any;
});
return realOs;
return {
...jest.requireActual('os'),
cpus() {
return ['foo'] as any;
},
};
});

import Path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-pm/src/utils/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe.skip('#waitUntilWatchIsReady', () => {
let buildOutputStream: EventEmitter;
let completionHintPromise: Promise<string>;
beforeEach(() => {
jest.useFakeTimers('legacy');
jest.useFakeTimers({ legacyFakeTimers: true });

buildOutputStream = new EventEmitter();
completionHintPromise = waitUntilWatchIsReady(buildOutputStream, {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ TYPES_DEPS = [
"@npm//@elastic/elasticsearch",
"@npm//@jest/console",
"@npm//@jest/reporters",
"@npm//@jest/types",
"@npm//axios",
"@npm//elastic-apm-node",
"@npm//del",
Expand Down
11 changes: 9 additions & 2 deletions packages/kbn-test/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

/** @typedef {import("@jest/types").Config.InitialOptions} JestConfig */
/** @type {JestConfig} */
module.exports = {
// The directory where Jest should output its coverage files
coverageDirectory: '<rootDir>/target/kibana-coverage/jest',
Expand Down Expand Up @@ -77,6 +79,11 @@ module.exports = {
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/react_testing_library.js',
],

snapshotFormat: {
escapeString: true,
printBasicPrototype: true,
},

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
snapshotSerializers: [
'<rootDir>/src/plugins/kibana_react/public/util/test_helpers/react_mount_serializer.ts',
Expand All @@ -100,8 +107,8 @@ module.exports = {
// A map from regular expressions to paths to transformers
transform: {
'^.+\\.(js|tsx?)$': '<rootDir>/node_modules/@kbn/test/target_node/jest/babel_transform.js',
'^.+\\.txt?$': 'jest-raw-loader',
'^.+\\.html?$': 'jest-raw-loader',
'^.+\\.txt?$': '<rootDir>/node_modules/@kbn/test/target_node/jest/raw_transform.js',
'^.+\\.html?$': '<rootDir>/node_modules/@kbn/test/target_node/jest/raw_transform.js',
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-test/jest_integration/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

const preset = require('../jest-preset');

/** @typedef {import("@jest/types").Config.InitialOptions} JestConfig */
/** @type {JestConfig} */
module.exports = {
...preset,
testMatch: ['**/integration_tests**/*.test.{js,mjs,ts,tsx}'],
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-test/jest_node/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

const preset = require('../jest-preset');

/** @typedef {import("@jest/types").Config.InitialOptions} JestConfig */
/** @type {JestConfig} */
module.exports = {
...preset,
testEnvironment: 'node',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ export function decorateSnapshotUi({
function getSnapshotState(file: string, updateSnapshot: SnapshotUpdateState) {
const dirname = path.dirname(file);
const filename = path.basename(file);
const rootDir = path.join(dirname + `/__snapshots__/`);

const snapshotState = new SnapshotState(
path.join(dirname + `/__snapshots__/` + filename.replace(path.extname(filename), '.snap')),
path.join(rootDir, filename.replace(path.extname(filename), '.snap')),
{
updateSnapshot,
prettierPath: require.resolve('prettier'),
snapshotFormat: { escapeString: true, printBasicPrototype: true },
rootDir,
}
);

Expand Down Expand Up @@ -203,7 +205,7 @@ export function expectSnapshot(received: any) {

function expectToMatchSnapshot(snapshotContext: SnapshotContext, received: any) {
const matcher = toMatchSnapshot.bind(snapshotContext as any);
const result = matcher(received);
const result = matcher(received) as any;

if (!result.pass) {
throw new Error(result.message());
Expand All @@ -217,7 +219,7 @@ function expectToMatchInlineSnapshot(
) {
const matcher = toMatchInlineSnapshot.bind(snapshotContext as any);

const result = arguments.length === 2 ? matcher(received) : matcher(received, _actual);
const result = (arguments.length === 2 ? matcher(received) : matcher(received, _actual)) as any;

if (!result.pass) {
throw new Error(result.message());
Expand Down
15 changes: 15 additions & 0 deletions packages/kbn-test/src/jest/raw_transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
process(sourceText) {
return {
code: `module.exports = ${JSON.stringify(sourceText)}`,
};
},
};
4 changes: 2 additions & 2 deletions packages/kbn-test/src/jest/utils/testbed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ export const setup = registerTestBed<TestSubjects>(MyComponent);

In order to prevent flakiness in component integration tests, please consider the following best practices:

- **Use** `jest.useFakeTimers('legacy')`.
- **Use** `jest.useFakeTimers({ legacyFakeTimers: true })`.

The code under a test might be using `setTimeout()` calls. This is bad for deterministic tests. In order to avoid it, we need to use mocked timers from jest. For that we declare at the top of each component integration test the following:
```js
beforeAll(() => {
jest.useFakeTimers('legacy');
jest.useFakeTimers({ legacyFakeTimers: true });
});
afterAll(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-typed-react-router-config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ RUNTIME_DEPS = [
"@npm//utility-types",
"@npm//io-ts",
"@npm//query-string",
"@npm//react",
"@npm//react-router-config",
"@npm//react-router-dom",
]
Expand All @@ -43,6 +44,7 @@ TYPES_DEPS = [
"@npm//@types/jest",
"@npm//@types/history",
"@npm//@types/node",
"@npm//@types/react",
"@npm//@types/react-router-config",
"@npm//@types/react-router-dom",
]
Expand Down
1 change: 0 additions & 1 deletion src/core/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/src/core'],
testRunner: 'jasmine2',
};
Loading