vite.config.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. import { configDefaults } from 'vitest/config'
  2. import { playwright } from 'vitest/browser-playwright'
  3. import { defineConfig } from 'vite-plus'
  4. import { entries } from './scripts/aliases.js'
  5. export default defineConfig({
  6. define: {
  7. __DEV__: process.env.MODE !== 'benchmark',
  8. __TEST__: true,
  9. __E2E_TEST__: false,
  10. __VERSION__: '"test"',
  11. __BROWSER__: false,
  12. __GLOBAL__: false,
  13. __ESM_BUNDLER__: true,
  14. __ESM_BROWSER__: false,
  15. __CJS__: true,
  16. __SSR__: true,
  17. __BENCHMARK__: false,
  18. __FEATURE_OPTIONS_API__: true,
  19. __FEATURE_SUSPENSE__: true,
  20. __FEATURE_PROD_DEVTOOLS__: false,
  21. __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
  22. __COMPAT__: true,
  23. },
  24. resolve: {
  25. alias: entries,
  26. },
  27. test: {
  28. globals: true,
  29. pool: 'threads',
  30. setupFiles: 'scripts/setup-vitest.ts',
  31. sequence: {
  32. hooks: 'list',
  33. },
  34. coverage: {
  35. provider: 'v8',
  36. reporter: ['text', 'html'],
  37. include: ['packages/*/src/**'],
  38. exclude: [
  39. 'packages/vue-compat/**',
  40. 'packages/vue/src/dev.ts',
  41. 'packages/vue/src/runtime.ts',
  42. 'packages/vue/src/runtime-with-vapor.ts',
  43. 'packages/vue/src/index-with-vapor.ts',
  44. 'packages/runtime-core/src/profiling.ts',
  45. 'packages/runtime-core/src/featureFlags.ts',
  46. 'packages/runtime-core/src/customFormatter.ts',
  47. 'packages/runtime-core/src/hydrationStrategies.ts',
  48. 'packages/runtime-dom/src/components/Transition*',
  49. 'packages/runtime-vapor/src/components/Transition*',
  50. ],
  51. },
  52. projects: [
  53. {
  54. extends: true,
  55. test: {
  56. name: 'unit-gc',
  57. pool: 'forks',
  58. execArgv: ['--expose-gc'],
  59. include: [
  60. 'packages/reactivity/__tests__/gc.spec.ts',
  61. 'packages/server-renderer/__tests__/ssrWatch.spec.ts',
  62. ],
  63. },
  64. },
  65. {
  66. extends: true,
  67. test: {
  68. name: 'unit',
  69. exclude: [
  70. ...configDefaults.exclude,
  71. 'packages/reactivity/__tests__/gc.spec.ts',
  72. 'packages/server-renderer/__tests__/ssrWatch.spec.ts',
  73. '**/e2e/**',
  74. '**/vapor-e2e-test/**',
  75. 'packages/{vue,vue-compat,runtime-dom,runtime-vapor}/**',
  76. ],
  77. },
  78. },
  79. {
  80. extends: true,
  81. test: {
  82. name: 'unit-jsdom',
  83. environment: 'jsdom',
  84. include: [
  85. 'packages/{vue,vue-compat,runtime-dom,runtime-vapor}/**/*.spec.ts',
  86. ],
  87. exclude: [...configDefaults.exclude, '**/e2e/**'],
  88. },
  89. },
  90. {
  91. extends: true,
  92. test: {
  93. name: 'e2e',
  94. environment: 'jsdom',
  95. isolate: true,
  96. include: ['packages/vue/__tests__/e2e/*.spec.ts'],
  97. },
  98. },
  99. // @ts-expect-error - https://github.com/vuejs/core/actions/runs/23430103557/job/68154030981
  100. // When running `vp test --project unit*`, Vitest still initializes all projects (this is
  101. // expected behavior see https://github.com/vitest-dev/vitest/issues/9849) and loads
  102. // `packages-private/vapor-e2e-test/vite.config.ts`. That config immediately imports
  103. // `vue/compiler-sfc`, but the package has not been built yet.
  104. // To work around this, we conditionally include the vapor e2e test project only when the
  105. // `VAPOR_E2E` env variable is set.
  106. // for Vitest VSCode extension, we can set this env variable in the `vitest.nodeEnv` config
  107. // to ensure the vapor e2e tests are included when running tests in VSCode.
  108. // "vitest.nodeEnv": {
  109. // "VAPOR_E2E": "1"
  110. // },
  111. ...(process.env.VAPOR_E2E === '1'
  112. ? [
  113. {
  114. extends: './packages-private/vapor-e2e-test/vite.config.ts',
  115. root: './packages-private/vapor-e2e-test',
  116. test: {
  117. globals: true,
  118. isolate: true,
  119. name: 'e2e-vapor',
  120. setupFiles: ['./__tests__/setupBrowser.ts'],
  121. browser: {
  122. enabled: true,
  123. provider: playwright({
  124. launchOptions: {
  125. args: process.env.CI
  126. ? ['--no-sandbox', '--disable-setuid-sandbox']
  127. : [],
  128. },
  129. }),
  130. headless: true,
  131. screenshotFailures: false,
  132. instances: [{ browser: 'chromium' }],
  133. },
  134. include: ['./__tests__/*.spec.ts'],
  135. },
  136. },
  137. ]
  138. : []),
  139. ],
  140. onConsoleLog(log) {
  141. if (log.startsWith('You are running a development build of Vue.')) {
  142. return false
  143. }
  144. },
  145. },
  146. staged: {
  147. '*.{js,json}': ['vp fmt --no-error-on-unmatched-pattern'],
  148. '*.ts?(x)': ['vp lint --fix', 'vp fmt --no-error-on-unmatched-pattern'],
  149. },
  150. lint: {
  151. categories: {
  152. correctness: 'off',
  153. },
  154. env: {
  155. builtin: true,
  156. },
  157. ignorePatterns: [
  158. '**/dist/',
  159. '**/temp/',
  160. '**/coverage/',
  161. 'dts-build/packages',
  162. ],
  163. overrides: [
  164. {
  165. files: ['**/*.js', '**/*.ts', '**/*.tsx'],
  166. rules: {
  167. 'no-debugger': 'error',
  168. 'no-console': [
  169. 'error',
  170. {
  171. allow: ['warn', 'error', 'info'],
  172. },
  173. ],
  174. 'no-restricted-globals': [
  175. 'error',
  176. 'window',
  177. 'document',
  178. 'module',
  179. 'require',
  180. ],
  181. 'sort-imports': [
  182. 'error',
  183. {
  184. ignoreDeclarationSort: true,
  185. },
  186. ],
  187. '@typescript-eslint/prefer-ts-expect-error': 'error',
  188. '@typescript-eslint/consistent-type-imports': [
  189. 'error',
  190. {
  191. fixStyle: 'inline-type-imports',
  192. disallowTypeAnnotations: false,
  193. },
  194. ],
  195. '@typescript-eslint/no-import-type-side-effects': 'error',
  196. },
  197. },
  198. {
  199. files: ['packages/shared/**'],
  200. rules: {
  201. 'no-restricted-globals': 'off',
  202. },
  203. },
  204. {
  205. files: ['packages/{vue,vue-compat,runtime-*}/**'],
  206. rules: {
  207. 'no-restricted-globals': ['error', 'module', 'require'],
  208. 'oxc/no-optional-chaining': 'error',
  209. },
  210. },
  211. {
  212. files: ['packages/{compiler-*,server-renderer}/**'],
  213. rules: {
  214. 'no-restricted-globals': ['error', 'window', 'document'],
  215. 'oxc/no-const-enum': 'error',
  216. },
  217. },
  218. {
  219. files: [
  220. 'packages-private/template-explorer/**',
  221. 'packages-private/sfc-playground/**',
  222. ],
  223. rules: {
  224. 'no-restricted-globals': ['error', 'module', 'require'],
  225. 'oxc/no-const-enum': 'error',
  226. 'no-console': 'off',
  227. },
  228. },
  229. {
  230. files: ['*.js'],
  231. rules: {
  232. 'no-unused-vars': [
  233. 'error',
  234. {
  235. vars: 'all',
  236. args: 'none',
  237. },
  238. ],
  239. },
  240. },
  241. {
  242. files: [
  243. '**/__tests__/**',
  244. 'packages-private/dts-test/**',
  245. 'packages-private/dts-build-test/**',
  246. ],
  247. rules: {
  248. 'no-console': 'off',
  249. 'no-restricted-globals': 'off',
  250. 'no-unused-vars': 'off',
  251. 'oxc/no-optional-chaining': 'off',
  252. },
  253. globals: {
  254. suite: 'writable',
  255. test: 'writable',
  256. describe: 'writable',
  257. it: 'writable',
  258. expectTypeOf: 'writable',
  259. assertType: 'writable',
  260. expect: 'writable',
  261. assert: 'writable',
  262. chai: 'writable',
  263. vitest: 'writable',
  264. vi: 'writable',
  265. beforeAll: 'writable',
  266. afterAll: 'writable',
  267. beforeEach: 'writable',
  268. afterEach: 'writable',
  269. onTestFailed: 'writable',
  270. onTestFinished: 'writable',
  271. },
  272. },
  273. {
  274. files: [
  275. 'scripts/**',
  276. './*.{js,ts}',
  277. 'packages/*/*.js',
  278. 'packages/vue/*/*.js',
  279. 'packages-private/benchmark/*',
  280. 'packages-private/e2e-utils/*',
  281. ],
  282. rules: {
  283. 'no-restricted-globals': 'off',
  284. 'oxc/no-const-enum': 'error',
  285. 'no-console': 'off',
  286. },
  287. },
  288. ],
  289. },
  290. fmt: {
  291. semi: false,
  292. singleQuote: true,
  293. arrowParens: 'avoid',
  294. printWidth: 80,
  295. experimentalSortPackageJson: false,
  296. ignorePatterns: ['dist', 'CHANGELOG*.md', '*.toml'],
  297. },
  298. })