Socket
Socket
Sign inDemoInstall

tap-mocha-reporter

Package Overview
Dependencies
29
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.5

slow.js

3

index.js

@@ -7,2 +7,3 @@ #!/usr/bin/env node

var reporters = require('./lib/reporters/index.js')
Formatter.types = Object.keys(reporters).sort()
var Writable = require('stream').Writable

@@ -57,3 +58,3 @@ var Runner = require('./lib/runner.js')

function avail () {
var types = Object.keys(reporters).sort().reduce(function (str, t) {
var types = Formatter.types.reduce(function (str, t) {
var ll = str.split('\n').pop().length + t.length

@@ -60,0 +61,0 @@ if (ll < 40)

@@ -38,5 +38,8 @@ /**

exports.useColors = process.env
? (supportsColor || (process.env.MOCHA_COLORS !== undefined))
? (supportsColor || (process.env.TAP_COLORS !== undefined))
: false;
if (exports.useColors && +process.env.TAP_COLORS === 0)
exports.useColors = false
/**

@@ -58,3 +61,4 @@ * Inline diffs instead of +/-

, 'bright yellow': 93
, 'pending': 36
, 'pending': 35
, 'skip': 36
, 'suite': 0

@@ -271,3 +275,4 @@ , 'error title': 0

stats.end = new Date;
stats.duration = new Date - stats.start;
if (!stats.duration)
stats.duration = stats.end - stats.start;
});

@@ -318,6 +323,3 @@

Base.list(this.failures);
console.log();
}
console.log();
};

@@ -324,0 +326,0 @@

@@ -1,39 +0,189 @@

exports = module.exports = Dump
exports = module.exports = Classic
var Base = require('./base')
, cursor = Base.cursor
, color = Base.color;
, color = Base.color
, yaml = require('js-yaml')
, util = require('util')
, fancy = Base.useColors
function Dump(runner) {
util.inherits(Classic, Base)
function Classic (runner) {
Base.call(this, runner);
var events = [
'start',
'version',
'end',
'suite',
'suite end',
'test',
'pending',
'pass',
'fail',
'test end',
];
var self = this
var i = process.argv.indexOf('dump')
if (i !== -1) {
var args = process.argv.slice(i + 1)
if (args.length)
events = args
}
var grandTotal = 0
var grandPass = 0
events.forEach(function (ev) {
runner.on(ev, function () {
console.log(ev)
if (arguments.length) {
var args = [].concat.apply([], arguments)
console.log.apply(console, args)
console.log()
var bailed = false
var hadFails = false
var currentSuite = null
var tests = []
var skipped = 0
var skipMsg = []
var todo = []
var fails = []
var total = 0
var pass = 0
var tickDots = 0
var tickColor = 'checkmark'
runner.on('bailout', function (bailout, suite) {
if (currentSuite)
runner.emit('suite end', currentSuite)
if (bailed)
return
bailed = true
console.log(Base.color('fail', 'Bail out! ' + bailout))
})
runner.on('suite', function (suite) {
if (!suite.root)
return
if (fancy) {
process.stdout.write(suite.title + ' ')
tickDots = 0
tickColor = 'checkmark'
}
currentSuite = suite
tests = []
todo = []
fails = []
skipMsg = []
skipped = 0
pass = 0
total = 0
})
runner.on('suite end', function (suite) {
if (!suite.root)
return
if (fancy)
Base.cursor.beginningOfLine()
currentSuite = null
var len = 60
var title = suite.title || '(unnamed)'
var num = pass + '/' + total
var dots = len - title.length - num.length - 2
if (dots < 3)
dots = 3
dots = ' ' + new Array(dots).join('.') + ' '
if (pass === total)
num = Base.color('checkmark', num)
else if (fails.length)
num = Base.color('fail', num)
else
num = Base.color('pending', num)
console.log(title + dots + num)
if (fails.length) {
var failMsg = ''
fails.forEach(function (t) {
failMsg += Base.color('fail', 'not ok ' + t.name) + '\n'
if (t.diag)
failMsg += indent(yaml.safeDump(t.diag), 2) + '\n'
})
console.log(indent(failMsg, 2))
}
if (todo.length) {
var todoMsg = ''
var bullet = Base.color('pending', '~ ')
todo.forEach(function (t) {
if (t.todo !== true)
t.name += ' - ' + Base.color('pending', t.todo)
todoMsg += bullet + t.name + '\n'
if (t.diag)
todoMsg += indent(yaml.safeDump(t.diag), 4) + '\n'
})
console.log(indent(todoMsg, 2))
}
if (skipped) {
var fmt = Base.color('skip', indent('Skipped: %d', 2))
console.log(fmt, skipped)
if (skipMsg.length)
console.log(indent(skipMsg.join('\n'), 4))
console.log('')
}
})
runner.on('test', function (test) {
total ++
grandTotal ++
var t = test.result
if (fancy && currentSuite) {
var max = 57 - currentSuite.title.length
if (max < 3)
max = 3
if (tickDots > max) {
tickDots = 0
Base.cursor.deleteLine()
Base.cursor.beginningOfLine();
process.stdout.write(currentSuite.title + ' ')
}
})
tickDots ++
if (t.todo &&
(tickColor === 'checkmark' || tickColor === 'skip'))
tickColor = 'pending'
else if (t.skip && tickColor === 'checkmark')
tickColor = 'skip'
else if (!t.ok)
tickColor = 'fail'
process.stdout.write(Base.color(tickColor, '.'))
}
if (t.skip) {
skipped += 1
if (t.skip !== true)
skipMsg.push(t.name + ' ' + Base.color('skip', t.skip))
else
skipMsg.push(t.name)
}
else if (t.todo)
todo.push(t)
else if (!t.ok) {
fails.push(t)
hadFails = true
}
else {
pass ++
grandPass ++
}
})
runner.on('end', function () {
total = grandTotal
pass = grandPass
tests = []
todo = []
fails = []
skipMsg = []
skipped = 0
if (hadFails)
fails = [,,,]
runner.emit('suite end', { title: 'total', root: true })
self.failures = []
self.epilogue();
if (grandTotal === grandPass) {
console.log(Base.color('checkmark', '\n ok'))
}
})
}
function indent (str, n) {
var ind = new Array(n + 1).join(' ')
str = ind + str.split('\n').join('\n' + ind)
return str.replace(/(\n\s*)+$/, '\n')
}

@@ -1,2 +0,1 @@

exports.base = require('./base.js')
exports.dot = require('./dot.js')

@@ -3,0 +2,0 @@ exports.doc = require('./doc.js')

@@ -49,2 +49,3 @@ // A facade from the tap-parser to the Mocha "Runner" object.

var Parser = require('tap-parser')
var timere = /^#\s*time=((?:0|[1-9][0-9]*)(:?\.[0-9]+)?)(ms|s)?\n$/

@@ -85,7 +86,2 @@ util.inherits(Runner, Writable)

function attachEvents (runner, parser, level) {
var events = [
'version', 'plan', 'assert', 'comment',
'complete', 'extra', 'bailout'
]
parser.runner = runner

@@ -97,2 +93,5 @@

})
parser.on('complete', function (res) {
runner.emit('end', runner.stats)
})
}

@@ -102,13 +101,30 @@

parser.didAssert = false
parser.printed = false
parser.name = ''
parser.doingChild = null
parser.on('finish', function () {
if (!parser.parent)
runner.emit('end')
parser.on('complete', function (res) {
if (!res.ok) {
var fail = { ok: false, diag: {} }
var count = res.count
if (res.plan) {
var plan = res.plan.end - res.plan.start + 1
if (count !== plan) {
fail.name = 'test count !== plan'
fail.diag = {
found: count,
wanted: plan
}
} else {
// probably handled on child parser
return
}
} else {
fail.name = 'missing plan'
}
fail.diag.results = res
emitTest(parser, fail)
}
})
parser.on('child', function (child) {
//console.log('>>> child')
child.parent = parser

@@ -128,6 +144,19 @@ attachEvents(runner, child, level + 1)

parser.on('comment', function (c) {
if (!this.printed && c.match(/^# Subtest: /)) {
if (c.match(/^# Subtest: /)) {
c = c.trim().replace(/^# Subtest: /, '')
this.name = c
parser.name = c
}
// get the top-level duration from the trailing comment,
// if one occurs.
if (!this.suite || this.suite.root) {
var m = c.match(timere)
if (m) {
var time = m[1]
if (m[2] === 's')
time *= 1000
runner.stats.duration = Math.round(time, 0)
}
}
})

@@ -141,8 +170,13 @@

parser.on('assert', function (result) {
emitSuite(this)
emitSuite(this, result)
// no need to print the trailing assert for subtests
// we've already emitted a 'suite end' event for this.
// just do a 'suite end' event for this.
if (this.doingChild && this.doingChild.didAssert &&
this.doingChild.name === result.name) {
var suite = this.doingChild.suite
if (suite) {
suite.duration = Math.round(result.time, 0)
runner.emit('suite end', this.doingChild.suite)
}
this.doingChild = null

@@ -160,6 +194,11 @@ return

this.results = results
if (this.suite)
runner.emit('suite end', this.suite)
})
parser.on('bailout', function (reason) {
var suite = this.suite
runner.emit('bailout', reason, suite)
if (suite)
this.suite = suite.parent
})
// proxy all stream events directly

@@ -179,9 +218,10 @@ var streamEvents = [

function emitSuite (parser) {
//console.log('emitSuite', parser.emittedSuite, parser.level, parser.name)
if (!parser.emittedSuite && parser.name) {
function emitSuite (parser, result) {
if (!parser.emittedSuite && (parser.name || parser.level === 0)) {
parser.emittedSuite = true
var suite = parser.suite = new Suite(parser)
if (parser.parent && parser.parent.suite)
if (parser.parent && parser.parent.suite) {
parser.parent.suite.suites.push(suite)
}
parser.runner.emit('suite', suite)

@@ -195,2 +235,7 @@ }

if (!parser.suite) {
emitSuite(parser, result)
}
if (parser.suite) {

@@ -200,2 +245,4 @@ //if (test.parent === parser)

parser.suite.tests.push(test)
} else {
console.error('test without suite?')
}

@@ -202,0 +249,0 @@

{
"name": "tap-mocha-reporter",
"version": "0.0.4",
"version": "0.0.5",
"description": "Format a TAP stream using Mocha's set of reporters",

@@ -25,2 +25,3 @@ "main": "index.js",

"glob": "^5.0.5",
"js-yaml": "isaacs/js-yaml",
"supports-color": "^1.3.1",

@@ -27,0 +28,0 @@ "tap-parser": "^1.0.4"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc