๐Ÿ“ฆ mui / mui-x

๐Ÿ“„ vitest.shared.mts ยท 109 lines
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import { playwright } from '@vitest/browser-playwright';

const CURRENT_DIR = dirname(fileURLToPath(import.meta.url));
const WORKSPACE_ROOT = resolve(CURRENT_DIR, './');

export const alias = [
  // Generates resolver aliases for all packages and their plans.
  ...[
    { lib: 'x-charts', plans: ['pro', 'premium'] },
    { lib: 'x-date-pickers', plans: ['pro'] },
    { lib: 'x-tree-view', plans: ['pro'] },
    { lib: 'x-data-grid', plans: ['pro', 'premium', 'generator'] },
    { lib: 'x-scheduler' },
    { lib: 'x-scheduler-headless' },
    { lib: 'x-internals' },
    { lib: 'x-internal-gestures' },
    { lib: 'x-license' },
    { lib: 'x-telemetry' },
    { lib: 'x-virtualizer' },
  ].flatMap((v) => {
    return [
      {
        find: `@mui/${v.lib}`,
        replacement: resolve(WORKSPACE_ROOT, `./packages/${v.lib}/src`),
      },
      ...(v.plans ?? []).map((plan) => ({
        find: `@mui/${v.lib}-${plan}`,
        replacement: resolve(WORKSPACE_ROOT, `./packages/${v.lib}-${plan}/src`),
      })),
    ];
  }),
  {
    find: 'test/utils',
    replacement: fileURLToPath(new URL('./test/utils', import.meta.url)),
  },
];

export default defineConfig({
  // If enabling babel plugins, ensure the tests in CI are stable
  // https://github.com/mui/mui-x/pull/18341
  plugins: [react()],
  // We seem to need both this and the `env` property below to make it work.
  define: {
    'process.env.NODE_ENV': '"test"',
    LICENSE_DISABLE_CHECK: 'false',
  },
  esbuild: {
    minifyIdentifiers: false,
    keepNames: true,
  },
  resolve: {
    alias,
  },
  test: {
    globals: true,
    setupFiles: [fileURLToPath(new URL('test/setupVitest.ts', import.meta.url))],
    // Required for some tests that contain early returns or conditional tests.
    passWithNoTests: true,
    env: {
      NODE_ENV: 'test',
      VITEST: 'true',
    },
    browser: {
      provider: playwright({
        launchOptions: {
          // Required for tests which use scrollbars.
          ignoreDefaultArgs: ['--hide-scrollbars'],
        },
        ...(process.env.PLAYWRIGHT_SERVER_WS
          ? {
              connectOptions: {
                wsEndpoint: process.env.PLAYWRIGHT_SERVER_WS,
              },
            }
          : {}),
      }),
      viewport: { width: 1280, height: 800 },
      headless: true,
      screenshotFailures: false,
      orchestratorScripts: [
        {
          id: 'vitest-reload-on-error',
          content: `window.addEventListener('vite:preloadError', (event) => { window.location.reload(); });`,
          async: true,
        },
      ],
    },
    // Disable isolation to speed up the tests.
    isolate: false,
    // Performance improvements for the tests.
    // https://vitest.dev/guide/improving-performance.html#improving-performance
    ...(process.env.CI && {
      // Important to avoid timeouts on CI.
      fileParallelism: false,
      // Increase the timeout for the tests due to slow CI machines.
      testTimeout: 30000,
      // Retry failed tests up to 3 times. This is useful for flaky tests.
      retry: 3,
      // Reduce the number of workers to avoid CI timeouts.
      maxWorkers: 1,
    }),
    exclude: ['**/*.spec.{js,ts,tsx}', '**/node_modules/**', '**/dist/**'],
  },
});