-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathvitest.config.ts
More file actions
57 lines (55 loc) · 1.88 KB
/
Copy pathvitest.config.ts
File metadata and controls
57 lines (55 loc) · 1.88 KB
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
import { defineConfig } from 'vitest/config';
import { resolve } from 'path';
import type { Plugin } from 'vite';
// Handle .css imports in tests by returning an empty module.
// Needed because source files import CSS from leaflet plugins directly.
function mockCssPlugin(): Plugin {
return {
name: 'mock-css',
resolveId(id: string) {
if (id.endsWith('.css')) return id;
},
load(id: string) {
if (id.endsWith('.css')) return 'export default {}';
},
};
}
export default defineConfig({
plugins: [mockCssPlugin()],
test: {
environment: 'jsdom',
include: ['tests/**/*.test.ts'],
setupFiles: ['tests/setup.ts'],
},
resolve: {
alias: [
// Obsidian API — not available outside the Obsidian app
{
find: 'obsidian',
replacement: resolve(__dirname, 'tests/__mocks__/obsidian.ts'),
},
// Leaflet plugins with DOM/global side effects — not needed for unit tests
{
find: 'leaflet-extra-markers',
replacement: resolve(
__dirname,
'tests/__mocks__/leaflet-extra-markers.ts',
),
},
{
find: /^leaflet-extra-markers\/.*/,
replacement: resolve(__dirname, 'tests/__mocks__/empty.ts'),
},
{
find: '@geoman-io/leaflet-geoman-free',
replacement: resolve(__dirname, 'tests/__mocks__/empty.ts'),
},
{
find: /^@geoman-io\/leaflet-geoman-free\/.*/,
replacement: resolve(__dirname, 'tests/__mocks__/empty.ts'),
},
// Resolve 'src' prefix to the src directory
{ find: 'src', replacement: resolve(__dirname, 'src') },
],
},
});