Skip to content

Commit

Permalink
fix(runner): preserve fixtures when calling runif and skipif (fix vit…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyddall authored and LorenzoBloedow committed Dec 19, 2023
1 parent eb0fe12 commit 06a1fae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/runner/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,12 @@ export function createTaskCollector(
}
}

taskFn.skipIf = (condition: any) => (condition ? test.skip : test) as TestAPI
taskFn.runIf = (condition: any) => (condition ? test : test.skip) as TestAPI
taskFn.skipIf = function (this: TestAPI, condition: any) {
return condition ? this.skip : this
}
taskFn.runIf = function (this: TestAPI, condition: any) {
return condition ? this : this.skip
}

taskFn.extend = function (fixtures: Fixtures<Record<string, any>>) {
const _context = mergeContextFixtures(fixtures, context)
Expand Down
8 changes: 8 additions & 0 deletions test/core/test/fixture-initialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ describe('fixture initialization', () => {
})
})

myTest.runIf(true)('fixtures work with runIf', ({ a }) => {
expect(a).toBe(1)
})

myTest.skipIf(false)('fixtures work with skipIf', ({ a }) => {
expect(a).toBe(1)
})

describe('fixture dependency', () => {
myTest2('b => a', ({ b }) => {
expect(b).toBe('2')
Expand Down

0 comments on commit 06a1fae

Please sign in to comment.