Commit ff93f601 authored by Daniel Shumway's avatar Daniel Shumway

feat: large refactor

- split codebase into multiple files (for constants)
- new method (`assert`)
- code cleanup/organization (better Promises)
- remove test timeouts
parent 2ea032bd
This diff is collapsed.
var ENVIRONMENTS = {
NODE : 'node',
BROWSER : 'browser'
};
ENVIRONMENTS.current = (function () {
if (typeof process !== 'undefined') {
return ENVIRONMENTS.NODE;
} else if (typeof window !== 'undefined') {
return ENVIRONMENTS.BROWSER;
}
//TODO: detect promise support
return '';
}());
module.exports = Object.freeze(ENVIRONMENTS);
module.exports = {
en : {
attachPostResolve: function () {
return [
"Test attached after the suite has already finished. Usually, this is a mistake.",
"Set `options.attachPostResolve` if you really know what you're doing."
].join("\n");
},
callbackError: function () {
return ["Uncaught error in suite callback:", ""].join("\n");
}
}
};
module.exports = Object.freeze({
PASSED : 'passed',
FAILED : 'failed',
PENDING : 'pending',
SKIPPED : 'skipped'
});
var STATUS = require('constants/status');
var COLORS = {
RED : '\x1b[31m',
GREEN : '\x1b[32m',
RESET : '\x1b[0m'
};
function color (color, str) {
return color + str + COLORS.RESET;
}
module.exports = function () {
var passed = true;
var report = function (test, prefix) {
if (test.label) {
var status = test.status === STATUS.PASSED ?
color(COLORS.GREEN, '(/)') :
color(COLORS.RED, '(X)');
console.log(prefix, status, test.label);
prefix = ' ' + prefix;
if (test.error) {
console.log(test.error);
}
}
passed = passed && test.status === STATUS.PASSED;
test.children.forEach(function (child) {
report(child, prefix);
});
if (test.children.length !== 0) { console.log(); }
};
if (this.parent == null) {
report(this, '-');
console.log(passed ?
color(COLORS.GREEN, 'Test suite passed!') :
color(COLORS.RED, 'Test suite failed!')
);
process.exitCode = passed ? 0 : 1;
}
};
var ENVIRONMENTS = require('constants/environments');
var STATUS = require('constants/status');
var environment = ENVIRONMENTS.current;
module.exports = (function () {
var buffer = '';
var log = function (message) {
if (environment === ENVIRONMENTS.NODE) {
process.stdout.write(message);
} else if (console.clear) {
buffer = buffer + message;
console.clear();
console.log(buffer);
} else {
console.log(message);
}
};
var failPath = function(suite) {
if (suite.parent == null) {
return suite.label ? '(' + suite.label + ')' : '';
}
return failPath(suite.parent) + '(' + suite.label + ')';
};
var passed = true;
return function (suite) {
if (suite.status === STATUS.PASSED) {
log('.');
} else if (suite.status === STATUS.FAILED) {
log('X');
log('\n\n' + failPath(suite) + ' failed!');
if(suite.error) {
if (typeof suite.error.expected !== 'undefined') {
log('\nExpected: ' + suite.error.expected);
log('\nActual: ' + suite.error.actual);
}
log('\n' + suite.error.stack);
}
log('\n\n');
if(environment === ENVIRONMENTS.NODE) {
process.exitCode = 1;
pass = false;
}
}
if (suite.parent == null) {
log('\nTests finished: ' +
(passed ? 'passed' : 'failed') + '\n');
}
};
}());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment