From c39a9acf50df603339b6318f0b80f6ee771cdb9f Mon Sep 17 00:00:00 2001 From: Ivan Demchuk Date: Sat, 16 Jul 2022 12:57:41 +0300 Subject: [PATCH 1/2] Move tests --- test/core/test/basic.test.ts | 15 --------------- test/core/test/run-if.test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 test/core/test/run-if.test.ts diff --git a/test/core/test/basic.test.ts b/test/core/test/basic.test.ts index 122397d10b91..61e488ee07e9 100644 --- a/test/core/test/basic.test.ts +++ b/test/core/test/basic.test.ts @@ -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) -}) diff --git a/test/core/test/run-if.test.ts b/test/core/test/run-if.test.ts new file mode 100644 index 000000000000..1a67c4689bc7 --- /dev/null +++ b/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) + }) + */ +}) From 5a98f915def793ac3c79e43eb0e6f92e19045779 Mon Sep 17 00:00:00 2001 From: Ivan Demchuk Date: Sat, 16 Jul 2022 13:09:46 +0300 Subject: [PATCH 2/2] Fix types for `test.each` and `describe.each` --- packages/vitest/src/types/tasks.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/vitest/src/types/tasks.ts b/packages/vitest/src/types/tasks.ts index 773601590d78..1f4c876288aa 100644 --- a/packages/vitest/src/types/tasks.ts +++ b/packages/vitest/src/types/tasks.ts @@ -103,24 +103,28 @@ interface EachFunction { ) => void } -export type TestAPI = ChainableFunction< +type ChainableTestAPI = ChainableFunction< 'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [name: string, fn?: TestFunction, timeout?: number], void -> & { +> + +export type TestAPI = ChainableTestAPI & { each: EachFunction - skipIf(condition: any): TestAPI - runIf(condition: any): TestAPI + skipIf(condition: any): ChainableTestAPI + runIf(condition: any): ChainableTestAPI } -export type SuiteAPI = ChainableFunction< +type ChainableSuiteAPI = ChainableFunction< 'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [name: string, factory?: SuiteFactory], SuiteCollector -> & { +> + +export type SuiteAPI = ChainableSuiteAPI & { each: EachFunction - skipIf(condition: any): SuiteAPI - runIf(condition: any): SuiteAPI + skipIf(condition: any): ChainableSuiteAPI + runIf(condition: any): ChainableSuiteAPI } export type HookListener = (...args: T) => Awaitable