-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runner): support automatic fixtures (#5102)
Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>
- Loading branch information
1 parent
bc5b2d0
commit 0441f76
Showing
4 changed files
with
99 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { afterAll, beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
||
const mockServer = { setup: vi.fn(), teardown: vi.fn() } | ||
const FnA = vi.fn() | ||
|
||
const myTest = test.extend<{ | ||
autoFixture: void | ||
normalFixture: any[] | ||
}>({ | ||
autoFixture: [async ({}, use) => { | ||
await mockServer.setup() | ||
await use() | ||
await mockServer.teardown() | ||
}, { auto: true }], | ||
|
||
normalFixture: [async () => { | ||
await FnA() | ||
}, {}], | ||
}) | ||
|
||
describe('fixture with options', () => { | ||
describe('automatic fixture', () => { | ||
beforeEach(() => { | ||
expect(mockServer.setup).toBeCalledTimes(1) | ||
}) | ||
|
||
afterAll(() => { | ||
expect(mockServer.setup).toBeCalledTimes(1) | ||
expect(mockServer.teardown).toBeCalledTimes(1) | ||
}) | ||
|
||
myTest('should setup mock server', () => { | ||
expect(mockServer.setup).toBeCalledTimes(1) | ||
}) | ||
}) | ||
|
||
describe('normal fixture', () => { | ||
myTest('it is not a fixture with options', ({ normalFixture }) => { | ||
expect(FnA).not.toBeCalled() | ||
expect(normalFixture).toBeInstanceOf(Array) | ||
}) | ||
}) | ||
}) |