-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vest): Add AbortSignal as a parameter to test (#1079)
- Loading branch information
Showing
11 changed files
with
194 additions
and
5 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
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
83 changes: 83 additions & 0 deletions
83
packages/vest/src/core/test/__tests__/testFunctionPayload.test.ts
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,83 @@ | ||
import * as vest from 'vest'; | ||
|
||
describe('Test Function Payload', () => { | ||
describe('AbortSignal', () => { | ||
it('Should pass abort signal to test functions', () => { | ||
const testFnSync = jest.fn(); | ||
const testFnAsync = jest.fn().mockResolvedValue(undefined); | ||
const suite = vest.create(() => { | ||
vest.test('field_1', testFnSync); | ||
vest.test('field_2', testFnAsync); | ||
}); | ||
suite(); | ||
|
||
expect(callPayload(testFnSync).signal).toBeInstanceOf(AbortSignal); | ||
expect(callPayload(testFnAsync).signal).toBeInstanceOf(AbortSignal); | ||
}); | ||
|
||
describe('When test is not canceled', () => { | ||
it('Should proceed without aborting the test', async () => { | ||
const testFn = jest.fn().mockResolvedValue(undefined); | ||
const suite = vest.create(() => { | ||
vest.test('field_1', testFn); | ||
}); | ||
suite(); | ||
|
||
await expect(callPayload(testFn).signal.aborted).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('When test is canceled', () => { | ||
it('Should abort the test', async () => { | ||
const testFn = jest.fn().mockResolvedValue(undefined); | ||
const suite = vest.create(() => { | ||
vest.test('field_1', testFn); | ||
}); | ||
suite(); | ||
suite(); | ||
|
||
await expect(callPayload(testFn).signal.aborted).toBe(true); | ||
await expect(callPayload(testFn, 1, 0).signal.aborted).toBe(false); | ||
}); | ||
|
||
it('Should set the reason to `canceled`', async () => { | ||
const testFn = jest.fn().mockResolvedValue(undefined); | ||
const suite = vest.create(() => { | ||
vest.test('field_1', testFn); | ||
}); | ||
suite(); | ||
suite(); | ||
|
||
await expect(callPayload(testFn).signal.reason).toBe('CANCELED'); | ||
}); | ||
}); | ||
|
||
describe('Multiple async tests', () => { | ||
it('Should abort only the canceled test', async () => { | ||
const testFn1 = jest.fn().mockResolvedValue(undefined); | ||
const testFn2 = jest.fn().mockResolvedValue(undefined); | ||
|
||
const suite = vest.create((only?: string) => { | ||
vest.only(only); | ||
|
||
vest.test('field_1', testFn1); | ||
vest.test('field_2', testFn2); | ||
}); | ||
|
||
suite(); | ||
suite('field_1'); | ||
|
||
await expect(callPayload(testFn1).signal.aborted).toBe(true); | ||
expect(callPayload(testFn2).signal.aborted).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function callPayload( | ||
fn: jest.Mock<any, any, any>, | ||
call: number = 0, | ||
arg: number = 0 | ||
) { | ||
return fn.mock.calls[call][arg]; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/vest/src/exports/__tests__/__snapshots__/SuiteSerializer.test.ts.snap
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SuiteSerializer Should produce a valid serialized dump 1`] = `"{"children":[{"$":"Focused","D":{"focusMode":0,"match":["field_1"],"matchAll":false}},{"$":"Test","D":{"severity":"error","status":"FAILED","fieldName":"field_1","message":"field_1_message"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","fieldName":"field_2","message":"field_2_message"}},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","fieldName":"field_3","groupName":"group_1","message":"field_3_message_1"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","fieldName":"field_3","groupName":"group_1","message":"field_3_message_2"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","fieldName":"field_4","groupName":"group_1","message":"field_4_message"}}],"$":"Group","D":{}},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","fieldName":"field_5","message":"field_5_message"}}],"$":"SkipWhen","D":{}}],"$":"Suite","D":{"optional":{}}}"`; | ||
exports[`SuiteSerializer Should produce a valid serialized dump 1`] = `"{"children":[{"$":"Focused","D":{"focusMode":0,"match":["field_1"],"matchAll":false}},{"$":"Test","D":{"severity":"error","status":"FAILED","abortController":{},"fieldName":"field_1","message":"field_1_message"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_2","message":"field_2_message"}},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_1"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_3","groupName":"group_1","message":"field_3_message_2"}},{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_4","groupName":"group_1","message":"field_4_message"}}],"$":"Group","D":{}},{"children":[{"$":"Test","D":{"severity":"error","status":"SKIPPED","abortController":{},"fieldName":"field_5","message":"field_5_message"}}],"$":"SkipWhen","D":{}}],"$":"Suite","D":{"optional":{}}}"`; |
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
2d28ea7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vest – ./website
vest.vercel.app
vest-ealush.vercel.app
vest-git-latest-ealush.vercel.app
vestjs.dev
www.vestjs.dev
2d28ea7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vest-next – ./website
vest-next-ealush.vercel.app
vest-next.vercel.app
vest-website.vercel.app
vest-next-git-latest-ealush.vercel.app