Skip to content

Commit cca1f93

Browse files
committed
test: Polyfill tests like the server does
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 36fa7c4 commit cca1f93

File tree

5 files changed

+58
-32
lines changed

5 files changed

+58
-32
lines changed

package-lock.json

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"@vue/test-utils": "^1.3.6",
8484
"@vue/tsconfig": "^0.5.1",
8585
"@zamiell/typedoc-plugin-not-exported": "^0.3.0",
86+
"core-js": "^3.39.0",
8687
"gettext-extractor": "^3.8.0",
8788
"gettext-parser": "^8.0.0",
8889
"happy-dom": "^14.12.3",

test/setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: CC0-1.0
4+
*/
5+
6+
// Polyfill like the server does
7+
import 'core-js/stable/index.js'

vite.config.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,6 @@ export default defineConfig((env) => {
3131
// Fix for vite config, TODO: remove with next release
3232
cssCodeSplit: false,
3333
},
34-
// vitest configuration
35-
test: {
36-
environment: 'happy-dom',
37-
coverage: {
38-
all: true,
39-
provider: 'v8',
40-
include: ['lib/**/*.ts', 'lib/*.ts'],
41-
exclude: ['lib/**/*.spec.ts'],
42-
},
43-
css: {
44-
modules: {
45-
classNameStrategy: 'non-scoped',
46-
},
47-
},
48-
server: {
49-
deps: {
50-
inline: [
51-
/@nextcloud\/vue/, // Fix unresolvable .css extension for ssr
52-
/@nextcloud\/files/, // Fix CommonJS cancelable-promise not supporting named exports
53-
],
54-
},
55-
},
56-
},
5734
},
5835
// We build for ESM and legacy common js
5936
libraryFormats: ['es', 'cjs'],

vitest.config.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,41 @@
33
* SPDX-License-Identifier: CC0-1.0
44
*/
55
import type { ConfigEnv } from 'vite'
6+
import { defineConfig, type ViteUserConfig } from 'vitest/config'
67
import config from './vite.config'
78

8-
export default async (env: ConfigEnv) => {
9+
export default defineConfig(async (env: ConfigEnv): Promise<ViteUserConfig> => {
910
const cfg = await config(env)
10-
// filter node-externals which will interfere with vitest
11-
cfg.plugins = cfg.plugins!.filter((plugin) => plugin && (!('name' in plugin) || plugin.name !== 'node-externals'))
12-
return cfg
13-
}
11+
12+
return {
13+
...cfg,
14+
15+
// filter node-externals which will interfere with vitest
16+
plugins: cfg.plugins!.filter((plugin) => plugin && (!('name' in plugin) || plugin.name !== 'node-externals')),
17+
18+
// vitest configuration
19+
test: {
20+
environment: 'happy-dom',
21+
coverage: {
22+
all: true,
23+
provider: 'v8',
24+
include: ['lib/**/*.ts', 'lib/*.ts'],
25+
exclude: ['lib/**/*.spec.ts'],
26+
},
27+
css: {
28+
modules: {
29+
classNameStrategy: 'non-scoped',
30+
},
31+
},
32+
setupFiles: 'test/setup.ts',
33+
server: {
34+
deps: {
35+
inline: [
36+
/@nextcloud\/vue/, // Fix unresolvable .css extension for ssr
37+
/@nextcloud\/files/, // Fix CommonJS cancelable-promise not supporting named exports
38+
],
39+
},
40+
},
41+
},
42+
}
43+
})

0 commit comments

Comments
 (0)