Published
Edited
Jan 6, 2020
1 fork
Importers
10 stars
Insert cell
Insert cell
test("something is wrong", async t => {
t.plan(4);
t.equal(1, 1);
for (let i = 0; i < 2; i++) {
t.ok(1, `just making sure everything's okay, part ${i}`);
await Promises.delay(100);
}
t.ok(false, `but this is not ok`);
})
Insert cell
Insert cell
test('making sure that everything is okay', async t => {
t.plan(4);
t.equal(1, 1);
t.inDelta([0.000000000000001, -0.00000000001], [0,0]);
for (let i = 0; i < 3; i++) {
t.ok(1, `just making sure everything's okay, part ${i}`);
await Promises.delay(100);
}
})
Insert cell
Insert cell
test = {
const tape = await require(await FileAttachment("tape-4.12.js").url());
tape.Test.prototype.inDelta = inDelta;

return (name, fn, options) => {
let test = tape.createHarness();
let stream = test.createStream();
const output = html`<pre style='padding:2rem;overflow-x:auto;margin:0;' />`
const display = html`<div style='padding-bottom:1rem'><div style='position:relative;background:#F4F4F4;'>
<div style='text-align:center;font-weight:bold;text-transform:uppercase;padding:1rem 0;'>${name}</div>
${output}
</div></div>`
test(name, fn, options);
return Generators.observe(change => {
let results = '';
let failed = false;
stream.on('data', d => {
output.appendChild(document.createTextNode(d));
if (d.startsWith('not ok')) {
display.firstChild.style.background = '#FFDFDF';
failed = true;
}
change(display);
});
});
}
}
Insert cell
inDelta = {
function inDelta(actual, expected, delta) {
return (Array.isArray(expected) ? inDeltaArray : inDeltaNumber)(
actual,
expected,
delta
);
}
function inDeltaArray(actual, expected, delta) {
var n = expected.length,
i = -1;
if (actual.length !== n) return false;
while (++i < n) if (!inDelta(actual[i], expected[i], delta)) return false;
return true;
}
function inDeltaNumber(actual, expected, delta) {
return actual >= expected - delta && actual <= expected + delta;
}
return function(actual, expected, delta) {
delta = delta || 1e-6;
this._assert(inDelta(actual, expected, delta), {
message: "should be in delta " + delta,
operator: "inDelta",
actual: actual,
expected: expected
});
};
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more