|
1 | 1 | import path from 'path'; |
2 | 2 | import topLevelAwait from 'vite-plugin-top-level-await'; |
3 | 3 | import wasm from 'vite-plugin-wasm'; |
4 | | -import { defineConfig, UserConfigExport } from 'vitest/config'; |
| 4 | +import { defineConfig, ViteUserConfigExport } from 'vitest/config'; |
5 | 5 |
|
6 | | -const config: UserConfigExport = { |
7 | | - server: { |
8 | | - headers: { |
9 | | - 'Cross-Origin-Opener-Policy': 'same-origin', |
10 | | - 'Cross-Origin-Embedder-Policy': 'require-corp' |
11 | | - } |
12 | | - }, |
13 | | - // This is only needed for local tests to resolve the package name correctly |
14 | | - resolve: { |
15 | | - alias: { |
16 | | - /** |
17 | | - * Note that this requires the Typescript to be compiled with `tsc` |
18 | | - * first. This is required due to the format of Webworker URIs |
19 | | - * they link to `.js` files. |
20 | | - */ |
21 | | - '@powersync/web': path.resolve(__dirname, './lib/src'), |
22 | | - // https://jira.mongodb.org/browse/NODE-5773 |
23 | | - bson: require.resolve('bson') |
24 | | - } |
25 | | - }, |
26 | | - worker: { |
27 | | - format: 'es', |
28 | | - plugins: () => [wasm(), topLevelAwait()] |
29 | | - }, |
30 | | - optimizeDeps: { |
31 | | - // Don't optimise these packages as they contain web workers and WASM files. |
32 | | - // https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673 |
33 | | - exclude: ['@journeyapps/wa-sqlite', '@powersync/web'], |
34 | | - include: ['bson', 'comlink', 'async-mutex'] |
35 | | - }, |
36 | | - plugins: [wasm(), topLevelAwait()], |
37 | | - test: { |
38 | | - globals: true, |
39 | | - include: ['tests/**/*.test.ts'], |
40 | | - maxConcurrency: 1, |
41 | | - // This doesn't currently seem to work in browser mode, but setting this for one day when it does |
42 | | - sequence: { |
43 | | - shuffle: false, // Disable shuffling of test files |
44 | | - concurrent: false // Run test files sequentially |
| 6 | +export default defineConfig(async () => { |
| 7 | + // Import of an ES module is not directly supported since we don't yet define this package directly as an ES module |
| 8 | + const { playwright } = await import('@vitest/browser-playwright'); |
| 9 | + |
| 10 | + return { |
| 11 | + server: { |
| 12 | + headers: { |
| 13 | + 'Cross-Origin-Opener-Policy': 'same-origin', |
| 14 | + 'Cross-Origin-Embedder-Policy': 'require-corp' |
| 15 | + } |
| 16 | + }, |
| 17 | + // This is only needed for local tests to resolve the package name correctly |
| 18 | + resolve: { |
| 19 | + alias: { |
| 20 | + /** |
| 21 | + * Note that this requires the Typescript to be compiled with `tsc` |
| 22 | + * first. This is required due to the format of Webworker URIs |
| 23 | + * they link to `.js` files. |
| 24 | + */ |
| 25 | + '@powersync/web': path.resolve(__dirname, './lib/src'), |
| 26 | + // https://jira.mongodb.org/browse/NODE-5773 |
| 27 | + bson: require.resolve('bson') |
| 28 | + } |
45 | 29 | }, |
46 | | - browser: { |
47 | | - enabled: true, |
48 | | - /** |
49 | | - * Starts each test in a new iFrame |
50 | | - */ |
51 | | - isolate: true, |
52 | | - provider: 'playwright', |
53 | | - headless: true, |
54 | | - instances: [ |
55 | | - { |
56 | | - browser: 'chromium' |
57 | | - } |
58 | | - // { |
59 | | - // browser: 'firefox' |
60 | | - // } |
61 | | - // This requires some additional work to get all tests passing |
62 | | - // { |
63 | | - // browser: 'webkit' |
64 | | - // } |
65 | | - ] |
| 30 | + worker: { |
| 31 | + format: 'es', |
| 32 | + plugins: () => [wasm(), topLevelAwait()] |
| 33 | + }, |
| 34 | + optimizeDeps: { |
| 35 | + // Don't optimise these packages as they contain web workers and WASM files. |
| 36 | + // https://github.com/vitejs/vite/issues/11672#issuecomment-1415820673 |
| 37 | + exclude: ['@journeyapps/wa-sqlite', '@powersync/web'], |
| 38 | + include: ['bson', 'comlink', 'async-mutex'] |
| 39 | + }, |
| 40 | + plugins: [wasm(), topLevelAwait()], |
| 41 | + test: { |
| 42 | + globals: true, |
| 43 | + include: ['tests/**/*.test.ts'], |
| 44 | + maxConcurrency: 1, |
| 45 | + // This doesn't currently seem to work in browser mode, but setting this for one day when it does |
| 46 | + sequence: { |
| 47 | + shuffle: false, // Disable shuffling of test files |
| 48 | + concurrent: false // Run test files sequentially |
| 49 | + }, |
| 50 | + browser: { |
| 51 | + enabled: true, |
| 52 | + /** |
| 53 | + * Starts each test in a new iFrame |
| 54 | + */ |
| 55 | + isolate: true, |
| 56 | + provider: playwright(), |
| 57 | + headless: true, |
| 58 | + instances: [ |
| 59 | + { |
| 60 | + browser: 'chromium' |
| 61 | + } |
| 62 | + // { |
| 63 | + // browser: 'firefox' |
| 64 | + // } |
| 65 | + // This requires some additional work to get all tests passing |
| 66 | + // { |
| 67 | + // browser: 'webkit' |
| 68 | + // } |
| 69 | + ] |
| 70 | + } |
66 | 71 | } |
67 | | - } |
68 | | -}; |
69 | | - |
70 | | -export default defineConfig(config); |
| 72 | + } satisfies ViteUserConfigExport; |
| 73 | +}); |
0 commit comments