Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samualtnorman/babel-plugin-vitest
import.meta.vitest -> undefined
https://github.com/samualtnorman/babel-plugin-vitest
babel babel-plugin vitest
Last synced: 26 days ago
JSON representation
import.meta.vitest -> undefined
- Host: GitHub
- URL: https://github.com/samualtnorman/babel-plugin-vitest
- Owner: samualtnorman
- License: mit
- Created: 2024-03-29T16:07:09.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-04-23T15:20:48.000Z (7 months ago)
- Last Synced: 2024-04-23T16:40:41.222Z (7 months ago)
- Topics: babel, babel-plugin, vitest
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/babel-plugin-vitest
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Babel Plugin Vitest (`babel-plugin-vitest`)
This a plugin for [Babel](https://babeljs.io/) 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](https://vitest.dev/)'s
[In-Source Testing](https://vitest.dev/guide/in-source.html) feature.## Setup
### Install```sh
npm install --save-dev babel-plugin-vitest
```### Babel config
`babel.config.json`
```json
{
"plugins": [ "babel-plugin-vitest" ]
}
```## Example
### In
`src/index.js````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`
```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)
})
}
```