Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,34 @@ module.exports = {
*/
process(process) {
if (process === null) return (outputProcess = '')
if (process) outputProcess = String(process).length === 1 ? `[0${process}]` : `[${process}]`
if (process) {
// Handle objects by converting to empty string or extracting properties
let processValue = process
if (typeof process === 'object') {
// If it's an object, try to extract a numeric value or use empty string
processValue = process.id || process.index || process.worker || ''
}

const processNum = parseInt(processValue, 10)
const processStr = !isNaN(processNum) ? String(processNum).padStart(2, '0') : String(processValue).padStart(2, '0')

// Assign different colors to different workers for better identification
const workerColors = [
colors.cyan, // Worker 01 - Cyan
colors.magenta, // Worker 02 - Magenta
colors.green, // Worker 03 - Green
colors.yellow, // Worker 04 - Yellow
colors.blue, // Worker 05 - Blue
colors.red, // Worker 06 - Red
colors.white, // Worker 07 - White
colors.gray, // Worker 08 - Gray
]
const workerIndex = !isNaN(processNum) ? processNum - 1 : -1
const colorFn = workerIndex >= 0 && workerColors[workerIndex % workerColors.length]
? workerColors[workerIndex % workerColors.length]
: colors.cyan
outputProcess = colorFn.bold(`[Worker ${processStr}]`)
}
return outputProcess
},

Expand Down Expand Up @@ -149,25 +176,34 @@ module.exports = {
* @param {Mocha.Test} test
*/
started(test) {
print(` ${colors.magenta.bold(test.title)}`)
const featureName = test.parent?.title ? `${colors.cyan.bold(test.parent.title)} › ` : ''
print(` ${featureName}${colors.magenta.bold(test.title)}`)
},
/**
* @param {Mocha.Test} test
*/
passed(test) {
print(` ${colors.green.bold(figures.tick)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`)
const featureName = test.parent?.title ? `${colors.cyan(test.parent.title)} › ` : ''
const scenarioName = colors.bold(test.title)
const executionTime = colors.cyan(`in ${test.duration}ms`)
print(` ${colors.green.bold(figures.tick)} ${featureName}${scenarioName} ${executionTime}`)
},
/**
* @param {Mocha.Test} test
*/
failed(test) {
print(` ${colors.red.bold(figures.cross)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`)
const featureName = test.parent?.title ? `${colors.yellow(test.parent.title)} › ` : ''
const scenarioName = colors.bold(test.title)
const executionTime = colors.yellow(`in ${test.duration}ms`)
print(` ${colors.red.bold(figures.cross)} ${featureName}${scenarioName} ${executionTime}`)
},
/**
* @param {Mocha.Test} test
*/
skipped(test) {
print(` ${colors.yellow.bold('S')} ${test.title}`)
const featureName = test.parent?.title ? `${colors.gray(test.parent.title)} › ` : ''
const scenarioName = colors.bold(test.title)
print(` ${colors.yellow.bold('S')} ${featureName}${scenarioName}`)
},
},

Expand Down
4 changes: 3 additions & 1 deletion test/unit/output_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ describe('Output', () => {
}

output.process(expectedProcess)
expect(output.process()).to.equal(`[${expectedProcess}]`)
// The new format includes "Worker" prefix and cyan color
expect(output.process()).to.contain('[Worker')
expect(output.process()).to.contain(']')
})

it('should allow debug messages when output level >= 2', () => {
Expand Down
Loading