-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.config.ts
More file actions
55 lines (52 loc) · 1.64 KB
/
Copy pathvitest.config.ts
File metadata and controls
55 lines (52 loc) · 1.64 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
import { defineConfig, type Plugin } from 'vitest/config';
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
import { playwright } from '@vitest/browser-playwright';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const dirname = path.dirname(fileURLToPath(import.meta.url));
// The Storybook preview.ts imports individual components from
// dist/components/ (dist-custom-elements output). That output is only
// available after a full `stencil build`, not after `stencil-test` dev
// builds. During vitest runs the lazy-loader in vitest-setup.ts already
// registers every component, so we stub the custom-element imports out.
function stubDistCustomElements(): Plugin {
const stubCode = 'export function defineCustomElement() {}';
return {
name: 'stub-dist-custom-elements',
enforce: 'pre',
resolveId(id, importer) {
if (importer && id.includes('dist/components/') && id.endsWith('.js')) {
return '\0stub-define-custom-element';
}
},
load(id) {
if (id === '\0stub-define-custom-element') {
return stubCode;
}
},
};
}
export default defineConfig({
test: {
projects: [
{
plugins: [
stubDistCustomElements(),
storybookTest({
configDir: path.join(dirname, '.storybook'),
}),
],
test: {
name: 'storybook',
browser: {
enabled: true,
provider: playwright(),
headless: true,
instances: [{ browser: 'chromium' }],
},
setupFiles: ['./.storybook/vitest.setup.ts'],
},
},
],
},
});