2021-02-23 16:53:34 +08:00
|
|
|
define([], function () {
|
|
|
|
return function () {
|
|
|
|
var failMessages = [];
|
|
|
|
var passed = 0;
|
|
|
|
var ASSERTS = [];
|
2021-04-16 22:00:12 +08:00
|
|
|
var MESSAGES = [];
|
2021-02-23 16:53:34 +08:00
|
|
|
var assert = function (test, msg) {
|
2021-04-16 22:00:12 +08:00
|
|
|
MESSAGES.push(msg || false);
|
2022-04-04 19:01:20 +08:00
|
|
|
ASSERTS.push(function (_cb, i) {
|
|
|
|
var called = false;
|
|
|
|
var to;
|
|
|
|
var cb = function (arg) {
|
|
|
|
if (to) {
|
|
|
|
clearTimeout(to);
|
|
|
|
to = undefined;
|
2021-02-23 16:53:34 +08:00
|
|
|
}
|
2022-04-04 19:01:20 +08:00
|
|
|
|
|
|
|
if (called) { return; }
|
|
|
|
called = true;
|
|
|
|
_cb(arg);
|
|
|
|
};
|
|
|
|
|
|
|
|
var _msg = document.createElement('span');
|
|
|
|
_msg.innerText = "An unexpected error occurred. See your browser's console for more details";
|
|
|
|
if (msg && !msg.innerText) {
|
|
|
|
msg.innerText = _msg.innerText;
|
|
|
|
}
|
|
|
|
|
|
|
|
to = setTimeout(function () {
|
|
|
|
cb({
|
|
|
|
test: i,
|
|
|
|
message: msg || _msg,
|
|
|
|
output: "TIMEOUT",
|
|
|
|
});
|
|
|
|
}, 25000);
|
|
|
|
|
|
|
|
try {
|
|
|
|
test(function (result) {
|
|
|
|
if (result === true) {
|
|
|
|
passed++;
|
|
|
|
cb();
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
test: i,
|
|
|
|
message: msg || _msg,
|
|
|
|
output: result,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, msg);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
msg.innerText = `Synchronous error thrown (${(err.message || err)}). See console for more details.`;
|
|
|
|
|
|
|
|
//from ${err.fileName} line ${err.lineNumber}`;
|
|
|
|
cb({
|
|
|
|
test: i,
|
|
|
|
message: msg || _msg,
|
|
|
|
output: {
|
|
|
|
message: err.message,
|
|
|
|
file: err.fileName,
|
|
|
|
line: err.lineNumber,
|
|
|
|
stack: typeof(err.stack) === 'string'?
|
|
|
|
err.stack.split('\n'):
|
|
|
|
err.stack,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-02-23 16:53:34 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-03-02 23:45:52 +08:00
|
|
|
assert.run = function (cb, progress) {
|
|
|
|
progress = progress || function () {};
|
2021-02-23 16:53:34 +08:00
|
|
|
var count = ASSERTS.length;
|
2021-03-02 23:45:52 +08:00
|
|
|
var total = ASSERTS.length;
|
2021-02-23 16:53:34 +08:00
|
|
|
var done = function (err) {
|
|
|
|
count--;
|
|
|
|
if (err) { failMessages.push(err); }
|
|
|
|
if (count === 0) {
|
|
|
|
cb({
|
|
|
|
total: ASSERTS.length,
|
|
|
|
passed: passed,
|
|
|
|
errors: failMessages,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ASSERTS.forEach(function (f, index) {
|
|
|
|
f(function (err) {
|
|
|
|
//console.log("test " + index);
|
2021-03-02 23:45:52 +08:00
|
|
|
progress(index, total);
|
2021-02-23 16:53:34 +08:00
|
|
|
done(err, index);
|
|
|
|
}, index);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return assert;
|
|
|
|
};
|
|
|
|
});
|