diff --git a/Makefile b/Makefile index 4fe42ff80d..0ddb21e8fa 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,6 @@ appstore: rm -rf $(build_dir) mkdir -p $(sign_dir) rsync -a \ - --exclude=babel.config.js \ --exclude=/build \ --exclude=composer.patches.json \ --exclude=docs \ @@ -85,8 +84,7 @@ appstore: --exclude=.gitattributes \ --exclude=.github \ --exclude=.gitignore \ - --exclude=jest.config.js \ - --exclude=jest.global.setup.js \ + --exclude=vitest.config.js \ --exclude=.l10nignore \ --exclude=mkdocs.yml \ --exclude=Makefile \ diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index 6f249242ab..0000000000 --- a/babel.config.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -const babelConfig = require('@nextcloud/babel-config') - -module.exports = babelConfig diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 28ebc92df8..0000000000 --- a/jest.config.js +++ /dev/null @@ -1,100 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -const { resolve } = require('node:path') - -// Listed packages will be transformed with babel-jest -// TODO: find a way to consolidate this in one place, with webpack.common.js -const ignorePatterns = [ - '@nextcloud/dialogs', - '@nextcloud/vue', - '@mdi/svg', - '@vueuse/core', - '@vueuse/router', - '@vueuse/shared', - 'bail', - 'ccount', // ESM dependency of remark-gfm - 'comma-separated-tokens', - 'decode-named-character-reference', - 'devlop', - 'escape-string-regexp', - 'hast-.*', - 'is-.*', - 'longest-streak', // ESM dependency of remark-gfm - 'markdown-table', // ESM dependency of remark-gfm - 'mdast-.*', - 'micromark', - 'property-information', - 'rehype-.*', - 'remark-.*', - 'space-separated-tokens', - 'trim-lines', - 'trough', - 'unified', - 'unist-.*', - 'vfile', - 'vue-material-design-icons', - 'web-namespaces', - 'zwitch', // ESM dependency of remark-gfm -] - -module.exports = { - - // Allow tests in the src and in tests/unit folders - testMatch: ['/src/**/*.(spec|test).(ts|js)'], - // FIXME Skip tests using @nextcloud/dialogs, @nextcloud/vue, @nextcloud/upload - testPathIgnorePatterns: [ - '/src/components', - '/src/store/fileUploadStore.spec.js', - ], - // Transform packages from top-level and nested 'node_modules' - transformIgnorePatterns: [ - `/node_modules/(?!(?:.*\\/node_modules\\/)?(?:${ignorePatterns.join('|')}))`, - ], - resetMocks: false, - setupFiles: [], - setupFilesAfterEnv: [ - '/src/test-setup.js', - ], - globalSetup: resolve(__dirname, 'jest.global.setup.js'), - - collectCoverageFrom: [ - '/src/**/*.{js,ts,vue}', - ], - - testEnvironment: 'jest-environment-jsdom', - testEnvironmentOptions: { - customExportConditions: ['node', 'node-addons'], - }, - - moduleFileExtensions: [ - 'js', - 'mjs', - 'ts', - 'vue', - ], - - moduleNameMapper: { - '\\.(css|scss)$': 'jest-transform-stub', - '^.+\\.svg(\\?raw)?$': '/src/__mocks__/svg.js', - 'vendor/tflite/(.*).wasm$': '/src/utils/media/effects/virtual-background/vendor/tflite/$1.js', - '@matrix-org/olm/(.*).wasm$': '/node_modules/@matrix-org/olm/$1.js', - '^@nextcloud/dialogs': '/node_modules/@nextcloud/dialogs/dist/index.mjs', - '^@nextcloud/vue/(.*)/(.*)$': '/node_modules/@nextcloud/vue/dist/$1/$2/index.mjs', - }, - - transform: { - '\\.ts$': ['ts-jest', { - useESM: true, - tsconfig: { - verbatimModuleSyntax: false, - }, - }], - '\\.(js|mjs)$': 'babel-jest', - '\\.vue$': '@vue/vue3-jest', - '\\.tflite$': 'jest-transform-stub', - '\\.(css|scss)$': 'jest-transform-stub', - }, -} diff --git a/jest.global.setup.js b/jest.global.setup.js deleted file mode 100644 index c86c92ea27..0000000000 --- a/jest.global.setup.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -module.exports = () => { - process.env.TZ = 'UTC' -} diff --git a/package.json b/package.json index 57e978e917..bb7e34559e 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,8 @@ "serve": "node --max-old-space-size=4096 ./node_modules/webpack/bin/webpack.js serve --node-env development --progress --allowed-hosts all", "stylelint": "stylelint \"css/*.css\" \"css/*.scss\" \"src/**/*.scss\" \"src/**/*.vue\"", "stylelint:fix": "stylelint \"css/*.css\" \"css/*.scss\" \"src/**/*.scss\" \"src/**/*.vue\" --fix", - "test": "jest", - "test:coverage": "jest --coverage", - "test:watch": "jest --watch", + "test": "vitest", + "test:coverage": "vitest run --coverage", "typescript:check": "vue-tsc --noEmit", "typescript:generate": "npx openapi-typescript -t", "typescript:generate-core-types": "./src/types/generate-core-types.sh", diff --git a/src/test-global-setup.js b/src/test-global-setup.js new file mode 100644 index 0000000000..d97c2a3954 --- /dev/null +++ b/src/test-global-setup.js @@ -0,0 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/** + * Vitest global setup + */ +export default function setup() { + process.env.TZ = 'UTC' +} diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 0000000000..aa54d4fdc9 --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,42 @@ +/* + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import vue from '@vitejs/plugin-vue' +import { resolve } from 'node:path' +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + plugins: [vue()], + assetsInclude: ['**/*.tflite', '**/*.wasm'], + test: { + include: ['src/**/*.{test,spec}.?(c|m)[jt]s?(x)'], + exclude: [ + // TODO: migrate to Vue 3 + 'src/components/**', + // FIXME: broken after Vue 3 migration + 'src/store/fileUploadStore.spec.js', + ], + server: { + deps: { + // Allow importing CSS from dependencies + inline: ['@nextcloud/vue'], + }, + }, + alias: [ + { find: './vendor/tflite/tflite.wasm', replacement: resolve(import.meta.dirname, 'src/utils/media/effects/virtual-background/vendor/tflite/tflite.js') }, + { find: './vendor/tflite/tflite-simd.wasm', replacement: resolve(import.meta.dirname, 'src/utils/media/effects/virtual-background/vendor/tflite/tflite-simd.js') }, + { find: '@matrix-org/olm/olm.wasm', replacement: '@matrix-org/olm/olm.js' }, + ], + globals: true, + environment: 'jsdom', + environmentOptions: { + jsdom: { + url: 'http://localhost', + }, + }, + setupFiles: ['src/test-setup.js'], + globalSetup: 'src/test-global-setup.js', + }, +})