babel-plugin-vitest
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

Babel Plugin Vitest (babel-plugin-vitest)

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.

Setup

Install

npm install --save-dev babel-plugin-vitest

Babel config

babel.config.json

{
	"plugins": [ "babel-plugin-vitest" ]
}

Example

In

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)
	})
}

Out

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)
	})
}

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-vitest

Weekly Downloads

39

Version

0.0.0

License

MIT

Unpacked Size

3.84 kB

Total Files

5

Last publish

Collaborators

  • samual