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

chore(NA): introduce preset for jest-integration tests on @kbn/test #105144

Merged
merged 8 commits into from
Jul 14, 2021
18 changes: 1 addition & 17 deletions jest.config.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@
* Side Public License, v 1.
*/

const preset = require('@kbn/test/jest-preset');

module.exports = {
preset: '@kbn/test',
preset: '@kbn/test/jest_integration',
rootDir: '.',
roots: ['<rootDir>/src', '<rootDir>/packages'],
testMatch: ['**/integration_tests**/*.test.{js,mjs,ts,tsx}'],
testPathIgnorePatterns: preset.testPathIgnorePatterns.filter(
(pattern) => !pattern.includes('integration_tests')
),
setupFilesAfterEnv: [
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/after_env.integration.js',
],
reporters: [
'default',
['@kbn/test/target_node/jest/junit_reporter', { reportName: 'Jest Integration Tests' }],
],
coverageReporters: !!process.env.CI
? [['json', { file: 'jest-integration.json' }]]
: ['html', 'text'],
};
1 change: 1 addition & 0 deletions packages/kbn-test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ filegroup(
NPM_MODULE_EXTRA_FILES = [
"jest/package.json",
"jest-preset.js",
"jest_integration/jest-preset.js",
"jest.config.js",
"README.md",
"package.json",
Expand Down
27 changes: 27 additions & 0 deletions packages/kbn-test/jest_integration/jest-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
*/

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

module.exports = {
...preset,
testMatch: ['**/integration_tests**/*.test.{js,mjs,ts,tsx}'],
testPathIgnorePatterns: preset.testPathIgnorePatterns.filter(
(pattern) => !pattern.includes('integration_tests')
),
setupFilesAfterEnv: [
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/after_env.integration.js',
],
reporters: [
'default',
['@kbn/test/target_node/jest/junit_reporter', { reportName: 'Jest Integration Tests' }],
],
coverageReporters: !!process.env.CI
? [['json', { file: 'jest-integration.json' }]]
: ['html', 'text'],
};
20 changes: 10 additions & 10 deletions src/core/server/legacy/integration_tests/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('logging service', () => {
const loggedString = getPlatformLogsFromMock(mockConsoleLog);
expect(loggedString).toMatchInlineSnapshot(`
Array [
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][INFO ][test-file] handled by NP",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][INFO ][test-file] handled by NP",
mistic marked this conversation as resolved.
Show resolved Hide resolved
]
`);
});
Expand Down Expand Up @@ -131,9 +131,9 @@ describe('logging service', () => {

expect(getPlatformLogsFromMock(mockConsoleLog)).toMatchInlineSnapshot(`
Array [
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][INFO ][test-file] info",
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][WARN ][test-file] warn",
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][ERROR][test-file] error",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][INFO ][test-file] info",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][WARN ][test-file] warn",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][ERROR][test-file] error",
]
`);

Expand Down Expand Up @@ -162,9 +162,9 @@ describe('logging service', () => {

expect(getPlatformLogsFromMock(mockConsoleLog)).toMatchInlineSnapshot(`
Array [
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][INFO ][test-file] info",
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][WARN ][test-file] warn",
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][ERROR][test-file] error",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][INFO ][test-file] info",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][WARN ][test-file] warn",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][ERROR][test-file] error",
]
`);

Expand Down Expand Up @@ -199,9 +199,9 @@ describe('logging service', () => {

expect(getPlatformLogsFromMock(mockConsoleLog)).toMatchInlineSnapshot(`
Array [
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][INFO ][test-file] info",
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][WARN ][test-file] warn",
"[xxxx-xx-xxTxx:xx:xx.xxx-xx:xx][ERROR][test-file] error",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][INFO ][test-file] info",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][WARN ][test-file] warn",
"[xxxx-xx-xxTxx:xx:xx.xxx+xx:xx][ERROR][test-file] error",
]
`);

Expand Down
1 change: 1 addition & 0 deletions src/dev/precommit_hook/casing_check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const IGNORE_FILE_GLOBS = [
'vars/*',
'.ci/pipeline-library/**/*',
'packages/kbn-test/jest-preset.js',
'packages/kbn-test/jest_integration/jest-preset.js',
Copy link
Contributor

@mshustov mshustov Jul 12, 2021

Choose a reason for hiding this comment

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

Why can't we use jest_preset? Is it a limitation of jest?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mshustov jest doesn't allow us to configurate wether to make or not the workers to follow symlinks (except in places where we can use a custom resolver, so mostly within test code). Therefore we discover that if we keep the reporters config hold inside the @kbn/test package other than overridden outside, we are able to keep the preserve symlink option set in the parent process and correctly discover the output folder for the reports on the CI

Copy link
Contributor

Choose a reason for hiding this comment

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

I think he's asking specifically about the use of kebab-case instead of camel_case

Copy link
Member Author

Choose a reason for hiding this comment

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

🤦 thanks @spalger , reading it a second time make that clear. Yeah it is a jest limitation, it will always look for a jest-preset.* file. More info at https://jestjs.io/docs/configuration#preset-string

'test/package/Vagrantfile',
'**/test/**/fixtures/**/*',

Expand Down