Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tap-arc

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tap-arc - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

CHANGELOG.md

197

index.js

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

const JSON5 = require('json5')
const minimist = require('minimist')
const Parser = require('tap-parser')
const stripAnsi = require('strip-ansi')
const through = require('through2')

@@ -21,17 +23,70 @@ const {

const RESULT_COMMENTS = [ 'tests ', 'pass ', 'skip', 'todo', 'fail ', 'failed ', 'ok' ]
const alias = {
help: [ 'h', 'help' ],
pessimistic: [ 'p', 'pessimistic', 'bail' ],
verbose: [ 'v', 'verbose' ],
}
const options = {
color: true,
help: false,
indent: 'dot',
padding: 'space',
pessimistic: false,
verbose: false,
...minimist(process.argv.slice(2), { alias })
}
if (options.help) {
console.log(`
Usage:
tap-arc <options>
Parses TAP data from stdin, and outputs a "spec-like" formatted result.
Options:
-v | --verbose
Output full stack trace
-p | --pessimistic | --bail
Immediately exit upon encountering a failure
example: tap-arc -p
--no-color
Output without ANSI escape sequences for colors
example: tap-arc --no-color
--padding [space, dot, <custom characters>]
String to use when padding output (default=" ")
example: tap-arc --padding "••"
example: tap-arc --padding dot
--indent [space, dot, <custom characters>]
String to use when indenting Object diffs (default="··")
example: tap-arc --indent ">>"
example: tap-arc --indent space`)
process.exit()
}
switch (options.indent) {
case 'dot': options.indent = '··'; break
case 'space': options.indent = ' '; break
}
switch (options.padding) {
case 'dot':options.padding = '··'; break
case 'space':options.padding = ' '; break
}
const parser = new Parser({ bail: options.pessimistic })
const tapArc = through()
const cwd = process.cwd()
const start = Date.now()
const OKAY = green('✔')
const FAIL = red('✖')
function createPad (character) {
return (count = 1, char) => {
return dim(char || character).repeat(count)
}
function pad (count = 1, char) {
return dim(char || options.padding).repeat(count)
}
function prettyMs (start) {
const ms = Date.now() - start
return ms < 1000 ? `${ms} ms` : `${ms / 1000} s`
}
function makeDiff (actual, expected, indent = ' ') {

@@ -69,94 +124,21 @@ let msg = []

function usage () {
console.log(`
Usage:
tap-arc <options>
Parses TAP data from stdin, and outputs a "spec-like" formatted result.
Options:
-v | --verbose
Output full stack trace
-p | --pessimistic | --bail
Immediately exit upon encountering a failure
example: tap-arc -p
--padding [space, dot, <custom characters>]
String to use when padding output (default=" ")
example: tap-arc --padding "••"
example: tap-arc --padding dot
--indent [space, dot, <custom characters>]
String to use when indenting Object diffs (default="··")
example: tap-arc --indent ">>"
example: tap-arc --indent space
`)
process.exit()
function print (msg) {
tapArc.push(options.color ? msg : stripAnsi(msg))
}
const options = { pessimistic: false, verbose: false, indent: '··', padding: ' ' }
const args = process.argv.slice(2)
for (let i = 0; i < args.length; i++) {
const arg = args[i]
if (arg === '-v' || arg === '--verbose') options.verbose = true
else if (arg === '-p' || arg === '--pessimistic' || arg === '--bail') options.pessimistic = true
else if (arg === '-h' || arg === '--help') usage()
else if (arg === '--indent') {
let val = args[i + 1]
switch (val) {
case 'dot':
options.indent = '··'
break
case 'space':
options.indent = ' '
break
default:
options.indent = val
break
}
i += 1
}
else if (arg === '--padding') {
let val = args[i + 1]
switch (val) {
case 'dot':
options.padding = '··'
break
case 'space':
options.padding = ' '
break
default:
options.padding = val
break
}
i += 1
}
else {
console.error(`Unrecognized arg: ${arg}`)
process.exit(1)
}
function prettyMs (start) {
const ms = Date.now() - start
return ms < 1000 ? `${ms} ms` : `${ms / 1000} s`
}
let { indent, pessimistic, padding, verbose } = options
const parser = new Parser({ bail: pessimistic })
const tapArc = through()
const pad = createPad(padding)
const cwd = process.cwd()
const start = Date.now()
parser.on('pass', (pass) => {
tapArc.push(`${pad(2)}${OKAY} ${dim(pass.name)}\n`)
print(`${pad(2)}${OKAY} ${dim(pass.name)}\n`)
})
parser.on('skip', (skip) => {
tapArc.push(`${pad(2)}${dim(`SKIP ${skip.name}`)}\n`)
print(`${pad(2)}${dim(`SKIP ${skip.name}`)}\n`)
})
parser.on('extra', (extra) => {
if (extra.trim().length > 0) tapArc.push(`${pad(2)}${yellow(`> ${extra}`)}`)
if (extra.trim().length > 0) print(`${pad(2)}${yellow(`> ${extra}`)}`)
})

@@ -166,13 +148,14 @@

// Log test-group name
const RESULT_COMMENTS = [ 'tests ', 'pass ', 'skip', 'todo', 'fail ', 'failed ', 'ok' ]
if (!RESULT_COMMENTS.some((c) => comment.startsWith(c, 2)))
tapArc.push(`\n${pad()}${underline(comment.trimEnd().replace(/^(# )/, ''))}\n`)
print(`\n${pad()}${underline(comment.trimEnd().replace(/^(# )/, ''))}\n`)
})
parser.on('todo', (todo) => {
if (todo.ok) tapArc.push(`${pad(2)}${yellow('TODO')} ${dim(todo.name)}\n`)
else tapArc.push(`${pad(2)}${red('TODO')} ${dim(todo.name)}\n`)
if (todo.ok) print(`${pad(2)}${yellow('TODO')} ${dim(todo.name)}\n`)
else print(`${pad(2)}${red('TODO')} ${dim(todo.name)}\n`)
})
parser.on('fail', (fail) => {
tapArc.push(`${pad(2)}${FAIL} ${dim(`${fail.id})`)} ${red(fail.name)}\n`)
print(`${pad(2)}${FAIL} ${dim(`${fail.id})`)} ${red(fail.name)}\n`)

@@ -185,7 +168,7 @@ if (fail.diag) {

if (typeof expected === 'string' && typeof actual === 'string') {
msg = [ ...msg, ...makeDiff(actual, expected, indent) ]
msg = [ ...msg, ...makeDiff(actual, expected, options.indent) ]
}
else if (typeof expected === 'object' && typeof actual === 'object') {
// probably an array
msg = [ ...msg, ...makeDiff(actual, expected, indent) ]
msg = [ ...msg, ...makeDiff(actual, expected, options.indent) ]
}

@@ -248,3 +231,3 @@ else if (typeof expected === 'number' || typeof actual === 'number') {

if (verbose && stack) {
if (options.verbose && stack) {
msg.push('')

@@ -261,3 +244,3 @@ stack.split('\n').forEach((s) => {

tapArc.push(msg.join(''))
print(msg.join(''))
}

@@ -274,15 +257,15 @@ })

tapArc.push(failureSummary)
print(failureSummary)
for (const fail of result.failures) {
tapArc.push(`${pad(2)}${FAIL} ${dim(`${fail.id})`)} ${fail.name}\n`)
print(`${pad(2)}${FAIL} ${dim(`${fail.id})`)} ${fail.name}\n`)
}
}
tapArc.push(`\n${pad()}total: ${result.count}\n`)
if (result.pass > 0) tapArc.push(green(`${pad()}passing: ${result.pass}\n`))
if (result.fail > 0) tapArc.push(red(`${pad()}failing: ${result.fail}\n`))
if (result.skip > 0) tapArc.push(`${pad()}skipped: ${result.skip}\n`)
if (result.todo > 0) tapArc.push(`${pad()}todo: ${result.todo}\n`)
if (result.bailout) tapArc.push(`${pad()}${bold(underline(red('BAILED!')))}\n`)
print(`\n${pad()}total: ${result.count}\n`)
if (result.pass > 0) print(green(`${pad()}passing: ${result.pass}\n`))
if (result.fail > 0) print(red(`${pad()}failing: ${result.fail}\n`))
if (result.skip > 0) print(`${pad()}skipped: ${result.skip}\n`)
if (result.todo > 0) print(`${pad()}todo: ${result.todo}\n`)
if (result.bailout) print(`${pad()}${bold(underline(red('BAILED!')))}\n`)

@@ -289,0 +272,0 @@ tapArc.end(`${dim(`${pad()}${prettyMs(start)}`)}\n\n`)

@@ -5,3 +5,3 @@ {

"author": "tbeseda",
"version": "0.1.0",
"version": "0.1.1",
"license": "Apache-2.0",

@@ -50,3 +50,5 @@ "main": "index.js",

"json5": "^2.2.0",
"minimist": "~1.2.5",
"picocolors": "^1.0.0",
"strip-ansi": "^6.0.1",
"tap-parser": "^10.1.0",

@@ -53,0 +55,0 @@ "through2": "^4.0.2"

@@ -16,3 +16,3 @@ # `tap-arc`

> Requires Node.js 14+
> Compatible with Node.js 12+.

@@ -53,18 +53,22 @@ For a JavaScript project, save `tap-arc` as a development dependency:

-v | --verbose
Output full stack trace
-v | --verbose
Output full stack trace
-p | --pessimistic | --bail
Immediately exit upon encountering a failure
example: tap-arc -p
-p | --pessimistic | --bail
Immediately exit upon encountering a failure
example: tap-arc -p
--padding [space, dot, <custom characters>]
String to use when padding output (default=" ")
example: tap-arc --padding "••"
example: tap-arc --padding dot
--no-color
Output without ANSI escape sequences for colors
example: tap-arc --no-color
--indent [space, dot, <custom characters>]
String to use when indenting Object diffs (default="··")
example: tap-arc --indent ">>"
example: tap-arc --indent space
--padding [space, dot, <custom characters>]
String to use when padding output (default=" ")
example: tap-arc --padding "••"
example: tap-arc --padding dot
--indent [space, dot, <custom characters>]
String to use when indenting Object diffs (default="··")
example: tap-arc --indent ">>"
example: tap-arc --indent space
```

@@ -89,2 +93,1 @@

- [tap-min](https://github.com/derhuerst/tap-min) helpful approaches to streaming and exit codes
- [ansi-regex](https://github.com/chalk/ansi-regex) copied regex pattern for ansi
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc