Skip to content

Commit f816f9b

Browse files
[8.18] fix dysfunctional read_jest_help.mjs (#236143) (#236229)
# Backport This will backport the following commits from `main` to `8.18`: - [fix dysfunctional `read_jest_help.mjs` (#236143)](#236143) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Alex Szabo","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-09-24T08:24:02Z","message":"fix dysfunctional `read_jest_help.mjs` (#236143)\n\n## Summary\n`src/platform/packages/shared/kbn-test/src/jest/run.ts` makes a\nreference to an existing script, `read_jest_help.mjs`. However this file\ndoesn't work as advertised.\n\n```\nnode:internal/modules/esm/resolve:204\n const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n ^\n\nError: Cannot find package '/Users/alex/Git/elastic-kibana/node_modules/@kbn/dev-cli-errors/index.js' imported from /Users/alex/Git/elastic-kibana/scripts/read_jest_help.mjs\n at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n at packageResolve (node:internal/modules/esm/resolve:778:12)\n```\n\nAn easy way to fix this was to move it to cjs, updating the imports, and\nit started working again.\nThe update to the\n`src/platform/packages/shared/kbn-test/src/jest/jest_flags.json` is\nthrough running the script.","sha":"06971a36690b2bd34c7cd4b1db53ed8312515e6d","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.2.0"],"title":"fix dysfunctional `read_jest_help.mjs`","number":236143,"url":"https://github.com/elastic/kibana/pull/236143","mergeCommit":{"message":"fix dysfunctional `read_jest_help.mjs` (#236143)\n\n## Summary\n`src/platform/packages/shared/kbn-test/src/jest/run.ts` makes a\nreference to an existing script, `read_jest_help.mjs`. However this file\ndoesn't work as advertised.\n\n```\nnode:internal/modules/esm/resolve:204\n const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n ^\n\nError: Cannot find package '/Users/alex/Git/elastic-kibana/node_modules/@kbn/dev-cli-errors/index.js' imported from /Users/alex/Git/elastic-kibana/scripts/read_jest_help.mjs\n at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n at packageResolve (node:internal/modules/esm/resolve:778:12)\n```\n\nAn easy way to fix this was to move it to cjs, updating the imports, and\nit started working again.\nThe update to the\n`src/platform/packages/shared/kbn-test/src/jest/jest_flags.json` is\nthrough running the script.","sha":"06971a36690b2bd34c7cd4b1db53ed8312515e6d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/236143","number":236143,"mergeCommit":{"message":"fix dysfunctional `read_jest_help.mjs` (#236143)\n\n## Summary\n`src/platform/packages/shared/kbn-test/src/jest/run.ts` makes a\nreference to an existing script, `read_jest_help.mjs`. However this file\ndoesn't work as advertised.\n\n```\nnode:internal/modules/esm/resolve:204\n const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);\n ^\n\nError: Cannot find package '/Users/alex/Git/elastic-kibana/node_modules/@kbn/dev-cli-errors/index.js' imported from /Users/alex/Git/elastic-kibana/scripts/read_jest_help.mjs\n at legacyMainResolve (node:internal/modules/esm/resolve:204:26)\n at packageResolve (node:internal/modules/esm/resolve:778:12)\n```\n\nAn easy way to fix this was to move it to cjs, updating the imports, and\nit started working again.\nThe update to the\n`src/platform/packages/shared/kbn-test/src/jest/jest_flags.json` is\nthrough running the script.","sha":"06971a36690b2bd34c7cd4b1db53ed8312515e6d"}}]}] BACKPORT--> Co-authored-by: Alex Szabo <[email protected]>
1 parent ecb2950 commit f816f9b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

scripts/read_jest_help.mjs renamed to scripts/read_jest_help.cjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import Fsp from 'fs/promises';
11-
import Path from 'path';
10+
require('../src/setup_node_env');
1211

13-
import { createFailError } from '@kbn/dev-cli-errors';
14-
import { run } from '@kbn/dev-cli-runner';
15-
import { REPO_ROOT } from '@kbn/repo-info';
12+
const Fsp = require('fs/promises');
13+
const Path = require('path');
14+
15+
const { createFailError } = require('@kbn/dev-cli-errors');
16+
const { run } = require('@kbn/dev-cli-runner');
17+
const { REPO_ROOT } = require('@kbn/repo-info');
1618

1719
const FLAGS_FILE = 'src/platform/packages/shared/kbn-test/src/jest/jest_flags.json';
1820

@@ -21,7 +23,7 @@ function readStdin() {
2123
let buffer = '';
2224
let timer = setTimeout(() => {
2325
reject(
24-
createFailError('you must pipe the output of `yarn jest --help` to this script', {
26+
new Error('you must pipe the output of `yarn jest --help` to this script', {
2527
showHelp: true,
2628
})
2729
);
@@ -113,7 +115,7 @@ run(
113115
log.warning('make sure you bootstrap to rebuild @kbn/test');
114116
},
115117
{
116-
usage: `yarn jest --help | node scripts/read_jest_help.mjs`,
118+
usage: `yarn jest --help | node scripts/read_jest_help.cjs`,
117119
description: `
118120
Jest no longer exposes the ability to parse CLI flags externally, so we use this
119121
script to read the help output and convert it into parameters we can pass to getopts()

src/platform/packages/shared/kbn-test/src/jest/jest_flags.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"modulePathIgnorePatterns",
2525
"modulePaths",
2626
"notifyMode",
27+
"openHandlesTimeout",
2728
"outputFile",
2829
"preset",
2930
"prettierPath",
@@ -88,6 +89,7 @@
8889
"onlyChanged",
8990
"onlyFailures",
9091
"passWithNoTests",
92+
"randomize",
9193
"resetMocks",
9294
"resetModules",
9395
"restoreMocks",
@@ -104,7 +106,8 @@
104106
"version",
105107
"watch",
106108
"watchAll",
107-
"watchman"
109+
"watchman",
110+
"workerThreads"
108111
],
109112
"alias": {
110113
"b": "bail",

src/platform/packages/shared/kbn-test/src/jest/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function runJest(configName = 'jest.config.js') {
5656
5757
If this flag is valid you might need to update the flags in "src/platform/packages/shared/kbn-test/src/jest/run.js".
5858
59-
Run 'yarn jest --help | node scripts/read_jest_help.mjs' to update this scripts knowledge of what
59+
Run 'yarn jest --help | node scripts/read_jest_help.cjs' to update this scripts knowledge of what
6060
flags jest supports
6161
6262
`

0 commit comments

Comments
 (0)