Skip to content

Commit

Permalink
fix: move fresh-tape to deps and fix cov (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored Apr 6, 2021
1 parent 9593c3d commit 30cd1dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
Expand Down
46 changes: 25 additions & 21 deletions src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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.')
Expand Down

0 comments on commit 30cd1dc

Please sign in to comment.