From a732367115cd6490e7ff5366687cd044ffb6fe2e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 21 Feb 2025 10:00:18 +0100 Subject: [PATCH 1/2] test: adjust vitest for vitest v3 Signed-off-by: Ferdinand Thiessen --- vitest.config.ts | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/vitest.config.ts b/vitest.config.ts index 10e1cc4e..cf420b1e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -6,25 +6,23 @@ import type { UserConfig } from 'vitest/node' import config from './vite.config.ts' export default async (env) => { - const cfg = await config(env) - // Node externals does not work with vitest - cfg.plugins = cfg.plugins!.filter((plugin) => plugin && 'name' in plugin && plugin.name !== 'node-externals') - - cfg.test = { - environment: 'jsdom', - environmentOptions: { - jsdom: { - url: 'https://cloud.example.com/index.php/apps/test', + return { + ...await config(env), + test: { + environment: 'jsdom', + environmentOptions: { + jsdom: { + url: 'https://cloud.example.com/index.php/apps/test', + }, + }, + setupFiles: '__tests__/setup.ts', + coverage: { + include: ['lib/**'], + // This makes no sense to test + exclude: ['lib/utils/l10n.ts'], + reporter: ['lcov', 'text'], }, - }, - setupFiles: '__tests__/setup.ts', - coverage: { - include: ['lib/**'], - // This makes no sense to test - exclude: ['lib/utils/l10n.ts'], - reporter: ['lcov', 'text'], - }, - pool: 'vmForks', - } as UserConfig - return cfg + pool: 'vmForks', + } as UserConfig, + } } From 0dfdbc10a58cf8ac98a34fb082c07a15053a07cc Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 21 Feb 2025 10:00:41 +0100 Subject: [PATCH 2/2] test: await asynchronous expect call Signed-off-by: Ferdinand Thiessen --- __tests__/uploader.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/uploader.spec.ts b/__tests__/uploader.spec.ts index 645d33ca..0964ddc5 100644 --- a/__tests__/uploader.spec.ts +++ b/__tests__/uploader.spec.ts @@ -46,7 +46,7 @@ describe('Uploader', () => { it('fails if not logged in and not on public share', async () => { vi.spyOn(nextcloudAuth, 'getCurrentUser').mockImplementationOnce(() => null) - expect(async () => new Uploader()).rejects.toThrow(/User is not logged in/) + await expect(async () => new Uploader()).rejects.toThrow(/User is not logged in/) }) }) @@ -119,7 +119,7 @@ describe('Uploader', () => { mime: 'text/plain', }) - expect(() => { uploader.destination = newDestination as nextcloudFiles.Folder }).toThrowError(/invalid destination/i) + expect(() => { uploader.destination = newDestination as unknown as nextcloudFiles.Folder }).toThrowError(/invalid destination/i) }) }) })