Skip to content
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

chore: added worker support #163

Merged
merged 11 commits into from
May 30, 2023
Prev Previous commit
Next Next commit
chore: removed old sw suite runner logic
  • Loading branch information
lquixada committed May 30, 2023
commit 707f71b2934ce1cb00a24509e81c28c505ade549
5 changes: 2 additions & 3 deletions test/fetch-api/service-worker/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ globalThis.Headers = Headers

mocha.setup({
ui: 'bdd',
reporter: null // SWReporter,
reporter: SWReporter
})

describe('Browser:Fetch:ServiceWorker', () => {
addFetchSuite()
addNativeSuite({ fetch })
})

addReporterEventListeners(mocha.run())
// mocha.run()
mocha.run()
60 changes: 0 additions & 60 deletions test/fetch-api/service-worker/sw.reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,6 @@
* See: https://github.com/direct-adv-interfaces/mocha-headless-chrome/blob/273d9b8bc7445ea1196b10ad0eaf0a8bce6cbd5f/lib/runner.js#L68
*/

// eslint-disable-next-line no-unused-vars
const addReporterEventListeners = (runResults) => {
const all = []
const passes = []
const failures = []
const pending = []

const error = (err) => {
if (!err) return {}

const res = {}
Object.getOwnPropertyNames(err).forEach((key) => (res[key] = err[key]))
return res
}

const clean = (test) => ({
title: test.title,
fullTitle: test.fullTitle(),
duration: test.duration,
err: error(test.err)
})

const getResult = (stats) => ({
result: {
stats: {
tests: all.length,
passes: passes.length,
pending: pending.length,
failures: failures.length,
start: stats.start.toISOString(),
end: stats.end.toISOString(),
duration: stats.duration
},
tests: all.map(clean),
pending: pending.map(clean),
failures: failures.map(clean),
passes: passes.map(clean)
}
})

runResults
.on('pass', (test) => {
passes.push(test)
all.push(test)
})
.on('fail', (test) => {
failures.push(test)
all.push(test)
})
.on('pending', (test) => {
pending.push(test)
all.push(test)
})
.on('end', () => {
const result = getResult(runResults.stats)
const channel = new BroadcastChannel('sw-result')
channel.postMessage(JSON.stringify(result))
})
}

const { Spec } = Mocha.reporters
const {
EVENT_RUN_END,
Expand Down