From 93fa61c31a0c07051e49451da76746a7f35d8be0 Mon Sep 17 00:00:00 2001 From: john davis Date: Sun, 7 May 2017 16:44:14 -0700 Subject: [PATCH 1/3] test and handler added for fmt req query --- lib/handlers.js | 17 ++++++++++++----- package.json | 5 +++-- test/run-tests.js | 20 +++++++++++++++++--- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/handlers.js b/lib/handlers.js index 4492207..9585a92 100644 --- a/lib/handlers.js +++ b/lib/handlers.js @@ -45,10 +45,19 @@ function createHandler(opts) { app.get('/', function (req, res) { var origUrl = url.parse(req.originalUrl).pathname, origLength = origUrl.length; - if (origUrl.charAt(origLength - 1) !== '/') { - origUrl += '/'; + if (req.query.fmt) { + if (req.query.fmt === 'json' ) { + res.json(core.getCoverageObject() || {}); + } else { + res.status(450) + .send('invalid format'); + } + } else { + if (origUrl.charAt(origLength - 1) !== '/') { + origUrl += '/'; + } + core.render(null, res, origUrl); } - core.render(null, res, origUrl); }); //show page for specific file/ dir for /show?file=/path/to/file @@ -194,5 +203,3 @@ module.exports = { createHandler: createHandler, hookLoader: core.hookLoader }; - - diff --git a/package.json b/package.json index e911d12..fb27ffe 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,11 @@ "archiver": "0.14.x" }, "devDependencies": { + "async": "*", + "jshint": "*", "mkdirp": "*", + "request": "^2.81.0", "rimraf": "*", - "jshint": "*", - "async": "*", "yui-lint": "*" }, "engines": { diff --git a/test/run-tests.js b/test/run-tests.js index c817266..7b13f51 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -7,6 +7,7 @@ var child_process = require('child_process'), mkdirp = require('mkdirp'), rimraf = require('rimraf'), async = require('async'), + request = require('request'), serverProcess, timeoutHandle; @@ -23,7 +24,7 @@ function setup(cb) { mkdirp.sync(outputDir); timeoutHandle = setTimeout(function () { throw new Error('Tests timed out'); - }, 30000); + }, 30000*2*2); cb(); } catch (ex) { cb(ex); @@ -44,6 +45,20 @@ function runPhantomTests(cb) { }); } +function getJSON(cb) { + console.log('TEST: Getting json'); + request.get('http://localhost:8888/coverage?fmt=json', function (error, response, body) { + if (error) { + return cb(new Error(error)); + } + try { + cb(null, JSON.parse(body)); + } catch(error) { + return cb(new Error(error)); + } + }); +} + function downloadZip(cb) { var curlProcess = run(thisDir, 'curl', [ '-o', path.resolve(outputDir, 'coverage.zip'), 'http://localhost:8888/coverage/download' ]); curlProcess.on('exit', function (exitCode) { @@ -66,9 +81,8 @@ function unzipList(cb) { }); } -async.series([ setup, runServer, runPhantomTests, downloadZip, clearAll, unzipList], function (err) { +async.series([ setup, runServer, runPhantomTests, getJSON, downloadZip, clearAll, unzipList], function (err, responses) { if (err) { throw err; } console.log('All done'); process.exit(0); }); - From 4379e220c4a3047a0bca3c3df42e02c594e6c3a4 Mon Sep 17 00:00:00 2001 From: john davis Date: Sun, 7 May 2017 16:49:02 -0700 Subject: [PATCH 2/3] added description of fmt query arg --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9610406..cdb3a0e 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,11 @@ The above snippet adds the following endpoints to your app under `/coverage` GET /download Download a zip file with coverage JSON, HTML and lcov reports + + GET /download?fmt=json + Download the raw coverage JSON + + POST /client @@ -197,4 +202,3 @@ The following third-party libraries are used by this module: * express: https://github.com/visionmedia/express - to implement the middleware * archiver: https://github.com/ctalkington/node-archiver - for zip functionality - From e40bce7e7ba2af0669fa4bdcd3e55865f751b67a Mon Sep 17 00:00:00 2001 From: john davis Date: Sun, 7 May 2017 16:55:25 -0700 Subject: [PATCH 3/3] reset test timeout to 30 seconds --- test/run-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-tests.js b/test/run-tests.js index 7b13f51..42ec119 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -24,7 +24,7 @@ function setup(cb) { mkdirp.sync(outputDir); timeoutHandle = setTimeout(function () { throw new Error('Tests timed out'); - }, 30000*2*2); + }, 30000); cb(); } catch (ex) { cb(ex);