Skip to content

Commit

Permalink
tweak test output
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdustan committed Feb 27, 2017
1 parent f7de506 commit d27c1f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"description": "A tiny React renderer to demonstrate how to write a renderer.",
"main": "./index.js",
"scripts": {
"flow": "pushd src/fiber; flow; popd;",
"test-stack": "node ./test --stack",
"test-fiber": "node ./test --fiber",
"test": "node ./test && node ./test --fiber"
"test": "node ./test && node ./test --fiber && npm run flow"
},
"repository": {
"type": "git",
Expand Down
15 changes: 11 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const TEST_FILE = args[0] === '-f' || args[0] === '--fiber'
? 'fiber'
: 'stack';

console.log('Running %s tests', TEST_FILE);
const TinyRenderer = require('./src/' + TEST_FILE);
const render = TinyRenderer.render;
const toJSON = (props) => {
Expand Down Expand Up @@ -40,12 +41,21 @@ const Rte = (path, component, children) =>
const ok = [];
const fail = [];
const skipped = [];
const colors = {
green: '\x1b[32m',
red: '\x1b[31m',
reset: '\x1b[37m',
};

const it = (desc, fn) => {
try {
fn.call(null);
console.log('%s✓ %s%s', colors.green, colors.reset, desc);
ok.push({desc});
} catch (err) {
fail.push({desc, err});
console.log('%s𝘅 %s%s',colors.red, colors.reset, desc);
console.error('%s. Expected\n %j\n to equal\n %j\n', err.name, err.actual, err.expected)
}
};

Expand Down Expand Up @@ -95,10 +105,6 @@ it('should render with a custom toJSON method', () => {
});

if (fail.length > 0) {
fail.map(f => {
console.log(f.desc);
console.error('%s. Expected\n %j\n to equal\n %j\n', f.err.name, f.err.actual, f.err.expected)
});
console.log('%s tests passed', ok.length);
if (skipped.length) console.log('%s tests skipped', skipped.length);
console.log('%s tests failed', fail.length);
Expand All @@ -108,3 +114,4 @@ if (fail.length > 0) {
if (skipped.length) console.log('%s tests skipped', skipped.length);
}

console.log('');

0 comments on commit d27c1f9

Please sign in to comment.