-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.js
More file actions
123 lines (120 loc) · 4.09 KB
/
Copy pathvitest.config.js
File metadata and controls
123 lines (120 loc) · 4.09 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* SPDX-FileCopyrightText: 2026 Conduction / Dossiq Contributors
* SPDX-License-Identifier: EUPL-1.2
*
* Vitest configuration for Dossiq frontend unit tests.
*
* The bulk of the suite targets PURE calc/util logic under `src/utils/**`
* (SLA compliance, processing-time distribution, ISO 8601 duration parsing,
* workflow-graph validation) that is exercised end-to-end only through
* rendered dashboards — the exact computed numbers are not asserted
* anywhere else. These functions need no DOM, so the DEFAULT environment is
* `node`.
*
* A small number of component smoke tests (workflow editor: renders a
* definition, blocks save on invalid) need a real DOM + Vue 3 SFC
* compilation. Rather than switching every test to the heavier jsdom
* environment, those spec files opt in per-file via a
* `// @vitest-environment jsdom` pragma comment (Vitest reads this from the
* file itself) — see `tests/vitest/workflowEditorSmoke.spec.js`. The Vue 3
* SFC plugin (`@vitejs/plugin-vue`) + a CSS-noop plugin (recipe mirrors
* openbuild/vitest.config.js, the sibling app that already solved `.vue` +
* `@nextcloud/vue` CSS side-effect imports under Vitest on Vue 3) are
* registered unconditionally — they are inert for the node-environment
* tests, which never import a `.vue` file.
*
* NOTE(vue3): this file used to register `@vitejs/plugin-vue2`, and
* `tests/vitest/setup.js` used to call `Vue.mixin()` on a DEFAULT import
* from `vue`. `vue@3` publishes no default export, so that threw
* `Cannot read properties of undefined (reading 'mixin')` in the setup
* file — which Vitest runs before EVERY spec — and all 32 spec files
* errored during collection with `Tests: no tests`. The whole suite had
* been dead since the Vue 3 migration and nothing noticed, because no
* app's JS unit suite had ever been wired into CI.
*
* `@nextcloud/l10n` is aliased to a deterministic stub (English source string
* + {placeholder} substitution) so translated output is assertable.
*/
const path = require('path')
const vue = require('@vitejs/plugin-vue')
/**
* Side-effect imports of `*.css` from `@nextcloud/vue` (and friends) crash
* Vite's transform pipeline because those CSS files don't exist on disk —
* they are produced by a parallel vite build and referenced via tree-shaken
* `import './foo.css'` lines that survive transpilation. A small plugin
* intercepts `*.css` resolution and returns a virtual empty module so unit
* tests can mount components without ever loading a stylesheet.
*/
const cssNoop = {
name: 'dossiq-css-noop',
enforce: 'pre',
resolveId(id) {
if (typeof id === 'string' && /\.css(\?.*)?$/.test(id)) {
return '\0virtual:css-noop'
}
return null
},
load(id) {
if (id === '\0virtual:css-noop') {
return 'export default {}'
}
return null
},
}
module.exports = {
plugins: [cssNoop, vue.default ? vue.default() : vue()],
test: {
environment: 'node',
globals: false,
include: ['tests/vitest/**/*.spec.{js,ts}'],
exclude: [
'tests/e2e/**',
'tests/zgw/**',
'tests/Unit/**',
'tests/unit/**',
'node_modules/**',
],
setupFiles: [path.resolve(__dirname, 'tests/vitest/setup.js')],
server: {
deps: {
// Inline Vue 2 + Nextcloud packages so Vite transforms their
// .css side-effect imports through the cssNoop plugin above,
// for the (jsdom-opted-in) component specs that import them.
inline: [/@nextcloud\/vue/, /vue-material-design-icons/],
},
},
},
resolve: {
alias: [
{ find: '@', replacement: path.resolve(__dirname, 'src') },
{
find: /^@nextcloud\/l10n$/,
replacement: path.resolve(
__dirname,
'tests/vitest/stubs/nextcloud-l10n.js',
),
},
{
find: /^@nextcloud\/axios$/,
replacement: path.resolve(
__dirname,
'tests/vitest/stubs/nextcloud-axios.js',
),
},
{
find: /^@nextcloud\/router$/,
replacement: path.resolve(
__dirname,
'tests/vitest/stubs/nextcloud-router.js',
),
},
{
find: /^@conduction\/nextcloud-vue$/,
replacement: path.resolve(
__dirname,
'tests/vitest/stubs/conduction-nextcloud-vue.js',
),
},
],
},
}