diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-04-22 12:19:58 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-04-29 10:15:29 +0200 |
commit | 0e50ba839c878e1e4eedaf7b72303ed2134cffd4 (patch) | |
tree | 619dd8f60f5cc76d649ea2be480bc06b9e7ef78c | |
parent | f9b6b88d5ce4fbd69bafea63b350c1cb0f3c8465 (diff) | |
download | nextcloud-server-test/no-git-ignore.tar.gz nextcloud-server-test/no-git-ignore.zip |
test: ignore git-ignored files from teststest/no-git-ignore
Fix running `npm run test` when your development setup has other apps
checked out - like having the viewer app installed locally in `apps`.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | build/files-checker.php | 2 | ||||
-rw-r--r-- | vitest.config.mts | 57 | ||||
-rw-r--r-- | vitest.config.ts | 35 |
3 files changed, 58 insertions, 36 deletions
diff --git a/build/files-checker.php b/build/files-checker.php index 2282b525a4d..4cbd0874247 100644 --- a/build/files-checker.php +++ b/build/files-checker.php @@ -85,7 +85,7 @@ $expectedFiles = [ 'tsconfig.json', 'vendor-bin', 'version.php', - 'vitest.config.ts', + 'vitest.config.mts', 'webpack.common.js', 'webpack.config.js', 'webpack.modules.js', diff --git a/vitest.config.mts b/vitest.config.mts new file mode 100644 index 00000000000..4fe5bd4d32f --- /dev/null +++ b/vitest.config.mts @@ -0,0 +1,57 @@ +/** + * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: CC0-1.0 + */ +import { defaultExclude, defineConfig } from 'vitest/config' +import vue from '@vitejs/plugin-vue2' +import { exec } from 'node:child_process' +import { promisify } from 'node:util' + +const gitIgnore: string[] = [] +// get all files ignored in the apps directory (e.g. if putting `view` app there). +try { + const execAsync = promisify(exec) + const { stdout } = await execAsync('git check-ignore apps/*', { cwd: __dirname }) + gitIgnore.push(...stdout.split('\n').filter(Boolean)) + // eslint-disable-next-line no-console + console.log('Git ignored files excluded from tests: ', gitIgnore) +} catch (error) { + // we can ignore error code 1 as this just means there are no ignored files + if (error.code !== 1) { + // but otherwise something bad is happening and we should re-throw + throw error + } +} + +export default defineConfig({ + plugins: [vue()], + test: { + include: ['{apps,core}/**/*.{test,spec}.?(c|m)[jt]s?(x)'], + environment: 'jsdom', + environmentOptions: { + jsdom: { + url: 'http://nextcloud.local', + }, + }, + coverage: { + include: ['apps/*/src/**', 'core/src/**'], + exclude: ['**.spec.*', '**.test.*', '**.cy.*', 'core/src/tests/**'], + provider: 'v8', + reporter: ['lcov', 'text'], + }, + setupFiles: [ + '__tests__/mock-window.js', + '__tests__/setup-testing-library.js', + ], + exclude: [ + ...defaultExclude, + ...gitIgnore, + ], + globalSetup: '__tests__/setup-global.js', + server: { + deps: { + inline: [/@nextcloud\//], + }, + }, + }, +}) diff --git a/vitest.config.ts b/vitest.config.ts deleted file mode 100644 index 690598d9053..00000000000 --- a/vitest.config.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: CC0-1.0 - */ -import { defineConfig } from 'vitest/config' -import vue from '@vitejs/plugin-vue2' - -export default defineConfig({ - plugins: [vue()], - test: { - include: ['{apps,core}/**/*.{test,spec}.?(c|m)[jt]s?(x)'], - environment: 'jsdom', - environmentOptions: { - jsdom: { - url: 'http://nextcloud.local', - }, - }, - coverage: { - include: ['apps/*/src/**', 'core/src/**'], - exclude: ['**.spec.*', '**.test.*', '**.cy.*', 'core/src/tests/**'], - provider: 'v8', - reporter: ['lcov', 'text'], - }, - setupFiles: [ - '__tests__/mock-window.js', - '__tests__/setup-testing-library.js', - ], - globalSetup: '__tests__/setup-global.js', - server: { - deps: { - inline: [/@nextcloud\//], - }, - }, - }, -}) |