Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
chore: coverage improvements (#141)
Browse files Browse the repository at this point in the history
* fix: remove unreachable code

we check for the level being present in this.levels before moving forward. unless a user has manipulated log.disp manually by removing the level in question, it is impossible to log an item with an undefined level or a level not present in log.disp

* chore: increase test coverage

* chore: drop tap coverage override
  • Loading branch information
nlf authored Apr 26, 2023
1 parent 6c58b2c commit 567d24e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ log.showProgress = function (name, completed) {
var last = log.record[log.record.length - 1]
if (last) {
values.subsection = last.prefix
var disp = log.disp[last.level] || last.level
var disp = log.disp[last.level]
var logline = this._format(disp, log.style[last.level])
if (last.prefix) {
logline += ' ' + this._format(last.prefix, this.prefixStyle)
Expand Down Expand Up @@ -285,7 +285,7 @@ log.emitLog = function (m) {

// If 'disp' is null or undefined, use the lvl as a default
// Allows: '', 0 as valid disp
var disp = log.disp[m.level] != null ? log.disp[m.level] : m.level
var disp = log.disp[m.level]
this.clearProgress()
m.message.split(/\r?\n/).forEach(function (line) {
var heading = this.heading
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"tap": {
"branches": 95,
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
Expand Down
17 changes: 15 additions & 2 deletions test/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test('disableProgress', function (t) {
})

test('showProgress', function (t) {
t.plan(6)
t.plan(13)
resetTracker()
log.disableProgress()
actions = []
Expand All @@ -107,17 +107,30 @@ test('showProgress', function (t) {
actions = []
log.showProgress('foo')
didActions(t, 'showProgress', [['show', { section: 'foo', completed: 0 }]])
actions = []
log.log('info', undefined, 'foo')
actions = []
log.showProgress('foo')
didActions(t, 'showProgress', [
['show', { section: 'foo', subsection: '', completed: 0, logline: 'info foo' }],
])
log.record.length = 0
})

test('clearProgress', function (t) {
t.plan(4)
t.plan(6)
resetTracker()
log.clearProgress()
didActions(t, 'clearProgress', [['hide']])
log.disableProgress()
actions = []
log.clearProgress()
didActions(t, 'clearProgress disabled', [])
actions = []
log.clearProgress(() => {
t.ok('called cb')
})
didActions(t, 'clearProgress disabled', [])
})

test('newItem', function (t) {
Expand Down

0 comments on commit 567d24e

Please sign in to comment.