Skip to content

Commit

Permalink
feat(output): improving time reporting in output
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Apr 14, 2023
1 parent 4d9686a commit dc56d8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 23 additions & 10 deletions src/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ function browserIssue (job, { type, url, code, dir }) {
log(job, p`└──────────${pad.x('─')}┘`)
}

const formatTime = duration => {
duration = Math.ceil(duration / 1000)
const seconds = duration % 60
const minutes = (duration - seconds) / 60
return minutes.toString().padStart(2, '0') + ':' + seconds.toString().padStart(2, '0')
}

function build (job) {
let wrap
if (interactive) {
Expand All @@ -199,6 +206,8 @@ function build (job) {
} else {
wrap = method => method
}
const outputStart = Date.now()
const getElapsed = () => formatTime(Date.now() - outputStart)

return {
lastTick: 0,
Expand Down Expand Up @@ -236,9 +245,10 @@ function build (job) {
} else {
method = log
}
const text = `${getElapsed()}${status}`
method(job, '')
method(job, status)
method(job, ''.padStart(status.length, '─'))
method(job, text)
method(job, '──────┴'.padEnd(text.length, '─'))
},

watching: wrap(path => {
Expand Down Expand Up @@ -295,18 +305,25 @@ function build (job) {
},

browserStart (url) {
const text = p80()`${getElapsed()} >> ${pad.lt(url)}`
if (interactive) {
output(job, '>>', url)
output(job, text)
} else {
wrap(() => log(job, p80()`>> ${pad.lt(url)}`))()
wrap(() => log(job, text))()
}
},

browserStopped (url) {
let duration = ''
const page = job.qunitPages && job.qunitPages[url]
if (page) {
duration = ' (' + formatTime(page.end - page.start) + ')'
}
const text = p80()`${getElapsed()} << ${pad.lt(url + duration)}`
if (interactive) {
output(job, '<<', url)
output(job, text)
} else {
wrap(() => log(job, p80()`<< ${pad.lt(url)}`))()
wrap(() => log(job, text))()
}
},

Expand Down Expand Up @@ -436,10 +453,6 @@ function build (job) {
log(job, p80()`!! FAILFAST ${pad.lt(url)}`)
}),

timeSpent: wrap((start, end = new Date()) => {
log(job, p80()`Time spent: ${end - start}ms`)
}),

noTestPageFound: wrap(() => {
err(job, p80()`No test page found (or all filtered out)`)
}),
Expand Down
1 change: 0 additions & 1 deletion src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module.exports = {
})
promises.push(generateCoverageReport(job))
await Promise.all(promises)
output.timeSpent(job.start)
job.status = 'Done'
}
}

0 comments on commit dc56d8f

Please sign in to comment.