diff --git a/package.json b/package.json index 388e76f..0a988f6 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "prettier": "prettier --write .", "prettier:ci": "prettier --check .", "lint:sass": "yarn lint:sass:ci --fix", - "lint:ci": "run-p prettier:ci sync check lint:js:ci lint:sass:ci tsc tsc:tests", + "lint:ci": "run-s prettier:ci sync check lint:js:ci lint:sass:ci tsc tsc:tests", "lint:sass:ci": "stylelint '**/*.scss'", "docs:json": "sass -p node src/sass/json.scss static/built/json.css", "docs:sass": "sass -p node src/sass/app.scss static/built/app.css", diff --git a/test/routes/page.spec.ts b/test/routes/page.spec.ts index e1dd870..1d13fe1 100644 --- a/test/routes/page.spec.ts +++ b/test/routes/page.spec.ts @@ -3,7 +3,7 @@ import { render, type RenderResult } from '@testing-library/svelte'; import Page from '$src/routes/+page.svelte'; interface TestContext { - result: RenderResult; + result: RenderResult; } describe('Page', () => { diff --git a/vitest.config.ts b/vitest.config.ts index 3283be1..c28a037 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,4 +1,5 @@ import { svelteTesting } from '@testing-library/svelte/vite'; +import type { PluginOption } from 'vite'; import { coverageConfigDefaults, defineConfig, @@ -7,13 +8,24 @@ import { import viteConfig from './vite.config.js'; +// Run tests in browser environment +// https://github.com/testing-library/svelte-testing-library/issues/222 +const vitestBrowserConditionPlugin: PluginOption = { + name: 'vite-plugin-vitest-browser-condition', + config({ resolve }) { + if (process.env.VITEST) { + resolve?.conditions?.unshift('browser'); + } + }, +}; + /** * @see https://vitest.dev/config/#configuration */ export default mergeConfig( viteConfig, defineConfig({ - plugins: [svelteTesting()], + plugins: [vitestBrowserConditionPlugin, svelteTesting()], test: { include: ['./test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], globals: true,