-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(circus): enable writing async test event handlers (#9397)
- Loading branch information
Showing
16 changed files
with
219 additions
and
60 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
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 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 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 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 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
Oops, something went wrong.