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

fix(vm-threads): tests not cancelled on key press, cancelled tests shown twice #4781

Merged

Conversation

AriPerkkio
Copy link
Member

@AriPerkkio AriPerkkio commented Dec 19, 2023

Description

  • Fixes bug where test run is not cancelled when one of the registered keys is pressed. This is only present on pool: 'vmThreads'.
  • Fixes bug where cancelled tests were shown twice by reporters

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link

netlify bot commented Dec 19, 2023

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 4298d79
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/6583270f2298f500088c7011

@AriPerkkio
Copy link
Member Author

There's still one more bug to fix. Once tests have been interrupted and are re-run, the "skip status" of the tests is not reseted. Earlier this line has done it:

ctx.state.clearFiles(project, files)

Skip status is set here:

cancelFiles(files: string[], root: string, projectName: string) {
this.collectFiles(files.map(filepath => ({
filepath,
name: relative(root, filepath),
id: filepath,
mode: 'skip',
type: 'suite',
result: {
state: 'skip',
},
meta: {},
// Cancelled files have not yet collected tests
tasks: [],
projectName,
})))
}

This bug is present on all pools.

@@ -44,7 +44,7 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
if (project.config.browser.isolate) {
for (const path of paths) {
if (isCancelled) {
ctx.state.cancelFiles(files.slice(paths.indexOf(path)), ctx.config.root, project.getName())
ctx.state.cancelFiles(files.slice(paths.indexOf(path)), ctx.config.root, project.config.name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to match with the collected files:

projectName: config.name,

This feels a bit hacky. The WorkspaceProject.getSerializableConfig() always returns undefined for .name instead of '' when there's no name set for the project (no workspaces used).

The state.clearFiles uses the projectName when comparing files. When they don't match, there can be duplicate entries where one is from collection and one from cancelling:

'/x/vitest-example-project/vitest/test/sum.2.test.js' => [
  {
    filepath: '/x/vitest-example-project/vitest/test/sum.2.test.js',
    id: '/x/vitest-example-project/vitest/test/sum.2.test.js',
    mode: 'skip',   // <-- From test cancel
    name: 'test/sum.2.test.js',
    projectName: '',
    type: 'suite',
    ...
  },
  {
    filepath: '/x/vitest-example-project/vitest/test/sum.2.test.js',
    mode: 'run',     // <-- From test collect
    name: 'test/sum.2.test.js',
    type: 'suite',
    ...
  }
],

These show up in reports like below:

test-cancel.mp4

@AriPerkkio AriPerkkio changed the title fix(vm-threads): tests not cancelled on key press fix(vm-threads): tests not cancelled on key press, cancelled tests shown twice Dec 20, 2023
@AriPerkkio AriPerkkio marked this pull request as ready for review December 20, 2023 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants