Skip to content
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

[kbn-test] Jest run script should use testPathPattern to lookup config #206341

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

nickofthyme
Copy link
Contributor

@nickofthyme nickofthyme commented Jan 10, 2025

Summary

TLDR; Adds logic to support the jest vscode extension by reading the --testPathPattern arg for the purpose of config lookup. This enables running tests easily in the vscode jest extension.

Currently the yarn test:jest command, requires one of the following:

  • A path to a test file
  • A folder where tests can be found
  • A --config argument pointing to one of the many jest.config.js files

The jest vscode extension does not easily support this behavior as it expects a static command to run all tests.

One option people have used is virtualfolders but this requires enumerating all possible configs. See doc.

{
  "jest.virtualFolders": [
    {
      "name": "@kbn/maps-plugin",
      "jestCommandLine": "yarn test:jest --config x-pack/platform/plugins/shared/maps/jest.config.js"
    },
    {
      "name": "@kbn/embeddable-enhanced-plugin",
      "jestCommandLine": "yarn test:jest --config x-pack/platform/plugins/shared/embeddable_enhanced/jest.config.js"
    }
  ]
}

This could be autogenerate and @managed options in .vscode/setting but this is more complicated to achieve at the moment.

Without using virtualFolders the best option is to use the jestcommandline. But this option does not allow parameterizing the command like we can with the debug launch.json config (e.g. "${jest.testNamePattern}").

The jestcommandline does however pass a few additional argument as shown below...

node scripts/jest --testLocationInResults --json --useStderr --outputFile '/var/folders/yx/ykmyj9616fn746d191gqc50m0000gn/T/jest_runner_kibana_501_2.json' --testNamePattern 'IndexPattern Data Source #getUserMessages warning messages should show different types of warning messages$' --no-coverage --reporters 'default' --reporters '/Users/nickpartridge/.vscode/extensions/orta.vscode-jest-6.4.0/out/reporter.js' --colors --watchAll=false --testPathPattern '/Users/nickpartridge/Documents/repos/kibana/x-pack/platform/plugins/shared/lens/public/datasources/form_based/form_based.test.ts

Most importantly the --testPathPattern argument. This is passed whenever the extension is ran against a directory, file or specific test. The file name is passed as unnamed argument when run on save of a file. But the current yarn test:jest command expects this as an additional unnamed argument. This PR now treats the testPathPattern as a file or directory to find the config.

Warning

This works for most cases with the most notable exception being if you were to run a directory that contained multiple jest.config.ts files. This would error just the same as calling something like...

yarn test:jest x-pack/platform/plugins/shared

Or running this from the vscode jest extension like this...
node scriptsjest --testLocationInResult • Untitled-1 — kibana 2025-01-10 at 1 36 46 PM
This would result in multiple configs which will not work. I think this is not a very common use case.

If we did want to address this case I think it could be solved with virtualFolders to run files grouped by their respective configs.

@nickofthyme nickofthyme requested review from a team as code owners January 10, 2025 19:52
@nickofthyme nickofthyme added release_note:skip Skip the PR/issue when compiling release notes backport:all-open Backport to all branches that could still receive a release labels Jan 10, 2025
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

@nickofthyme nickofthyme merged commit 481b803 into elastic:main Jan 10, 2025
12 checks passed
@nickofthyme nickofthyme deleted the jest-vscode-args branch January 10, 2025 23:27
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 7.17, 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12718816148

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 10, 2025
…fig (elastic#206341)

Adds logic to support the jest vscode extension by reading the
`--testPathPattern` arg for the purpose of config lookup. This enables
running tests easily in the vscode jest extension.

(cherry picked from commit 481b803)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 10, 2025
…fig (elastic#206341)

Adds logic to support the jest vscode extension by reading the
`--testPathPattern` arg for the purpose of config lookup. This enables
running tests easily in the vscode jest extension.

(cherry picked from commit 481b803)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 10, 2025
…fig (elastic#206341)

Adds logic to support the jest vscode extension by reading the
`--testPathPattern` arg for the purpose of config lookup. This enables
running tests easily in the vscode jest extension.

(cherry picked from commit 481b803)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
7.17 Backport failed because of merge conflicts
8.16
8.17
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 206341

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 11, 2025
…0; to lookup config (#206341) (#206356)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[kbn-test] Jest run script should use `testPathPattern` to
lookup config (#206341)](#206341)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-10T23:27:05Z","message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:all-open"],"title":"[kbn-test]
Jest run script should use `testPathPattern` to lookup
config","number":206341,"url":"https://github.com/elastic/kibana/pull/206341","mergeCommit":{"message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206341","number":206341,"mergeCommit":{"message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9"}}]}]
BACKPORT-->

Co-authored-by: Nick Partridge <[email protected]>
kibanamachine added a commit that referenced this pull request Jan 11, 2025
…60; to lookup config (#206341) (#206354)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[kbn-test] Jest run script should use &#x60;testPathPattern&#x60; to
lookup config (#206341)](#206341)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-10T23:27:05Z","message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:all-open"],"title":"[kbn-test]
Jest run script should use `testPathPattern` to lookup
config","number":206341,"url":"https://github.com/elastic/kibana/pull/206341","mergeCommit":{"message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206341","number":206341,"mergeCommit":{"message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9"}}]}]
BACKPORT-->

Co-authored-by: Nick Partridge <[email protected]>
kibanamachine added a commit that referenced this pull request Jan 11, 2025
…60; to lookup config (#206341) (#206355)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[kbn-test] Jest run script should use &#x60;testPathPattern&#x60; to
lookup config (#206341)](#206341)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-10T23:27:05Z","message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:all-open"],"title":"[kbn-test]
Jest run script should use `testPathPattern` to lookup
config","number":206341,"url":"https://github.com/elastic/kibana/pull/206341","mergeCommit":{"message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206341","number":206341,"mergeCommit":{"message":"[kbn-test]
Jest run script should use `testPathPattern` to lookup config
(#206341)\n\nAdds logic to support the jest vscode extension by reading
the\r\n`--testPathPattern` arg for the purpose of config lookup. This
enables\r\nrunning tests easily in the vscode jest
extension.","sha":"481b8037d609e2d7a994e7696e2fa23f7b44f2b9"}}]}]
BACKPORT-->

Co-authored-by: Nick Partridge <[email protected]>
@nickofthyme nickofthyme added backport:version Backport to applied version labels and removed backport:all-open Backport to all branches that could still receive a release labels Jan 11, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12719812271

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.16 Cherrypick failed because the selected commit (481b803) is empty. It looks like the commit was already backported in #206354
8.17 Cherrypick failed because the selected commit (481b803) is empty. It looks like the commit was already backported in #206355
8.x Cherrypick failed because the selected commit (481b803) is empty. It looks like the commit was already backported in #206356

Manual backport

To create the backport manually run:

node scripts/backport --pr 206341

Questions ?

Please refer to the Backport tool documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes v8.16.3 v8.17.1 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants