diff --git a/package.json b/package.json index 048a5fc508b84..a8999e848fed4 100644 --- a/package.json +++ b/package.json @@ -1879,7 +1879,7 @@ "mochawesome-merge": "^4.3.0", "mock-fs": "^5.1.2", "ms-chromium-edge-driver": "^0.5.1", - "msw": "~2.5.2", + "msw": "~2.10.2", "mutation-observer": "^1.0.3", "nock": "12.0.3", "node-stdlib-browser": "^1.3.1", diff --git a/x-pack/solutions/security/plugins/cloud_security_posture/jest.config.js b/x-pack/solutions/security/plugins/cloud_security_posture/jest.config.js index 630c9292dd304..1b0148d2a1900 100644 --- a/x-pack/solutions/security/plugins/cloud_security_posture/jest.config.js +++ b/x-pack/solutions/security/plugins/cloud_security_posture/jest.config.js @@ -10,6 +10,10 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../../..', roots: ['/x-pack/solutions/security/plugins/cloud_security_posture'], + // setupFilesAfterEnv is a list of scripts that are executed after JSDOM is initialized. + setupFilesAfterEnv: [ + '/x-pack/solutions/security/plugins/cloud_security_posture/jest.setup.js', + ], coverageDirectory: '/target/kibana-coverage/jest/x-pack/solutions/security/plugins/cloud_security_posture', coverageReporters: ['text', 'html'], diff --git a/x-pack/solutions/security/plugins/cloud_security_posture/jest.setup.js b/x-pack/solutions/security/plugins/cloud_security_posture/jest.setup.js new file mode 100644 index 0000000000000..e43772b4f736c --- /dev/null +++ b/x-pack/solutions/security/plugins/cloud_security_posture/jest.setup.js @@ -0,0 +1,22 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +// This is a fix for the BroadcastChannel API not being available in JSDOM. +// This is a temporary workaround until JSDOM supports BroadcastChannel. +// https://github.com/mswjs/data/issues/306 +// https://github.com/elastic/kibana/pull/208427 +class BroadcastChannelMock { + constructor() { + this.onmessage = null; + } + postMessage(data) { + if (this.onmessage) { + this.onmessage({ data }); + } + } +} +global.BroadcastChannel = BroadcastChannelMock; diff --git a/yarn.lock b/yarn.lock index f77f87ad913c4..ed905c2b5beb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1864,12 +1864,12 @@ resolved "https://registry.yarnpkg.com/@bufbuild/protobuf/-/protobuf-2.5.2.tgz#9b6cf005c50fdda72701da82f8db44635463d730" integrity sha512-foZ7qr0IsUBjzWIq+SuBLfdQCpJ1j8cTuNNT4owngTHoN5KsJb8L9t65fzz7SCeSWzescoOil/0ldqiL041ABg== -"@bundled-es-modules/cookie@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bundled-es-modules/cookie/-/cookie-2.0.0.tgz#c3b82703969a61cf6a46e959a012b2c257f6b164" - integrity sha512-Or6YHg/kamKHpxULAdSqhGqnWFneIXu1NKvvfBBzKGwpVsYuFIQ5aBPHDnnoR3ghW1nvSkALd+EF9iMtY7Vjxw== +"@bundled-es-modules/cookie@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@bundled-es-modules/cookie/-/cookie-2.0.1.tgz#b41376af6a06b3e32a15241d927b840a9b4de507" + integrity sha512-8o+5fRPLNbjbdGRRmJj3h6Hh1AQJf2dk3qQ/5ZFb+PXkRNiSoMGGUKlsgLfrxneb72axVJyIYji64E2+nNfYyw== dependencies: - cookie "^0.5.0" + cookie "^0.7.2" "@bundled-es-modules/statuses@^1.0.1": version "1.0.1" @@ -8604,10 +8604,10 @@ express "^4.18.2" strict-event-emitter "^0.5.1" -"@mswjs/interceptors@^0.36.5": - version "0.36.5" - resolved "https://registry.yarnpkg.com/@mswjs/interceptors/-/interceptors-0.36.5.tgz#c0fc6970a7a9f8c7b9f4c122dbab3827e4cc19a5" - integrity sha512-aQ8WF5zQwOdcxLsxSEk9Jd01GgGb80xxqCaiDDlewhtwqpSm8MOvUHslwPydVirasdW09++NxDNNftm1vLY8yA== +"@mswjs/interceptors@^0.39.1": + version "0.39.2" + resolved "https://registry.yarnpkg.com/@mswjs/interceptors/-/interceptors-0.39.2.tgz#de9de0ab23f99d387c7904df7219a92157d1d666" + integrity sha512-RuzCup9Ct91Y7V79xwCb146RaBRHZ7NBbrIUySumd1rpKqHL5OonaqrGIbug5hNwP/fRyxFMA6ISgw4FTtYFYg== dependencies: "@open-draft/deferred-promise" "^2.2.0" "@open-draft/logger" "^0.3.0" @@ -15783,11 +15783,6 @@ cookie@0.7.1: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.1.tgz#2f73c42142d5d5cf71310a74fc4ae61670e5dbc9" integrity sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w== -cookie@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" - integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== - cookie@^0.7.1, cookie@^0.7.2: version "0.7.2" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.2.tgz#556369c472a2ba910f2979891b526b3436237ed7" @@ -24345,25 +24340,26 @@ msgpackr@^1.11.2: optionalDependencies: msgpackr-extract "^3.0.2" -msw@~2.5.2: - version "2.5.2" - resolved "https://registry.yarnpkg.com/msw/-/msw-2.5.2.tgz#dfce10b68dbabc2d5dafeb6d7fb82c3c7073a4d1" - integrity sha512-eBsFgU30NYtrfC62XzS1rdAzFK+Br0zKU4ORqD9Qliq86362DWZyPiD6FLfMgy0Ktik83DPTXmqPMz2bqwmJdA== +msw@~2.10.2: + version "2.10.2" + resolved "https://registry.yarnpkg.com/msw/-/msw-2.10.2.tgz#e7a56ed0b6865b00a30b4c4a5b59e5388fd48315" + integrity sha512-RCKM6IZseZQCWcSWlutdf590M8nVfRHG1ImwzOtwz8IYxgT4zhUO0rfTcTvDGiaFE0Rhcc+h43lcF3Jc9gFtwQ== dependencies: - "@bundled-es-modules/cookie" "^2.0.0" + "@bundled-es-modules/cookie" "^2.0.1" "@bundled-es-modules/statuses" "^1.0.1" "@bundled-es-modules/tough-cookie" "^0.1.6" "@inquirer/confirm" "^5.0.0" - "@mswjs/interceptors" "^0.36.5" + "@mswjs/interceptors" "^0.39.1" + "@open-draft/deferred-promise" "^2.2.0" "@open-draft/until" "^2.1.0" "@types/cookie" "^0.6.0" "@types/statuses" "^2.0.4" - chalk "^4.1.2" graphql "^16.8.1" headers-polyfill "^4.0.2" is-node-process "^1.2.0" outvariant "^1.4.3" path-to-regexp "^6.3.0" + picocolors "^1.1.1" strict-event-emitter "^0.5.1" type-fest "^4.26.1" yargs "^17.7.2"