Skip to content

Commit c8e1bde

Browse files
authored
chore(vue-query-devtools): set up vitest environment with production fallback test (#10629)
* test(vue-query-devtools): set up vitest environment with production fallback test * chore(vue-query-devtools): unify 'defineConfig' and 'mergeConfig' import from 'vitest/config'
1 parent 74fa05e commit c8e1bde

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

packages/vue-query-devtools/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"compile": "vue-tsc --build",
2020
"test:eslint": "eslint --concurrency=auto ./src",
2121
"test:types": "vue-tsc --build",
22+
"test:lib": "vitest",
23+
"test:lib:dev": "pnpm run test:lib --watch",
2224
"test:build": "publint --strict && attw --pack",
2325
"build": "pnpm run compile && vite build"
2426
},
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, it, vi } from 'vitest'
2+
3+
describe('VueQueryDevtools', () => {
4+
it('should return null in non-development environments', async () => {
5+
vi.stubEnv('NODE_ENV', 'production')
6+
vi.resetModules()
7+
8+
try {
9+
const { VueQueryDevtools } = await import('..')
10+
expect((VueQueryDevtools as unknown as () => null)()).toBeNull()
11+
} finally {
12+
vi.unstubAllEnvs()
13+
vi.resetModules()
14+
}
15+
})
16+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, it, vi } from 'vitest'
2+
3+
describe('VueQueryDevtoolsPanel', () => {
4+
it('should return null in non-development environments', async () => {
5+
vi.stubEnv('NODE_ENV', 'production')
6+
vi.resetModules()
7+
8+
try {
9+
const { VueQueryDevtoolsPanel } = await import('..')
10+
expect((VueQueryDevtoolsPanel as unknown as () => null)()).toBeNull()
11+
} finally {
12+
vi.unstubAllEnvs()
13+
vi.resetModules()
14+
}
15+
})
16+
})

packages/vue-query-devtools/vite.config.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { defineConfig, mergeConfig } from 'vite'
1+
import { defineConfig, mergeConfig } from 'vitest/config'
22
import vue from '@vitejs/plugin-vue'
33
import { tanstackViteConfig } from '@tanstack/vite-config'
44

5+
import packageJson from './package.json'
6+
57
const config = defineConfig({
68
plugins: [vue()],
79
// fix from https://github.com/vitest-dev/vitest/issues/6992#issuecomment-2509408660
@@ -15,6 +17,20 @@ const config = defineConfig({
1517
},
1618
},
1719
},
20+
test: {
21+
name: packageJson.name,
22+
dir: './src',
23+
watch: false,
24+
environment: 'jsdom',
25+
coverage: {
26+
enabled: true,
27+
provider: 'istanbul',
28+
include: ['src/**/*'],
29+
exclude: ['src/__tests__/**'],
30+
},
31+
typecheck: { enabled: true },
32+
restoreMocks: true,
33+
},
1834
})
1935

2036
export default mergeConfig(

0 commit comments

Comments
 (0)