0.0.0 • Published 5 months ago

babel-plugin-vitest v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

5 months ago

0.0.0

1 year ago