kibana/packages/kbn-test/jest-preset.js
Dario Gieselaar 764c93f5ba
[8.10] [Observability AI Assistant] More specific error handling (#165068) (#165188)
# Backport

This will backport the following commits from `main` to `8.10`:
- [[Observability AI Assistant] More specific error handling
(#165068)](https://github.com/elastic/kibana/pull/165068)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dario
Gieselaar","email":"dario.gieselaar@elastic.co"},"sourceCommit":{"committedDate":"2023-08-30T07:34:02Z","message":"[Observability
AI Assistant] More specific error handling (#165068)\n\nImplements more
specific error handling, in addition to a bug fix w/ the\r\nLens
function where it was not rendering outside of the Observability
AI\r\nAssistant plugin's context, and validation of the parameters
before\r\nexecuting the function.\r\n\r\nAdditionally:\r\n- improves
recall function\r\n- filter alerts and services by alert/health
status\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c5c6574592ee2b88f48454b8ad6d23229bdafab2","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:APM","release_note:skip","v8.10.0","v8.11.0"],"number":165068,"url":"https://github.com/elastic/kibana/pull/165068","mergeCommit":{"message":"[Observability
AI Assistant] More specific error handling (#165068)\n\nImplements more
specific error handling, in addition to a bug fix w/ the\r\nLens
function where it was not rendering outside of the Observability
AI\r\nAssistant plugin's context, and validation of the parameters
before\r\nexecuting the function.\r\n\r\nAdditionally:\r\n- improves
recall function\r\n- filter alerts and services by alert/health
status\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c5c6574592ee2b88f48454b8ad6d23229bdafab2"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/165068","number":165068,"mergeCommit":{"message":"[Observability
AI Assistant] More specific error handling (#165068)\n\nImplements more
specific error handling, in addition to a bug fix w/ the\r\nLens
function where it was not rendering outside of the Observability
AI\r\nAssistant plugin's context, and validation of the parameters
before\r\nexecuting the function.\r\n\r\nAdditionally:\r\n- improves
recall function\r\n- filter alerts and services by alert/health
status\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c5c6574592ee2b88f48454b8ad6d23229bdafab2"}}]}]
BACKPORT-->
2023-08-30 10:51:45 +02:00

125 lines
5 KiB
JavaScript

/*
* 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.
*/
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
/** @type {import("@jest/types").Config.InitialOptions} */
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', 'jest\\.config\\.js'],
// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: !!process.env.CODE_COVERAGE
? [['json', { file: 'jest.json' }]]
: ['html', 'text'],
// An array of file extensions your modules use
moduleFileExtensions: ['ts', 'tsx', 'js', 'mjs', 'json', 'node'],
moduleNameMapper: {
// do not use these, they're so slow. We have a custom resolver that can handle resolving different types of requests.
},
// 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',
[
'<rootDir>/packages/kbn-test/src/jest/junit_reporter',
{
rootDirectory: '.',
},
],
...(process.env.TEST_GROUP_TYPE_UNIT
? [
[
'<rootDir>/packages/kbn-test/src/jest/ci_stats_jest_reporter.ts',
{
testGroupType: process.env.TEST_GROUP_TYPE_UNIT,
},
],
]
: []),
],
// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: [
'<rootDir>/src/setup_node_env/polyfill.ts',
'<rootDir>/packages/kbn-test/src/jest/setup/polyfills.jsdom.js',
'<rootDir>/packages/kbn-test/src/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/src/jest/setup/setup_test.js',
'<rootDir>/packages/kbn-test/src/jest/setup/mocks.moment_timezone.js',
'<rootDir>/packages/kbn-test/src/jest/setup/mocks.eui.js',
'<rootDir>/packages/kbn-test/src/jest/setup/react_testing_library.js',
process.env.CI ? '<rootDir>/packages/kbn-test/src/jest/setup/disable_console_logs.js' : [],
].flat(),
snapshotFormat: {
escapeString: true,
printBasicPrototype: true,
},
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
snapshotSerializers: [
'<rootDir>/packages/react/kibana_mount/test_helpers/react_mount_serializer.ts',
'enzyme-to-json/serializer',
'<rootDir>/packages/kbn-test/src/jest/setup/emotion.js',
],
// The test environment that will be used for testing
testEnvironment: 'jest-environment-jsdom',
// 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/',
'<rootDir>/packages/kbn-pm/dist/',
`integration_tests/`,
],
// A map from regular expressions to paths to transformers
transform: {
'^.+\\.(js|tsx?)$': '<rootDir>/packages/kbn-test/src/jest/transforms/babel.js',
'^.+\\.(txt|html)?$': '<rootDir>/packages/kbn-test/src/jest/transforms/raw.js',
'^.+\\.peggy?$': '<rootDir>/packages/kbn-test/src/jest/transforms/peggy.js',
},
// 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 and react-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(?![\\/\\\\](byte-size|monaco-editor|monaco-yaml|vscode-languageserver-types|react-monaco-editor|d3-interpolate|d3-color|@cfworker))[/\\\\].+\\.js$',
'packages/kbn-pm/dist/index.js',
],
// An array of regexp pattern strings that are matched against all source file paths, matched files to include/exclude for code coverage
collectCoverageFrom: [
'**/*.{js,mjs,jsx,ts,tsx}',
'!**/{__test__,__snapshots__,__examples__,*mock*,tests,test_helpers,integration_tests,types}/**/*',
'!**/*mock*.{ts,tsx}',
'!**/*.test.{ts,tsx}',
'!**/*.d.ts',
'!**/index.{js,ts,tsx}',
],
watchPathIgnorePatterns: ['.*/__tmp__/.*'],
resolver: '<rootDir>/packages/kbn-test/src/jest/resolver.js',
};