Skip to content

Commit

Permalink
Run tests in browser env
Browse files Browse the repository at this point in the history
  • Loading branch information
jgerigmeyer committed Nov 7, 2024
1 parent a79e99a commit a70f6b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/routes/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, type RenderResult } from '@testing-library/svelte';
import Page from '$src/routes/+page.svelte';

interface TestContext {
result: RenderResult<Page>;
result: RenderResult<typeof Page>;
}

describe('Page', () => {
Expand Down
14 changes: 13 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { svelteTesting } from '@testing-library/svelte/vite';
import type { PluginOption } from 'vite';
import {
coverageConfigDefaults,
defineConfig,
Expand All @@ -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,
Expand Down

0 comments on commit a70f6b4

Please sign in to comment.