This a plugin for Babel that replaces instances of import.meta.vitest
in your code with
undefined
.
This plugin should be put in your babel config when you are using Vitest's In-Source Testing feature.
npm install --save-dev babel-plugin-vitest
babel.config.json
{
"plugins": [ "babel-plugin-vitest" ]
}
src/index.js
// the implementation
export function add(...args) {
return args.reduce((a, b) => a + b, 0)
}
// in-source test suites
if (import.meta.vitest) {
const { it, expect } = import.meta.vitest
it('add', () => {
expect(add()).toBe(0)
expect(add(1)).toBe(1)
expect(add(1, 2, 3)).toBe(6)
})
}
dist/index.js
// the implementation
export function add(...args) {
return args.reduce((a, b) => a + b, 0)
}
// in-source test suites
if (undefined) {
const { it, expect } = import.meta.vitest
it('add', () => {
expect(add()).toBe(0)
expect(add(1)).toBe(1)
expect(add(1, 2, 3)).toBe(6)
})
}