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

onTestFinished should run after each repeat not after all the repeats are done #5869

Closed
jackyzha0 opened this issue Jun 10, 2024 · 0 comments · Fixed by #6609
Closed

onTestFinished should run after each repeat not after all the repeats are done #5869

jackyzha0 opened this issue Jun 10, 2024 · 0 comments · Fixed by #6609
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome

Comments

@jackyzha0
Copy link

Describe the bug

I am using onTestFinished to cleanup resources per test without needing to lift variables to the describe level for afterEach.

Recently, we've started running tests with repeats to catch flakes and noticed that the run-order of onTestFinished is unexpected

test 1
afterEach 1
test 2
afterEach 2
test 3
afterEach 3
test 4
afterEach 4
onTestFinished 4
onTestFinished 3
onTestFinished 2
onTestFinished 1

whereas I would expect

test 1
afterEach 1
onTestFinished 1
test 2
afterEach 2
onTestFinished 2
test 3
afterEach 3
onTestFinished 3
test 4
afterEach 4
onTestFinished 4

Reproduction

https://replit.com/join/uueakwjekd-jzhao-replit

import { describe, expect, onTestFinished, test, afterEach } from "vitest";

describe("suite with repeats", () => {
  let n = 0;
  afterEach(() => {
    console.log('afterEach', n)
  })
  
  test("should run a test", () => {
    n += 1;
    const repeat = n;
    expect(1).toBe(1);
    onTestFinished(() => {
      console.log('onTestFinished', repeat)
    });
    
    console.log('test', repeat)
  }, { repeats: 3});
})
 RUN  v1.6.0 /home/runner/vitest-repro

stdout | index.test.ts > suite with repeats > should run a test
test 1
afterEach 1
test 2
afterEach 2
test 3
afterEach 3
test 4
afterEach 4
onTestFinished 4
onTestFinished 3
onTestFinished 2
onTestFinished 1

 ✓ index.test.ts (1)
   ✓ suite with repeats (1)
     ✓ should run a test (repeat x3)

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  19:00:54
   Duration  835ms (transform 33ms, setup 0ms, collect 24ms, tests 5ms, environment 0ms, prepare 108ms)

System Info

System:
    OS: Linux 6.5 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (16) x64 AMD EPYC 7B13
    Memory: 38.93 GB / 62.78 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.12.2 - /nix/store/a2iia53azgg3kjqas6cwmznpghhkkvqk-nodejs-20.12.2-wrapped/bin/node
    Yarn: 1.22.22 - /nix/store/d03xglbinz66yml6h55q6an183bxqcma-yarn-1.22.22/bin/yarn
    npm: 10.5.0 - /nix/store/a2iia53azgg3kjqas6cwmznpghhkkvqk-nodejs-20.12.2-wrapped/bin/npm
    pnpm: 8.15.5 - /nix/store/77wblnm5dnmgnan3695j3mk4r7j75s5j-pnpm-8.15.5/bin/pnpm
    bun: 1.1.11 - /nix/store/v0ps8nmsgbpdskm751vqg0s80nzkpiif-bun-1.1.11/bin/bun
  npmPackages:
    vitest: ^1.6.0 => 1.6.0 


### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@sheremet-va sheremet-va added pr welcome p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Jun 10, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants