Skip to content

Commit

Permalink
Merge pull request #1600 from nextcloud-libraries/tests/await-expect
Browse files Browse the repository at this point in the history
test: adjust config for vitest v3 and await expect
  • Loading branch information
susnux authored Feb 22, 2025
2 parents 21e3745 + 0dfdbc1 commit a4fbfce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions __tests__/uploader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
})
})

Expand Down Expand Up @@ -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)
})
})
})
38 changes: 18 additions & 20 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

0 comments on commit a4fbfce

Please sign in to comment.