Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Bring Test Coverage up to 100% (#152)
Browse files Browse the repository at this point in the history
* remove unccessary code block

* increase test coverage for type matcher

* bring up test coverage of image handler

* better coverage reporting

* bring up test coverage

* remove dead code
  • Loading branch information
trieloff authored and koraa committed Jan 18, 2019
1 parent 9239d17 commit fe2a3c4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pipeline.log
logs/pipeline.log
.nyc_output
logs/debug
coverage
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
adobe-helix-*
logs
test
coverage
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "nyc mocha --exit",
"test": "nyc nyc --reporter=lcov mocha --exit",
"lint": "npx eslint . && npm run types",
"types": "npm run docs && node bin/schema2ts.js",
"docs": "npx jsonschema2md -d src/schemas -o docs",
Expand Down
6 changes: 0 additions & 6 deletions src/html/output-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ function debug(payload, { logger }) {
// and causes rendering issues of the script
delete p.response.body;

if (p.content && p.content.document && p.content.document.innerHTML) {
// document is a 'live' document, so turn it into a nice HTML string
const html = p.content.document.innerHTML;
p.content.document = html;
}

const debugScript = DEBUG_TEMPLATE.replace(/PAYLOAD_JSON/, JSON.stringify(p));
// inject debug script before the closing body tag
p.response.body = body.replace(/<\/body>/i, `${debugScript}</body>`);
Expand Down
4 changes: 1 addition & 3 deletions src/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ class Pipeline {
*/
error(f) {
this.describe(f);
if (!this._last) {
this._last = this._pres;
}

const wrapped = errorWrapper(f);
// ensure proper alias
wrapped.alias = f.alias;
Expand Down
8 changes: 2 additions & 6 deletions src/utils/image-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ const url = require('uri-js');

/**
* Creates an array of widths based on a set of options
* @param {(object|number[])} options either an array of sizes or a set of parameters
* @param {object} options a set of parameters
* to generate an array of options
* @param {number} options.from smallest possible size
* @param {number} options.to largest possible size
* @param {number} options.steps number of steps
*/
function makewidths(options) {
if (Array.isArray(options)) {
return options;
}

const { from, to } = options;
const range = to - from;
const steps = Math.max(2, options.steps);
Expand All @@ -40,7 +36,7 @@ function image({
IMAGES_MAX_SIZE,
IMAGES_SIZE_STEPS,
IMAGES_SIZES,
} = {}) {
}) {
const widths = {
from: parseInt(IMAGES_MIN_SIZE, 10),
to: parseInt(IMAGES_MAX_SIZE, 10),
Expand Down
21 changes: 20 additions & 1 deletion test/testPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Testing Pipeline', () => {
.catch(done);
});

it('When works with promises pre before when', (done) => {
it('When works with promises resolving false pre before when', (done) => {
const order = [];
new Pipeline({ logger })
.before(() => { order.push('pre0'); })
Expand All @@ -155,6 +155,25 @@ describe('Testing Pipeline', () => {
.catch(done);
});


it('When works with promises resolving true pre before when', (done) => {
const order = [];
new Pipeline({ logger })
.before(() => { order.push('pre0'); })
.before(() => { order.push('enabled'); })
.when(() => Promise.resolve(true))
.before(() => { order.push('pre1'); })
.once(() => { order.push('once'); })
.after(() => { order.push('post0'); })
.after(() => { order.push('post1'); })
.run()
.then(() => {
assert.deepEqual(order, ['pre0', 'enabled', 'pre1', 'once', 'post0', 'post1']);
done();
})
.catch(done);
});

it('Disables post before when', (done) => {
const order = [];
new Pipeline({ logger })
Expand Down
3 changes: 3 additions & 0 deletions test/testTypeMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('Test Type Matcher Util', () => {
assert.deepEqual(new TypeMatcher(null).process(), []);
assert.deepEqual(new TypeMatcher().process(), []);
assert.deepEqual(new TypeMatcher([]).process(), []);
assert.deepEqual(new TypeMatcher([
{ type: 'root' },
]).process(), { type: 'root', types: [] });
});

it('TypeMatcher returns empty array if no matchers are registered', () => {
Expand Down

0 comments on commit fe2a3c4

Please sign in to comment.