clean up /assert/ scripts and create a new instance checkup page
parent
d4291fb3ed
commit
ce1f96ac61
@ -0,0 +1,48 @@
|
||||
define([], function () {
|
||||
return function () {
|
||||
var failMessages = [];
|
||||
var passed = 0;
|
||||
var ASSERTS = [];
|
||||
|
||||
var assert = function (test, msg) {
|
||||
ASSERTS.push(function (cb, i) {
|
||||
test(function (result) {
|
||||
if (result === true) {
|
||||
passed++;
|
||||
cb();
|
||||
} else {
|
||||
cb({
|
||||
test: i,
|
||||
message: msg,
|
||||
output: result,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
assert.run = function (cb) {
|
||||
var count = ASSERTS.length;
|
||||
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);
|
||||
done(err, index);
|
||||
}, index);
|
||||
});
|
||||
};
|
||||
|
||||
return assert;
|
||||
};
|
||||
});
|
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<script data-bootload="main.js" data-main="/common/boot.js" src="/bower_components/requirejs/require.js"></script>
|
||||
|
||||
<style>
|
||||
.report {
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
.success {
|
||||
border: 3px solid green;
|
||||
}
|
||||
.failure {
|
||||
border: 3px solid red;
|
||||
}
|
||||
.error {
|
||||
border: 1px solid red;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
@ -0,0 +1,49 @@
|
||||
define([
|
||||
'jquery',
|
||||
'/api/config',
|
||||
'/assert/assertions.js',
|
||||
'/common/hyperscript.js',
|
||||
'/customize/messages.js',
|
||||
|
||||
'/bower_components/tweetnacl/nacl-fast.min.js',
|
||||
'less!/customize/src/less2/pages/page-assert.less',
|
||||
], function ($, ApiConfig, Assertions, h, Messages) {
|
||||
var assert = Assertions();
|
||||
|
||||
assert(function (cb) {
|
||||
var c = ApiConfig;
|
||||
cb(Boolean(c.httpUnsafeOrigin && c.httpSafeOrigin));
|
||||
}, "Sandbox configuration: ensure that both httpUnsafeOrigin and httpSafeOrigin are defined"); // XXX
|
||||
|
||||
assert(function (cb) {
|
||||
var c = ApiConfig;
|
||||
return void cb(c.httpUnsafeOrigin !== c.httpSafeOrigin);
|
||||
}, 'Sandbox configuration: httpUnsafeOrigin !== httpSafeOrigin'); // XXX
|
||||
|
||||
assert(function (cb) {
|
||||
cb((window.location.origin + '/') === ApiConfig.httpUnsafeOrigin);
|
||||
}, 'Sandbox configuration: loading via httpUnsafeOrigin'); // XXX
|
||||
|
||||
assert.run(function (state) {
|
||||
var errors = state.errors;
|
||||
var failed = errors.length;
|
||||
|
||||
Messages.assert_numberOfTestsPassed = "{0} / {1} tests passed.";
|
||||
|
||||
var statusClass = failed? 'failure': 'success';
|
||||
$('body').prepend(h('div.report.' + statusClass, [
|
||||
Messages._getKey('assert_numberOfTestsPassed', [
|
||||
state.passed,
|
||||
state.total
|
||||
]),
|
||||
h('div.failures', errors.map(function (obj) {
|
||||
return h('p.error', [
|
||||
h('p', "Test number: " + obj.test),
|
||||
h('p', "Error message: " + obj.message),
|
||||
h('p', "Returned value: " + obj.output),
|
||||
h('br'),
|
||||
]);
|
||||
})),
|
||||
]));
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue