Package Exports
- vitest-gen
- vitest-gen/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vitest-gen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
vitest-gen
NPM package for generating Next.JS template files with corresponding Vitest test files
Features
- Generate both component (.tsx) and function (.ts) template files
- Generate template unit tests matching the directory structure of create files
vitest-gen requires Vitest >=2.1.1 Node >=v20.0.0
Examples
Generate component
$ npx vitest-gen app/home/page.tsx HomePage// app/home/page.tsx
export const HomePage = () => {
return (
<div>
<h1>HomePage</h1>
</div>
)
}// __test__/app/home/page.test.tsx
import { expect, test } from 'vitest'
import { render, screen } from '@testing-library/react'
import { HomePage } from '@/app/home/page'
test('HomePage', () => {
render(<HomePage />)
expect(screen.getByRole('heading', { level: 1, name: 'HomePage' })).toBeDefined()
})Generate function
$ npx vitest-gen lib/testFunc.ts TestFunc// lib/testFunc.ts
export function TestFunc() {
return 0
}// __test__/lib/testFunc.test.ts
import { expect, test } from 'vitest'
import { TestFunc } from '@/lib/testFunc'
test('TestFunc', () => {
expect(TestFunc()).equal(0, "TestFunc should return 0")
})License
MIT License © 2024-Present Kristian Kolehmainen