Skip to content

run order of beforeAll hook not as expected #7153

@lza

Description

@lza

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions