Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

babel-plugin-vitest

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-vitest

import.meta.vitest -> undefined

latest
Source
npmnpm
Version
0.0.0
Version published
Weekly downloads
1.9K
-32.87%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

babel

FAQs

Package last updated on 29 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts