-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
78 lines (76 loc) · 2.44 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import react from '@vitejs/plugin-react';
import serveStatic from 'serve-static';
import { defineConfig } from 'vite';
import { resolve } from 'path';
/**
* Vite plugins to serves contents of `packages/file-types/zarr/fixtures` during testing.
* Reference: https://github.com/hms-dbmi/viv/blob/d8b0ae/sites/avivator/vite.config.js#L12
*/
export function serveTestFixtures() {
const serveOptions = {
setHeaders: (res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
},
dotfiles: 'allow',
acceptRanges: true,
immutable: true,
index: false,
maxAge: 1000 * 60 * 60 * 24, // 24 hours
};
const dirZarr = resolve(__dirname, './packages/file-types/zarr/fixtures');
const serveZarr = serveStatic(dirZarr, serveOptions);
const dirJson = resolve(__dirname, './packages/file-types/json/src/legacy-loaders/schemas/fixtures');
const serveJson = serveStatic(dirJson, serveOptions);
const dirVitS = resolve(__dirname, './packages/vit-s/src/schemas/fixtures');
const serveVitS = serveStatic(dirVitS, serveOptions);
return {
name: 'serve-test-fixtures-dir',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (/^\/@fixtures\/zarr\//.test(req.url)) {
req.url = req.url.replace('/@fixtures/zarr/', '');
serveZarr(req, res, next);
} else if (/^\/@fixtures\/json-legacy\//.test(req.url)) {
req.url = req.url.replace('/@fixtures/json-legacy/', '');
serveJson(req, res, next);
} else if (/^\/@fixtures\/vit-s\//.test(req.url)) {
req.url = req.url.replace('/@fixtures/vit-s/', '');
serveVitS(req, res, next);
} else {
next();
}
});
}
};
}
// For tests.
export default defineConfig({
plugins: [
react({
jsxRuntime: 'classic',
}),
serveTestFixtures(),
],
test: {
api: 51204,
passWithNoTests: true,
testTimeout: 15000,
globals: true,
environment: 'jsdom',
setupFiles: [resolve(__dirname, './vitest.setup.js')],
environmentOptions: {
jsdom: {
resources: 'usable',
},
},
// Only run test files that are within src/
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
// To enable .js files that contain JSX to be imported by Vitest tests.
// Reference: https://github.com/vitest-dev/vitest/issues/1564
esbuild: {
loader: 'tsx',
include: /src\/.*\.[tj]sx?$/,
exclude: [],
},
});