Commit 628e3a83 authored by Daniel Shumway's avatar Daniel Shumway

feat: reorganize constants

 - remove (unexposed) Environment testing (will use Browserify instead)
 - add warnings is Promise isn't detected
 - attach Promises to both Distilled and Suites
parent aafebf5d
Pipeline #10297488 passed with stage
in 41 seconds
var GLOBAL = 'Distilled';
var STATUS = require('constants/status');
var ENVIRONMENTS = require('constants/environments');
var MESSAGES = require('constants/messages').en;
var REPORTERS = Object.freeze({
dot : require('reporters/dot'),
checklist : require('reporters/checklist'),
});
var MESSAGES = require('constants/messages').en;
var environment = ENVIRONMENTS.current;
(function () {
if (!Promise) {
console.log(MESSAGES.promiseMissing());
}
});
var uniqueId = (function (i) {
return function () { return Math.random() + '' + (++i); };
......@@ -18,7 +21,6 @@ var Suite = (function () {
options = options || {};
var that = this;
var _that = this[PRIVATE] = {
__proto__ : Suite._prototype, //TODO: how many browsers do I lock out with this? Do I care?
//---------------INTERNAL STATE---------------------------
assertion : options.assertion || Promise.resolve(),
......@@ -105,13 +107,6 @@ var Suite = (function () {
});
}
Suite._prototype = {
skip : function () {
var _that = this[PRIVATE];
_that.status = STATUS.SKIPPED;
},
};
Suite.prototype = {
constructor : Suite,
get error() { return this[PRIVATE].error; },
......@@ -123,6 +118,10 @@ var Suite = (function () {
return Object.create(this[PRIVATE].children);
},
get STATUS () { return STATUS },
get REPORTERS () { return REPORTERS },
get MESSAGES () { return MESSAGES },
assert : function (assertion) {
var that = this;
var _that = this[PRIVATE];
......@@ -181,7 +180,7 @@ var Suite = (function () {
assertion : _that.assertion.then(function () {
return test.assert(assertion);
}, function (error) {
_that.skip.call(test); //@huh: is it wrong for me to call my own skip?
test[PRIVATE].status = STATUS.SKIPPED; //@huh: possibly an encapsulation violation here.
throw error;
})
......@@ -204,9 +203,7 @@ var Suite = (function () {
var promise = _that.suite.then(callback, callback).catch(function (err) {
console.log(MESSAGES.callbackError, err);
if (environment === ENVIRONMENTS.NODE) {
process.exit(1);
}
//TODO: should this break?
});
_that.callbacks.push(promise);
......@@ -235,9 +232,9 @@ Distilled.STATUS = STATUS;
Distilled.REPORTERS = REPORTERS;
Distilled.MESSAGES = MESSAGES;
//Export to Node or attach global
if (environment === ENVIRONMENTS.NODE) {
module.exports = Distilled;
} else if (environment === ENVIRONMENTS.BROWSER && GLOBAL) {
window[GLOBAL] = Distilled;
}
Distilled.prototype.STATUS = STATUS;
Distilled.prototype.REPORTERS = REPORTERS;
Distilled.prototype.MESSAGES = MESSAGES;
module.exports = Distilled;
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);
......@@ -8,6 +8,12 @@ module.exports = {
},
callbackError: function () {
return ["Uncaught error in suite callback:", ""].join("\n");
},
promiseMissing : function () {
return [
"Distilled relies on Promise support or an equivalent polyfill: ",
"Expect to see a LOT of errors soon!"
].join("");
}
}
};
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) {
if (process && process.stdout) {
process.stdout.write(message);
} else if (console.clear) {
buffer = buffer + message;
......@@ -44,7 +41,7 @@ module.exports = (function () {
log('\n\n');
if(environment === ENVIRONMENTS.NODE) {
if(process) {
process.exitCode = 1;
pass = false;
}
......
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