Skip to content

Commit

Permalink
Print diagnostic info according to TAP spec; maintenance (#4)
Browse files Browse the repository at this point in the history
* Print diagnostic info according to TAP spec

TAP specification says that diagnostic info lines should start with `#`.

* Support Node.js 10

* Update dependencies

* Test using GitHub Actions

Co-authored-by: Daudov, Tymur <tymur.daudov@f-secure.com>
Co-authored-by: Mark Wubben <mark@novemberborn.net>
  • Loading branch information
3 people committed Dec 22, 2020
1 parent 8417845 commit 3341df8
Show file tree
Hide file tree
Showing 8 changed files with 527 additions and 820 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,22 @@
name: Test
on:
push:
branches:
- master
pull_request:
jobs:
nodejs:
name: Node.js
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [^10, ^12, ^14]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install --no-audit
- run: npm test
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

27 changes: 12 additions & 15 deletions index.js
@@ -1,29 +1,27 @@
'use strict';

const serializeErr = require('serialize-error');
const {serializeError} = require('serialize-error');
const indentString = require('indent-string');
const stripAnsi = require('strip-ansi');
const arrify = require('arrify');
const yaml = require('js-yaml');

const serializeError = err => {
const obj = serializeErr(err);
obj.at = obj.stack
const serializeErrorForTap = err => {
const object = serializeError(err);
object.at = object.stack
.split('\n')
.slice(1, 2)
.map(line => line.replace(/at/, '').trim())
.shift();

delete obj.stack;

return obj;
delete object.stack;
return object;
};

exports.start = () => 'TAP version 13';

exports.test = (title, options) => {
const error = options.error;
let passed = options.passed;
const {error} = options;
let {passed} = options;
let directive = '';

if (!error) {
Expand All @@ -37,21 +35,20 @@ exports.test = (title, options) => {
}

const comment = arrify(options.comment)
.map(line => indentString(line, 4).replace(/^ {4}/, ' * '))
.map(line => indentString(line, 4).replace(/^ {4}/gm, '# '))
.join('\n');

const output = [
`# ${stripAnsi(title)}`,
`${passed ? 'ok' : 'not ok'} ${options.index} - ${title} ${directive}`.trim(),
`${passed ? 'ok' : 'not ok'} ${options.index} - ${stripAnsi(title)} ${directive}`.trim(),
comment
];

if (error) {
const obj = error instanceof Error ? serializeError(error) : error;
const object = error instanceof Error ? serializeErrorForTap(error) : error;

output.push([
' ---',
indentString(yaml.safeDump(obj).trim(), 4),
indentString(yaml.safeDump(object).trim(), 4),
' ...'
].join('\n'));
}
Expand Down
28 changes: 14 additions & 14 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"url": "github.com/vadimdemedes"
},
"engines": {
"node": ">=4"
"node": ">=10"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -24,28 +24,28 @@
"output"
],
"dependencies": {
"arrify": "^1.0.1",
"indent-string": "^3.2.0",
"js-yaml": "^3.10.0",
"serialize-error": "^2.1.0",
"strip-ansi": "^4.0.0"
"arrify": "^2.0.1",
"indent-string": "^4.0.0",
"js-yaml": "^3.14.0",
"serialize-error": "^7.0.1",
"strip-ansi": "^6.0.0"
},
"devDependencies": {
"ava": "^0.20.0",
"ava": "^3.14.0",
"ctrlc-exit": "^1.0.0",
"execa": "^0.8.0",
"execa": "^5.0.0",
"faucet": "^0.0.1",
"p-each-series": "^1.0.0",
"tap-dot": "^1.0.5",
"p-each-series": "^2.2.0",
"tap-dot": "^2.0.0",
"tap-json": "^1.0.0",
"tap-min": "^1.2.2",
"tap-min": "^2.0.0",
"tap-nyan": "^1.1.0",
"tap-out": "^2.0.0",
"tap-out": "^3.0.0",
"tap-pessimist": "^1.0.1",
"tap-spec": "^4.1.1",
"tap-spec": "^5.0.0",
"tap-summary": "^4.0.0",
"wait-for-enter": "^1.0.0",
"xo": "^0.18.2"
"xo": "^0.36.1"
},
"ava": {
"serial": true
Expand Down
15 changes: 8 additions & 7 deletions scripts/check.js
Expand Up @@ -4,21 +4,22 @@ const waitForEnter = require('wait-for-enter');
const eachSeries = require('p-each-series');
const ctrlcExit = require('ctrlc-exit');
const execa = require('execa');
const path = require('path');

ctrlcExit();

const exec = cmd => {
return execa.shell(cmd)
.catch(err => err)
.then(result => result.stdout);
const exec = async cmd => {
const {stdout} = await execa.command(cmd, {reject: false, shell: true})
return stdout;
};

const fixtures = fs.readdirSync(`${__dirname}/../test/fixtures`);
const fixturePath = path.join(__dirname, '..', 'test', 'fixtures');

const fixtures = fs.readdirSync(fixturePath);
const reporter = process.argv[2];

eachSeries(fixtures, async fixture => {
const fixturePath = `${__dirname}/../test/fixtures/${fixture}`;
const reporterPath = `${__dirname}/../node_modules/.bin/${reporter}`;
const reporterPath = path.join(__dirname, '..', 'node_modules', '.bin', reporter);
const stdout = await exec(`node ${fixturePath} | ${reporterPath}`);
console.log(fixture);
console.log(stdout);
Expand Down

0 comments on commit 3341df8

Please sign in to comment.