-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Consolidates Jest configuration files and scripts #82671
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
360843e
Consolidates Jest configuration
cee11cc
Removes rest of x-pack/test_utils
d331994
Merge remote-tracking branch 'upstream/master' into single-jest-config
9f0e49d
Adds testbed README
47c6d4c
Revert newline
e02d309
Revert newline
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
const { resolve } = require('path'); | ||
|
||
module.exports = { | ||
// The directory where Jest should output its coverage files | ||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest', | ||
|
||
// An array of regexp pattern strings used to skip coverage collection | ||
coveragePathIgnorePatterns: ['/node_modules/', '.*\\.d\\.ts'], | ||
|
||
// A list of reporter names that Jest uses when writing coverage reports | ||
coverageReporters: !!process.env.CODE_COVERAGE ? ['json'] : ['html', 'text'], | ||
|
||
// An array of file extensions your modules use | ||
moduleFileExtensions: ['js', 'mjs', 'json', 'ts', 'tsx', 'node'], | ||
|
||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module | ||
moduleNameMapper: { | ||
'@elastic/eui/lib/(.*)?': '<rootDir>/node_modules/@elastic/eui/test-env/$1', | ||
'@elastic/eui$': '<rootDir>/node_modules/@elastic/eui/test-env', | ||
'\\.module.(css|scss)$': '<rootDir>/packages/kbn-test/target/jest/mocks/css_module_mock.js', | ||
'\\.(css|less|scss)$': '<rootDir>/packages/kbn-test/target/jest/mocks/style_mock.js', | ||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': | ||
'<rootDir>/packages/kbn-test/target/jest/mocks/file_mock.js', | ||
'\\.ace\\.worker.js$': '<rootDir>/packages/kbn-test/target/jest/mocks/worker_module_mock.js', | ||
'\\.editor\\.worker.js$': '<rootDir>/packages/kbn-test/target/jest/mocks/worker_module_mock.js', | ||
'^(!!)?file-loader!': '<rootDir>/packages/kbn-test/target/jest/mocks/file_mock.js', | ||
'^fixtures/(.*)': '<rootDir>/src/fixtures/$1', | ||
'^src/core/(.*)': '<rootDir>/src/core/$1', | ||
'^src/legacy/(.*)': '<rootDir>/src/legacy/$1', | ||
'^src/plugins/(.*)': '<rootDir>/src/plugins/$1', | ||
}, | ||
|
||
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader | ||
modulePathIgnorePatterns: ['__fixtures__/', 'target/'], | ||
|
||
// Use this configuration option to add custom reporters to Jest | ||
reporters: ['default', resolve(__dirname, './target/jest/junit_reporter')], | ||
|
||
// The paths to modules that run some code to configure or set up the testing environment before each test | ||
setupFiles: [ | ||
'<rootDir>/packages/kbn-test/target/jest/setup/babel_polyfill.js', | ||
'<rootDir>/packages/kbn-test/target/jest/setup/polyfills.js', | ||
'<rootDir>/packages/kbn-test/target/jest/setup/enzyme.js', | ||
], | ||
|
||
// A list of paths to modules that run some code to configure or set up the testing framework before each test | ||
setupFilesAfterEnv: [ | ||
'<rootDir>/packages/kbn-test/target/jest/setup/setup_test.js', | ||
'<rootDir>/packages/kbn-test/target/jest/setup/mocks.js', | ||
'<rootDir>/packages/kbn-test/target/jest/setup/react_testing_library.js', | ||
], | ||
|
||
// 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', | ||
'<rootDir>/node_modules/enzyme-to-json/serializer', | ||
], | ||
|
||
// The test environment that will be used for testing | ||
testEnvironment: 'jest-environment-jsdom-thirteen', | ||
|
||
// The glob patterns Jest uses to detect test files | ||
testMatch: ['**/*.test.{js,mjs,ts,tsx}'], | ||
|
||
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped | ||
testPathIgnorePatterns: [ | ||
'<rootDir>/packages/kbn-ui-framework/(dist|doc_site|generator-kui)/', | ||
'<rootDir>/packages/kbn-pm/dist/', | ||
`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>/packages/kbn-test/target/jest/babel_transform.js', | ||
'^.+\\.txt?$': 'jest-raw-loader', | ||
'^.+\\.html?$': 'jest-raw-loader', | ||
}, | ||
|
||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation | ||
transformIgnorePatterns: [ | ||
// ignore all node_modules except monaco-editor which requires babel transforms to handle dynamic import() | ||
// since ESM modules are not natively supported in Jest yet (https://github.com/facebook/jest/issues/4842) | ||
'[/\\\\]node_modules(?![\\/\\\\]monaco-editor)[/\\\\].+\\.js$', | ||
'packages/kbn-pm/dist/index.js', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "../target/jest", | ||
"types": "../target/types/jest/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
const { resolve } = require('path'); | ||
|
||
const del = require('del'); | ||
const supportsColor = require('supports-color'); | ||
const { run, withProcRunner } = require('@kbn/dev-utils'); | ||
|
||
const ROOT_DIR = resolve(__dirname, '..'); | ||
const BUILD_DIR = resolve(ROOT_DIR, 'target'); | ||
|
||
const padRight = (width, str) => | ||
str.length >= width ? str : `${str}${' '.repeat(width - str.length)}`; | ||
|
||
run( | ||
async ({ log, flags }) => { | ||
await withProcRunner(log, async (proc) => { | ||
log.info('Deleting old output'); | ||
await del(BUILD_DIR); | ||
|
||
const cwd = ROOT_DIR; | ||
const env = { ...process.env }; | ||
if (supportsColor.stdout) { | ||
env.FORCE_COLOR = 'true'; | ||
} | ||
|
||
log.info(`Starting babel and typescript${flags.watch ? ' in watch mode' : ''}`); | ||
await Promise.all([ | ||
proc.run(padRight(10, `babel`), { | ||
cmd: 'babel', | ||
args: [ | ||
'src', | ||
'--config-file', | ||
require.resolve('../babel.config.js'), | ||
'--out-dir', | ||
BUILD_DIR, | ||
'--extensions', | ||
'.ts,.js,.tsx', | ||
...(flags.watch ? ['--watch'] : ['--quiet']), | ||
...(!flags['source-maps'] || !!process.env.CODE_COVERAGE | ||
? [] | ||
: ['--source-maps', 'inline']), | ||
], | ||
wait: true, | ||
env, | ||
cwd, | ||
}), | ||
|
||
proc.run(padRight(10, 'tsc'), { | ||
cmd: 'tsc', | ||
args: [ | ||
...(flags.watch ? ['--watch', '--preserveWatchOutput', 'true'] : []), | ||
...(flags['source-maps'] ? ['--declarationMap', 'true'] : []), | ||
], | ||
wait: true, | ||
env, | ||
cwd, | ||
}), | ||
]); | ||
|
||
log.success('Complete'); | ||
}); | ||
}, | ||
{ | ||
description: 'Simple build tool for @kbn/i18n package', | ||
flags: { | ||
boolean: ['watch', 'source-maps'], | ||
help: ` | ||
--watch Run in watch mode | ||
--source-maps Include sourcemaps | ||
`, | ||
}, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please install the editorconfig plugin in your editor so that this doesn't keep getting flipped back in forth in every PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe we have come to a consensus on if we should have newlines or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I swapped it because the few I checked had trailing newlines, and I hate seeing the red notice in the Github UI. However, looks like we mostly don't use newlines so I will revert this one.
find packages -name "package.json" | xargs tail -n 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's not exactly enforced but the contributing guides says to install the editorconfig plugin and that config has a rule for package.json specifically (also npm/yarn don't add the extra newline IIRC) https://github.com/elastic/kibana/blob/master/.editorconfig#L11-L14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently there is an editorconfig plugin for eslint, so if we wanted to pass those files through eslint too we could, but that's a separate issue.