Skip to content

Commit

Permalink
test: Polyfill tests like the server does
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Nov 4, 2024
1 parent 36fa7c4 commit cca1f93
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 32 deletions.
19 changes: 15 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@vue/test-utils": "^1.3.6",
"@vue/tsconfig": "^0.5.1",
"@zamiell/typedoc-plugin-not-exported": "^0.3.0",
"core-js": "^3.39.0",
"gettext-extractor": "^3.8.0",
"gettext-parser": "^8.0.0",
"happy-dom": "^14.12.3",
Expand Down
7 changes: 7 additions & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: CC0-1.0
*/

// Polyfill like the server does
import 'core-js/stable/index.js'
23 changes: 0 additions & 23 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,6 @@ export default defineConfig((env) => {
// Fix for vite config, TODO: remove with next release
cssCodeSplit: false,
},
// vitest configuration
test: {
environment: 'happy-dom',
coverage: {
all: true,
provider: 'v8',
include: ['lib/**/*.ts', 'lib/*.ts'],
exclude: ['lib/**/*.spec.ts'],
},
css: {
modules: {
classNameStrategy: 'non-scoped',
},
},
server: {
deps: {
inline: [
/@nextcloud\/vue/, // Fix unresolvable .css extension for ssr
/@nextcloud\/files/, // Fix CommonJS cancelable-promise not supporting named exports
],
},
},
},
},
// We build for ESM and legacy common js
libraryFormats: ['es', 'cjs'],
Expand Down
40 changes: 35 additions & 5 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,41 @@
* SPDX-License-Identifier: CC0-1.0
*/
import type { ConfigEnv } from 'vite'
import { defineConfig, type ViteUserConfig } from 'vitest/config'
import config from './vite.config'

export default async (env: ConfigEnv) => {
export default defineConfig(async (env: ConfigEnv): Promise<ViteUserConfig> => {
const cfg = await config(env)
// filter node-externals which will interfere with vitest
cfg.plugins = cfg.plugins!.filter((plugin) => plugin && (!('name' in plugin) || plugin.name !== 'node-externals'))
return cfg
}

return {
...cfg,

// filter node-externals which will interfere with vitest
plugins: cfg.plugins!.filter((plugin) => plugin && (!('name' in plugin) || plugin.name !== 'node-externals')),

// vitest configuration
test: {
environment: 'happy-dom',
coverage: {
all: true,
provider: 'v8',
include: ['lib/**/*.ts', 'lib/*.ts'],
exclude: ['lib/**/*.spec.ts'],
},
css: {
modules: {
classNameStrategy: 'non-scoped',
},
},
setupFiles: 'test/setup.ts',
server: {
deps: {
inline: [
/@nextcloud\/vue/, // Fix unresolvable .css extension for ssr
/@nextcloud\/files/, // Fix CommonJS cancelable-promise not supporting named exports
],
},
},
},
}
})

0 comments on commit cca1f93

Please sign in to comment.