Skip to content

Commit

Permalink
feat(vitest): add vitest cleanup export (#294)
Browse files Browse the repository at this point in the history
feat(vitest): add vitest cleanup import
  • Loading branch information
mcous committed Jan 27, 2024
1 parent 16a7a4b commit ee1b1f7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
".": {
"types": "./types/index.d.ts",
"default": "./src/index.js"
},
"./vitest": {
"default": "./src/vitest.js"
}
},
"type": "module",
Expand Down Expand Up @@ -43,9 +46,9 @@
"toc": "doctoc README.md",
"lint": "(prettier . --check || true) && eslint .",
"format": "prettier . --write && eslint . --fix",
"test": "vitest run src",
"test:watch": "npm run test -- --watch",
"test:update": "npm run test -- --updateSnapshot --coverage",
"test": "vitest run --coverage",
"test:watch": "vitest",
"test:update": "vitest run --update",
"setup": "npm install && npm run validate",
"validate": "npm-run-all lint test",
"contributors:add": "all-contributors add",
Expand All @@ -61,10 +64,10 @@
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/jest-dom": "^6.3.0",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^0.33.0",
"all-contributors-cli": "^6.26.0",
"doctoc": "^2.2.1",
"eslint": "^8.43.0",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/_vitest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@testing-library/jest-dom/vitest'
import '../vitest'
11 changes: 0 additions & 11 deletions src/test-setup.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/vitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { afterEach } from 'vitest'

import { act, cleanup } from './pure.js'

afterEach(async () => {
await act()
cleanup()
})
12 changes: 8 additions & 4 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
test: {
environment: 'jsdom',
setupFiles: ['./src/test-setup.js'],
plugins: [svelte()],
test: {
environment: 'jsdom',
setupFiles: ['./src/__tests__/_vitest-setup.js'],
coverage: {
provider: 'v8',
include: ['src'],
},
},
})

0 comments on commit ee1b1f7

Please sign in to comment.