Skip to content

Commit

Permalink
feat: Added a quiet mode printer to versioned-tests (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Apr 15, 2024
1 parent 0f40f8b commit 9477251
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
24 changes: 19 additions & 5 deletions bin/version-manager.js
Expand Up @@ -61,7 +61,7 @@ function int(val) {
}

function printMode(mode) {
if (['pretty', 'simple'].indexOf(mode) === -1) {
if (['pretty', 'simple', 'quiet'].indexOf(mode) === -1) {
console.error('Invalid print mode "' + mode + '"')
process.exit(5)
}
Expand Down Expand Up @@ -90,10 +90,24 @@ function run(files, patterns) {
const mode = cmd.major ? 'major' : cmd.patch ? 'patch' : 'minor'

// Create our test structures.
const viewer =
process.env.TRAVIS || cmd.print === 'simple'
? new printers.SimplePrinter(files, { refresh: 100 })
: new printers.PrettyPrinter(files, { refresh: 100 })
let viewer
switch (cmd.print) {
case 'default':
case 'simple': {
viewer = new printers.SimplePrinter(files, { refresh: 100 })
break
}

case 'pretty': {
viewer = new printers.PrettyPrinter(files, { refresh: 100 })
break
}

case 'quiet': {
viewer = new printers.QuietPrinter(files, { refresh: 100 })
break
}
}

const runner = new Suite(directories, {
limit: maxParallelRuns,
Expand Down
1 change: 1 addition & 0 deletions lib/versioned/printers/index.js
Expand Up @@ -7,3 +7,4 @@

exports.PrettyPrinter = require('./pretty')
exports.SimplePrinter = require('./simple')
exports.QuietPrinter = require('./quiet')
33 changes: 33 additions & 0 deletions lib/versioned/printers/quiet.js
@@ -0,0 +1,33 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'

const TestPrinter = require('./printer')

/**
* A printer that will only write output to the destination stream when
* an error has occurred in a test suite.
*/
class QuietPrinter extends TestPrinter {
constructor(tests, options) {
super(tests, options)
}

print() {
// This method is required by TestPrinter.maybePrint, but we don't need
// to do anything.
}

update(test, status) {
// This method is used by the runner to update the status of a test.
// We only care if the test has failed. If it has, then indicate that
// the output should be printed.
const failed = this._isFailure(status) === true
this._doUpdate(test, status, failed === true)
}
}

module.exports = QuietPrinter

0 comments on commit 9477251

Please sign in to comment.