-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.js
55 lines (50 loc) · 1.63 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/// <reference types="vitest" />
import { sveltekit } from '@sveltejs/kit/vite';
import { basename, dirname, join } from 'pathe';
import Icons from 'unplugin-icons/vite';
import { defineConfig } from 'vite';
import ssrResolvePlugin from './src/site/plugin';
import highlightPlugin from './utils/highlight-plugin';
import semver from 'semver';
import { svelteTesting } from '@testing-library/svelte/vite';
import { createRequire } from 'node:module';
import * as fs from 'node:fs';
function getSvelteMajor() {
const require = createRequire(import.meta.url);
const sveltePackage = JSON.parse(fs.readFileSync(require.resolve('svelte/package.json')));
return semver.major(sveltePackage.version);
}
const svelteMajor = getSvelteMajor();
const isSsrTest = process.env.TEST_SSR === '1';
/** @type {Partial<import('vite').UserConfig['test']>} */
const testConfigDom = {
environment: 'jsdom',
include: ['src/tests/dom/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
};
/** @type {Partial<import('vite').UserConfig['test']>} */
const testConfigSsr = {
environment: 'node',
include: ['src/tests/ssr/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
};
export default defineConfig({
plugins: [
ssrResolvePlugin(),
highlightPlugin({}),
sveltekit(),
Icons({
compiler: 'svelte',
autoInstall: true
}),
isSsrTest ? undefined : svelteTesting()
].filter(Boolean),
test: {
setupFiles: 'src/tests/setup.js',
resolveSnapshotPath: (testPath, snapExtension) => {
return join(
join(dirname(testPath), '__snapshots__', `svelte@${svelteMajor}`),
`${basename(testPath)}${snapExtension}`
);
},
...(isSsrTest ? testConfigSsr : testConfigDom)
}
});