Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): fix test.each and describe.each types #1653

Merged
merged 2 commits into from Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/vitest/src/types/tasks.ts
Expand Up @@ -103,24 +103,28 @@ interface EachFunction {
) => void
}

export type TestAPI<ExtraContext = {}> = ChainableFunction<
type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<
'concurrent' | 'only' | 'skip' | 'todo' | 'fails',
[name: string, fn?: TestFunction<ExtraContext>, timeout?: number],
void
> & {
>

export type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
each: EachFunction
skipIf(condition: any): TestAPI<ExtraContext>
runIf(condition: any): TestAPI<ExtraContext>
skipIf(condition: any): ChainableTestAPI<ExtraContext>
runIf(condition: any): ChainableTestAPI<ExtraContext>
}

export type SuiteAPI<ExtraContext = {}> = ChainableFunction<
type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<
'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle',
[name: string, factory?: SuiteFactory],
SuiteCollector<ExtraContext>
> & {
>

export type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI & {
each: EachFunction
skipIf(condition: any): SuiteAPI<ExtraContext>
runIf(condition: any): SuiteAPI<ExtraContext>
skipIf(condition: any): ChainableSuiteAPI<ExtraContext>
runIf(condition: any): ChainableSuiteAPI<ExtraContext>
}

export type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>
Expand Down
15 changes: 0 additions & 15 deletions test/core/test/basic.test.ts
Expand Up @@ -57,18 +57,3 @@ it('timeout', () => new Promise(resolve => setTimeout(resolve, timeout)))
it.fails('deprecated done callback', (done) => {
done()
})

const shouldSkip = true

it.skipIf(shouldSkip)('skipped', () => {
throw new Error('foo')
})
it.skipIf(!shouldSkip)('not skipped', () => {
expect(1).toBe(1)
})
it.runIf(!shouldSkip)('skipped 2', () => {
throw new Error('foo')
})
it.runIf(shouldSkip)('not skipped 2', () => {
expect(1).toBe(1)
})
31 changes: 31 additions & 0 deletions test/core/test/run-if.test.ts
@@ -0,0 +1,31 @@
import { describe, expect, it } from 'vitest'

describe('runIf', () => {
const shouldSkip = true

it.skipIf(shouldSkip)('skipped', () => {
throw new Error('foo')
})

it.skipIf(!shouldSkip)('not skipped', () => {
expect(1).toBe(1)
})

it.runIf(!shouldSkip)('skipped 2', () => {
throw new Error('foo')
})

it.runIf(shouldSkip)('not skipped 2', () => {
expect(1).toBe(1)
})

/*
it.runIf(!shouldSkip).each([1, 2, 3])('works with each skipped', (num) => {
expect(Number.isInteger(num)).toBe(true)
})

it.runIf(shouldSkip).each([1, 2, 3])('works with each not skipped', (num) => {
expect(Number.isInteger(num)).toBe(true)
})
*/
})