From 3b821e0acb1fd539cf09157fb0dfa411ea314076 Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Mon, 8 Jan 2024 15:13:12 +0100 Subject: [PATCH] [Ops] Work around unit-tests in watch mode fails to set 'structuredClone' (#174444) ## Summary @CoenWarmer found that `--watch` on jest tests will cause this sort of error: ``` TypeError: Cannot assign to read only property 'structuredClone' of object '[object global]' ``` There's some workaround suggested on this thread (although not necessarily related): https://github.com/zloirock/core-js/issues/1281 In the workaround, we set `structuredClone` to `{}`, this would allow the currently offending 3rd party to overwrite it where it's currently getting an error. --- packages/kbn-test/jest-preset.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/kbn-test/jest-preset.js b/packages/kbn-test/jest-preset.js index 8d50a88e23073..73c5ffdf7257d 100644 --- a/packages/kbn-test/jest-preset.js +++ b/packages/kbn-test/jest-preset.js @@ -124,4 +124,10 @@ module.exports = { watchPathIgnorePatterns: ['.*/__tmp__/.*'], resolver: '/packages/kbn-test/src/jest/resolver.js', + + // Workaround to "TypeError: Cannot assign to read only property 'structuredClone' of object '[object global]'" + // This happens when we run jest tests with --watch after node20+ + globals: { + structuredClone: {}, + }, };