feat(testrunner): async suite descriptions (#4721)

This patch teaches TestRunner to support async suite
descriptions. This is needed to require tests using ES6 dynamic
imports:

```js
const t = new TestRunner();

await t.describe('tests', async () => {
  (await import('./some.spec.js')).addTests(t);
  (await import('./other.spec.js')).addTests(t);
});
```
This commit is contained in:
Andrey Lushnikov 2019-07-18 11:25:06 -07:00 committed by GitHub
parent 835e8849fd
commit 852c46c1e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -327,12 +327,14 @@ class TestRunner extends EventEmitter {
this._hasFocusedTestsOrSuites = this._hasFocusedTestsOrSuites || mode === TestMode.Focus; this._hasFocusedTestsOrSuites = this._hasFocusedTestsOrSuites || mode === TestMode.Focus;
} }
_addSuite(mode, comment, name, callback) { async _addSuite(mode, comment, name, callback) {
const oldSuite = this._currentSuite; const oldSuite = this._currentSuite;
const suite = new Suite(this._currentSuite, name, mode, comment); const suite = new Suite(this._currentSuite, name, mode, comment);
this._currentSuite.children.push(suite); this._currentSuite.children.push(suite);
this._currentSuite = suite; this._currentSuite = suite;
callback(); const result = callback();
if (result && (typeof result.then === 'function'))
await result;
this._currentSuite = oldSuite; this._currentSuite = oldSuite;
this._hasFocusedTestsOrSuites = this._hasFocusedTestsOrSuites || mode === TestMode.Focus; this._hasFocusedTestsOrSuites = this._hasFocusedTestsOrSuites || mode === TestMode.Focus;
} }