npm vite-node 0.10.0
v0.10.0

latest releases: 2.2.0-beta.1, 2.1.5, 2.1.4...
2 years ago

Breaking Changes

From Vitest v0.10.0, the callback style of declaring tests is deprecated. You can rewrite them to use async/await functions, or use Promise to mimic the callback style.

- it('should work', (done) => {
+ it('should work', () => new Promise(done => {
    // ...
    done()
- })
+ }))

Features

beforeAll / beforeEach cleanup callback

beforeAll / beforeEach now accepts an optional cleanup function as the return value (equivalent to afterAll / afterEach).

import { beforeAll } from 'vitest'

beforeEach(async () => {
  // called once before each test run
  await startMocking()

  // clean up function, called once after each test run
  return async () => {
    await stopMocking()
  }
})

Learn more at:

Test Context

Inspired by Playwright Fixtures, Vitest's test context allows you to define utils, states, and fixtures that can be used in your tests.

import { beforeEach, it } from 'vitest'

beforeEach((context) => {
  // extend context
  context.foo = 'bar'
})

it('should work', ({ foo }) => {
  console.log(foo) // 'bar'
})

Learn more at Test Context

Concurrent Snapshot

Due to the limitation of JavaScript, timing based Singleton pattern will cause conflicts when running multiple async functions in concurrent. Previously reported as #551. Thanks to the newly introduced Test Context, we can now provide a test specific expect instance to avoid conflicts. To use it, you can destructure the expect from each test context instead of the global one.

test.concurrent('test 1', async ({ expect }) => {
  expect(foo).toMatchSnapshot()
})
test.concurrent('test 2', async ({ expect }) => {
  expect(foo).toMatchSnapshot()
})

Reporter from file / package

Now you can pass a path to file, or a package name to the reporters options to use custom reporter. Thanks to @ericjgagnon (#1136) (f2bceb2)

Bug Fixes

Don't miss a new vite-node release

NewReleases is sending notifications on new releases.