From 6e084842ae4645766d404d1c951d2b1a863322c7 Mon Sep 17 00:00:00 2001 From: Gabriel Csapo Date: Wed, 20 Dec 2017 00:42:29 -0500 Subject: [PATCH] 0.2.0 - removes commander - improves readability - adds a named function tapHTML for readability - updates dependencies --- CHANGELOG.md | 7 +++++++ README.md | 14 ++++++++++--- bin/index.js | 45 +++++++++++++++++++++++++++++++++-------- docs/example/index.html | 2 +- docs/index.html | 2 +- index.js | 23 ++++++++++----------- lib/generate.js | 4 ++-- package.json | 19 +++++++++-------- 8 files changed, 79 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cdb017..d045999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.2.0 (12/20/2017) + +- removes commander +- improves readability +- adds a named function `tapHTML` for readability +- updates dependencies + # 0.1.8 (11/13/2017) - uses preact to reduce bundle size. diff --git a/README.md b/README.md index 0885519..b6dcb47 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,21 @@ npm install tap-html --save-dev ``` Usage: tap-html [options] +Commands: + -h, --help, help Output usage information + -v, --version, version Output the version number Options: + -o, --outFile [path] If instead of piping content you want it to be written to an html file locally please specify the relative path +``` + +By default tap parser should be pipeable as such: - -V, --version output the version number - -o, --out if instead of piping content you want it to be written to an html file locally please specify the relative path - -h, --help output usage information ``` +tape test/**.js | tap-html | html-cleanup > index.html +``` + +To generate a report running the following will create a file for you. > This will generate a tap-html.html file diff --git a/bin/index.js b/bin/index.js index 2db442e..a820afa 100755 --- a/bin/index.js +++ b/bin/index.js @@ -1,22 +1,51 @@ #!/usr/bin/env node -const program = require('commander'); const path = require('path'); - const parser = require('../'); const generate = require('../lib/generate'); -program - .version(require('../package').version) - .option('-o, --out ', 'if instead of piping content you want it to be written to an html file locally please specify the relative path') - .parse(process.argv); +let program = {}; +const args = process.argv.slice(2); + +args.forEach((arg, i) => { + switch (arg) { + case '-v': + case '--version': + case 'version': + console.log(`v${require('../package.json').version}`); // eslint-disable-line + process.exit(0); + break; + case '-h': + case '--help': + case 'help': + console.log(`` + // eslint-disable-line + ` +Usage: tap-html [options] + +Commands: + -h, --help, help Output usage information + -v, --version, version Output the version number + +Options: + -o, --outFile [path] If instead of piping content you want it to be written to an html file locally please specify the relative path +`); + process.exit(0); + break; + case '-o': + case '--out': + program['out'] = path.resolve(process.cwd(), args[i + 1]); + break; + } +}); + +const { out } = program; process.stdin .pipe(parser((res) => { // generate the html report - if(program.out) { + if(out) { // write the output to the specified location - generate(res, path.resolve(process.cwd(), program.out)); + generate(res, out); } else { generate(res); } diff --git a/docs/example/index.html b/docs/example/index.html index 55d2579..a14e8d0 100644 --- a/docs/example/index.html +++ b/docs/example/index.html @@ -8,5 +8,5 @@
- + diff --git a/docs/index.html b/docs/index.html index f60fedb..2fef3c9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -8,5 +8,5 @@
- + diff --git a/index.js b/index.js index 5085469..e549028 100644 --- a/index.js +++ b/index.js @@ -2,17 +2,17 @@ const Parser = require('tap-parser'); const Through = require('through2'); const Duplexer = require('duplexer'); -module.exports = (callback) => { - var tap = new Parser(); - var out = Through.obj(); - var dup = Duplexer(tap, out); +module.exports = function tapHTML(callback) { + const tap = new Parser(); + const out = Through.obj(); + const dup = Duplexer(tap, out); - var currentPlan = -1; - var currentAssertion = -1; - var data = []; - var plan = null; + let currentPlan = -1; + let currentAssertion = -1; + let data = []; + let plan = null; - var startTime = Date.now(); + const startTime = Date.now(); tap.on('comment', (res) => { if (!plan) { @@ -89,9 +89,8 @@ module.exports = (callback) => { data = data.filter((d) => d > ''); function calculateTime(test) { - if (test.end) { - return; - } + if (test.end) return; + test.end = test.assertions[test.assertions.length - 1].end; test.assertions.forEach((assertion) => { assertion.start = test.start; diff --git a/lib/generate.js b/lib/generate.js index e4cded6..16664b4 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -11,7 +11,7 @@ module.exports = (report, outfile) => { // this should be configurable const output = path.dirname(outfile) || process.cwd(); - var compiler = webpack({ + const compiler = webpack({ entry: path.resolve(__dirname, '..', 'src', 'index.js'), context: path.resolve(__dirname, '..'), output: { @@ -85,7 +85,7 @@ module.exports = (report, outfile) => { compiler.outputFileSystem = msf; } - compiler.run(function(err) { + compiler.run((err) => { if (err) console.error(err); // eslint-disable-line if (outfile) { try { diff --git a/package.json b/package.json index 4ff1f2c..31c0cc6 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "tap-html", - "version": "0.1.8", + "version": "0.2.0", "description": "📊 an html tap reporter", "author": "Gabriel J. Csapo ", - "license": "ISC", + "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/gabrielcsapo/tap-html.git" @@ -29,34 +29,33 @@ "babel-loader": "^7.1.1", "babel-preset-env": "^1.6.1", "babel-preset-react": "^6.24.1", - "commander": "^2.12.2", "css-loader": "^0.28.4", "duplexer": "^0.1.1", - "file-loader": "^1.1.5", + "file-loader": "^1.1.6", "font-awesome": "^4.7.0", "html-webpack-inline-source-plugin": "0.0.9", "html-webpack-plugin": "^2.29.0", "memory-fs": "^0.4.1", - "preact": "^8.2.6", + "preact": "^8.2.7", "preact-compat": "^3.17.0", "prop-types": "^15.6.0", "psychic-ui": "^1.0.7", - "style-loader": "^0.19.0", + "style-loader": "^0.19.1", "tap-parser": "^7.0.0", "through2": "^2.0.3", "url-loader": "^0.6.2", - "webpack": "^3.9.1" + "webpack": "^3.10.0" }, "devDependencies": { - "@storybook/react": "^3.2.16", + "@storybook/react": "^3.2.18", "babel-minify-webpack-plugin": "^0.2.0", "babel-polyfill": "^6.26.0", - "eslint": "^4.12.1", + "eslint": "^4.13.1", "eslint-plugin-react": "^7.5.1", "react": "^16.2.0", "react-dom": "^16.2.0", "tap": "^11.0.0", "tape": "^4.6.3", - "tryitout": "^1.2.0" + "tryitout": "^1.2.2" } }