-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat(circus): enable writing async test event handlers #9397
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
Merged
+219
−60
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
122c182
feat(circus): async handleTestEvent
noomorph 3ee2a23
Merge branch 'master' into feat/async-event-handler
noomorph 46d2f5a
Merge remote-tracking branch 'original/master' into feat/async-event-…
noomorph c855a81
Update e2e/test-environment-circus/CircusAsyncHandleTestEventEnvironm…
noomorph 2900542
Update e2e/test-environment-circus/CircusAsyncHandleTestEventEnvironm…
noomorph 7d1d6ee
Update CircusAsyncHandleTestEventEnvironment.js
noomorph 46c7589
Update testEventHandler.ts
noomorph 49f2b38
code: restore TODO comment
noomorph 032fe72
docs: fix CHANGELOG
noomorph afb77c2
test(circus): split handleTestEvent suite into two
noomorph a566dc1
test(circus): more comprehensive e2e test
noomorph 5749912
lint: fix error
noomorph 9561180
code: add TODO comment
noomorph f19e8e5
Merge branch 'master' into feat/async-event-handler
noomorph 001bf63
Merge branch 'master' into feat/async-event-handler
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {skipSuiteOnJasmine} from '@jest/test-utils'; | ||
import runJest from '../runJest'; | ||
|
||
skipSuiteOnJasmine(); | ||
|
||
it('calls asynchronous handleTestEvent in testEnvironment', () => { | ||
const result = runJest('test-environment-circus-async'); | ||
expect(result.failed).toEqual(true); | ||
|
||
const lines = result.stdout.split('\n'); | ||
expect(lines).toMatchInlineSnapshot(` | ||
Array [ | ||
"setup", | ||
"warning: add_hook is a sync event", | ||
"warning: start_describe_definition is a sync event", | ||
"warning: add_hook is a sync event", | ||
"warning: add_hook is a sync event", | ||
"warning: add_test is a sync event", | ||
"warning: add_test is a sync event", | ||
"warning: finish_describe_definition is a sync event", | ||
"add_hook", | ||
"start_describe_definition", | ||
"add_hook", | ||
"add_hook", | ||
"add_test", | ||
"add_test", | ||
"finish_describe_definition", | ||
"run_start", | ||
"run_describe_start", | ||
"run_describe_start", | ||
"test_start: passing test", | ||
"hook_start: beforeEach", | ||
"hook_success: beforeEach", | ||
"hook_start: beforeEach", | ||
"hook_success: beforeEach", | ||
"test_fn_start: passing test", | ||
"test_fn_success: passing test", | ||
"hook_start: afterEach", | ||
"hook_failure: afterEach", | ||
"test_done: passing test", | ||
"test_start: failing test", | ||
"hook_start: beforeEach", | ||
"hook_success: beforeEach", | ||
"hook_start: beforeEach", | ||
"hook_success: beforeEach", | ||
"test_fn_start: failing test", | ||
"test_fn_failure: failing test", | ||
"hook_start: afterEach", | ||
"hook_failure: afterEach", | ||
"test_done: failing test", | ||
"run_describe_finish", | ||
"run_describe_finish", | ||
"run_finish", | ||
"teardown", | ||
] | ||
`); | ||
}); |
38 changes: 38 additions & 0 deletions
38
e2e/test-environment-circus-async/CircusAsyncHandleTestEventEnvironment.js
This file contains hidden or 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,38 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const JSDOMEnvironment = require('jest-environment-jsdom'); | ||
|
||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | ||
|
||
class TestEnvironment extends JSDOMEnvironment { | ||
async handleTestEvent(event) { | ||
await this.assertRunnerWaitsForHandleTestEvent(event); | ||
|
||
if (event.hook) { | ||
console.log(event.name + ': ' + event.hook.type); | ||
} else if (event.test) { | ||
console.log(event.name + ': ' + event.test.name); | ||
} else { | ||
console.log(event.name); | ||
} | ||
} | ||
|
||
async assertRunnerWaitsForHandleTestEvent(event) { | ||
if (this.pendingEvent) { | ||
console.log(`warning: ${this.pendingEvent.name} is a sync event`); | ||
} | ||
|
||
this.pendingEvent = event; | ||
await sleep(0); | ||
this.pendingEvent = null; | ||
} | ||
} | ||
|
||
module.exports = TestEnvironment; |
23 changes: 23 additions & 0 deletions
23
e2e/test-environment-circus-async/__tests__/circusHandleTestEvent.test.js
This file contains hidden or 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,23 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @jest-environment ./CircusAsyncHandleTestEventEnvironment.js | ||
*/ | ||
|
||
describe('suite', () => { | ||
beforeEach(() => {}); | ||
afterEach(() => { | ||
throw new Error(); | ||
}); | ||
|
||
test('passing test', () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
test('failing test', () => { | ||
expect(true).toBe(false); | ||
}); | ||
}); |
This file contains hidden or 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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.