Skip to content

Commit

Permalink
test(supertape) coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Dec 11, 2020
1 parent 7a2f495 commit be9410f
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 95 deletions.
2 changes: 0 additions & 2 deletions lib/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const initOperator = ({out, reporter, count, incCount, incPassed, incFailed}) =>
if (is) {
incPassed();
reporter.emit('test:success', {
is,
count: count(),
message,
});
Expand All @@ -150,7 +149,6 @@ const initOperator = ({out, reporter, count, incCount, incPassed, incFailed}) =>
const reason = stack ? 'user' : 'assert';

reporter.emit('test:fail', {
is,
count: count(),
message,
operator: name,
Expand Down
73 changes: 44 additions & 29 deletions lib/operators.spec.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,72 @@
'use strict';

const test = require('..');
const {once, EventEmitter} = require('events');
const stub = require('@cloudcmd/stub');
const test = require('..');

const {
initOperators,
operators,
} = require('./operators');
const {createOutput} = require('./supertape');

test('supertape: operators: extendOperators', (t) => {
const out = createOutput();

test('supertape: operators: extendOperators', async (t) => {
const extensions = {
transformCode: (t) => (a, b) => {
return t.equal(a, b, 'should transform code');
},
};

const {transformCode} = initOperators(getStubs({out, extensions}));
const reporter = new EventEmitter();
const {transformCode} = initOperators(getStubs({reporter, extensions}));

transformCode('a', 'a');
const [[result]] = await Promise.all([
once(reporter, 'test:success'),
transformCode('a', 'a'),
]);

const result = out();
const expected = 'ok 1 should transform code';
const expected = {
count: 1,
message: 'should transform code',
};

t.equal(result, expected);
t.deepEqual(result, expected);
t.end();
});

test('supertape: operators: initOperators: notEqual', (t) => {
const out = createOutput();
const {notEqual} = initOperators(getStubs({out}));

notEqual(+0, -0);

const result = out();
const expected = 'ok 1 should not equal';
test('supertape: operators: initOperators: notEqual', async (t) => {
const reporter = new EventEmitter();
const {notEqual} = initOperators(getStubs({reporter}));

const [[result]] = await Promise.all([
once(reporter, 'test:success'),
notEqual(+0, -0),
]);

const expected = {
count: 1,
message: 'should not equal',
};

t.equal(result, expected);
t.deepEqual(result, expected);
t.end();
});

test('supertape: operators: initOperators: notDeepEqual: true', (t) => {
const out = createOutput();
const {notDeepEqual} = initOperators(getStubs({out}));

notDeepEqual({a: 'b'}, {b: 'a'});

const result = out();
const expected = 'ok 1 should not deep equal';
test('supertape: operators: initOperators: notDeepEqual: true', async (t) => {
const reporter = new EventEmitter();
const {notDeepEqual} = initOperators(getStubs({reporter}));

const [[result]] = await Promise.all([
once(reporter, 'test:success'),
notDeepEqual({a: 'b'}, {b: 'a'}),
]);

const expected = {
count: 1,
message: 'should not deep equal',
};

t.equal(result, expected);
t.deepEqual(result, expected);
t.end();
});

Expand Down Expand Up @@ -97,7 +112,7 @@ test('supertape: operators: notDeepEqual: true', (t) => {

function getStubs(stubs = {}) {
const {
out = stub(),
reporter = new EventEmitter(),
count = stub().returns(1),
incCount = stub(),
incPassed = stub(),
Expand All @@ -106,7 +121,7 @@ function getStubs(stubs = {}) {
} = stubs;

return {
out,
reporter,
count,
incCount,
incPassed,
Expand Down
4 changes: 2 additions & 2 deletions lib/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ module.exports.createReporter = (name) => {
});
});

reporter.on('test:fail', ({is, at, name, count,message, operator, actual, expected, output, errorStack}) => {
reporter.on('test:fail', ({is, at, count,message, operator, actual, expected, output, errorStack}) => {
harness.write({
type: 'fail',
is, at, name, count,message, operator, actual, expected, output, errorStack,
is, at, count,message, operator, actual, expected, output, errorStack,
});
});

Expand Down
4 changes: 2 additions & 2 deletions lib/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ module.exports.success = ({count, message}) => {
return `ok ${count} ${message}\n`;
}

module.exports.fail = ({is, at, name, count,message, operator, actual, expected, output, errorStack}) => {
module.exports.fail = ({is, at, count,message, operator, actual, expected, output, errorStack}) => {
const out = createOutput();

out(`not ok ${count} ${message}`);
out(' ---');
out(` operator: ${name}`);
out(` operator: ${operator}`);

if (output)
out(output);
Expand Down
Loading

0 comments on commit be9410f

Please sign in to comment.