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

run order of beforeAll hook not as expected #7153

Closed
6 tasks done
lza opened this issue Jan 1, 2025 · 3 comments · Fixed by #7183
Closed
6 tasks done

run order of beforeAll hook not as expected #7153

lza opened this issue Jan 1, 2025 · 3 comments · Fixed by #7183

Comments

@lza
Copy link

lza commented Jan 1, 2025

Describe the bug

the test code like below:

describe.sequential('sum', () => {
  beforeAll(() => {
    console.log('before all +++')
  })
  afterAll(() => {
    console.log('after all ++++')
  })
  beforeEach(()=> {
    console.log('before each')
  })
  afterEach(() => {
    console.log("after each")
  })
  test('1+2=3', async () => {
    expect(sum(1, 2)).toEqual(3);
    console.log('123')
  });
});

while the output like below:

vitest run

RUN v2.1.8 /home/projects/vitejs-vite-bju16tjp

stdout | src/sum.test.ts > sum > 1+2=3
before each
123
after each

stdout | src/sum.test.ts > sum
before all +++
after all ++++

✓ src/sum.test.ts (1)
✓ sum (1)
✓ 1+2=3

does not the beforeAll hook should run before all test case?

Reproduction

you could reproduce this issue with : this example

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^5.4.8 => 5.4.11 
    vitest: ^2.1.8 => 2.1.8

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 1, 2025

The output is probably due to the buffering/grouping. With --disableConsoleIntercept, you can see more precise logs.

$ npm run test --  --disableConsoleIntercept
...
 RUN  v2.1.8 /home/projects/vitejs-vite-bju16tjp

before all +++
before each
123
after each
after all ++++

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 6, 2025

Interestingly, the issue actually doesn't happen since 3.0.0-beta.2. Probably this is because we now always wait setTimeout(.., 0) for each test as par #6944.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 6, 2025

I made a PR to add a test #7183. This issue itself (i.e. mixing of before/after hook logs) doesn't exist anymore, so let me close this.

@hi-ogawa hi-ogawa closed this as completed Jan 6, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jan 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants