diff --git a/package-lock.json b/package-lock.json index d5a00294..835de852 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,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", @@ -1444,6 +1445,17 @@ "npm": "^9.0.0" } }, + "node_modules/@nextcloud/browser-storage/node_modules/core-js": { + "version": "3.33.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.33.0.tgz", + "integrity": "sha512-HoZr92+ZjFEKar5HS6MC776gYslNOKHt75mEBKWKnPeFDpZ6nH5OeF3S6HFT1mUAUZKrzkez05VboaX8myjSuw==", + "hasInstallScript": true, + "peer": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/@nextcloud/browserslist-config": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@nextcloud/browserslist-config/-/browserslist-config-3.0.1.tgz", @@ -4344,11 +4356,10 @@ } }, "node_modules/core-js": { - "version": "3.33.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.33.0.tgz", - "integrity": "sha512-HoZr92+ZjFEKar5HS6MC776gYslNOKHt75mEBKWKnPeFDpZ6nH5OeF3S6HFT1mUAUZKrzkez05VboaX8myjSuw==", + "version": "3.39.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.39.0.tgz", + "integrity": "sha512-raM0ew0/jJUqkJ0E6e8UDtl+y/7ktFivgWvqw8dNSQeNWoSDLvQ1H/RN3aPXB9tBd4/FhyR4RDPGhsNIMsAn7g==", "hasInstallScript": true, - "peer": true, "funding": { "type": "opencollective", "url": "https://opencollective.com/core-js" diff --git a/package.json b/package.json index b658f18c..a64a6801 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/setup.ts b/test/setup.ts new file mode 100644 index 00000000..c731e24c --- /dev/null +++ b/test/setup.ts @@ -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' diff --git a/vite.config.ts b/vite.config.ts index b54a55b1..70db91b6 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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'], diff --git a/vitest.config.ts b/vitest.config.ts index 4616f23b..702ca11e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -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 => { 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 + ], + }, + }, + }, + } +})