Skip to content

Commit

Permalink
fix: normalize logs and stop node run
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Oct 19, 2023
1 parent d5454f1 commit 4403489
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/node/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class NodeRunner {
} catch {
await this.stop(true, 'Tests failed.')
}
this.stop(false, 'Tests passed.')
}

async watch() {
Expand Down
16 changes: 7 additions & 9 deletions src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { mkdirSync } from 'fs'
import path from 'path'
import { fileURLToPath } from 'node:url'
import { asyncExitHook, gracefulExit } from 'exit-hook'
import ora from 'ora'
import { nanoid } from 'nanoid'
import { temporaryDirectory } from 'tempy'
import { premove } from 'premove/sync'
Expand Down Expand Up @@ -299,7 +298,6 @@ export class Runner {

this.beforeTestsOutput = await this.options.beforeTests(this.options)

const spinner = ora(`Setting up ${this.options.browser}`).start()
try {
// Setup the context
const context = await this.setupContext()
Expand All @@ -311,7 +309,7 @@ export class Runner {

// Setup page
const page = await this.setupPage(context)
spinner.succeed(`${this.options.browser} set up`)
log.info(`Browser "${this.options.browser}" setup complete.`)

const { outName } = await this.runTests(page)

Expand Down Expand Up @@ -349,10 +347,12 @@ export class Runner {
}

// exit
await this.stop(testsFailed)
await this.stop(
testsFailed,
testsFailed ? 'Tests failed.' : 'Tests passed.'
)
}
} catch (/** @type {any} */ error) {
spinner.fail('Running tests failed.')
await this.stop(true, error)
}
}
Expand Down Expand Up @@ -388,20 +388,18 @@ export class Runner {
})

this.beforeTestsOutput = await this.options.beforeTests(this.options)
const spinner = ora(`Setting up ${this.options.browser}`).start()

// Setup the context
const context = await this.setupContext()

// Run the before script
if (this.options.before) {
spinner.text = 'Running before script'
await this.setupBeforePage(context)
}

// Setup page
const page = await this.setupPage(context)
spinner.succeed(`${this.options.browser} set up`)
log.info(`Browser "${this.options.browser}" setup complete.`)

const { files } = await this.runTests(page)

Expand Down Expand Up @@ -431,7 +429,7 @@ export class Runner {
// Run after tests hook
await this.options.afterTests(this.options, this.beforeTestsOutput)

await premove(this.dir)
premove(this.dir)

const serverClose = new Promise((resolve, reject) => {
if (this.server) {
Expand Down
2 changes: 1 addition & 1 deletion src/taps/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function log(ctx, fail, time) {
? kleur.red('✘')
: ctx.skip
? kleur.yellow('-')
: kleur.green('')
: kleur.green('')
const _time = kleur.gray(`(${time})`)
const _msg = `${ctx.suite ? ctx.suite + ' > ' : ''}${ctx.name}`

Expand Down
4 changes: 2 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const log = {
*/
warn(message, quiet = false) {
if (!quiet) {
console.warn(kleur.yellow(''), message)
console.warn(kleur.yellow('-'), message)
}
},
/**
Expand All @@ -76,7 +76,7 @@ export const log = {
*/
error(message, quiet = false) {
if (!quiet) {
console.warn(kleur.red(''), message)
console.warn(kleur.red(''), message)
}
},
/**
Expand Down

0 comments on commit 4403489

Please sign in to comment.