diff --git a/package.json b/package.json index b58167c0..b39127b8 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "sirv": "^1.0.11", "source-map": "0.6.1", "strip-ansi": "^6.0.0", + "fresh-tape": "^5.1.1", "tempy": "^1.0.1", "test-exclude": "^6.0.0" }, @@ -75,10 +76,8 @@ "debug": "^4.3.1", "delay": "^5.0.0", "execa": "^5.0.0", - "fresh-tape": "^5.1.1", "hd-scripts": "^0.1.1", "mocha": "^8.3.2", - "np": "^7.3.0", "tap-spec": "^5.0.0", "uvu": "^0.5.1", "zora": "^4.0.2" diff --git a/src/runner.js b/src/runner.js index e6fda3a8..073c00c0 100644 --- a/src/runner.js +++ b/src/runner.js @@ -220,35 +220,21 @@ class Runner { } } - /** - * Wait for tests to finish - * - * @param {Page} page - */ - async waitForTestsToEnd(page) { - await page.waitForFunction( - // @ts-ignore - () => self.PW_TEST.ended === true, - undefined, - { - timeout: 0, - polling: 100, // need to be polling raf doesnt work in extensions - } - ) - const testsFailed = await page.evaluate('self.PW_TEST.failed') - - await this.stop(testsFailed) - } - async run() { let spinner = ora('Setting up browser').start() try { + // get the context const context = await this.launch() + + // run the before script if (this.options.before) { await this.runBefore(context) } + + // get the page const page = await this.setupPage(context) + // uncaught rejections page.on('pageerror', (err) => { console.error(err) @@ -259,9 +245,12 @@ class Runner { }) spinner.succeed('Browser setup') + // bundle tests spinner = ora('Bundling tests').start() const file = await this.compiler() spinner.succeed() + + // run tests await this.runTests(page, file) // Re run on page reload @@ -270,10 +259,25 @@ class Runner { await this.runTests(page, file) }) } else { - await this.waitForTestsToEnd(page) + // wait for the tests + await page.waitForFunction( + // @ts-ignore + () => self.PW_TEST.ended === true, + undefined, + { + timeout: 0, + polling: 100, // need to be polling raf doesnt work in extensions + } + ) + const testsFailed = await page.evaluate('self.PW_TEST.failed') + + // coverage if (this.options.cov && page.coverage) { await createCov(this, await page.coverage.stopJSCoverage(), file) } + + // exit + await this.stop(testsFailed) } } catch (err) { spinner.fail('Running tests failed.')