Add support for manually stepping through tests

This commit is contained in:
Ladd Hoffman 2023-03-02 10:28:28 -06:00
parent aba7cc6870
commit 3072dbae28
33 changed files with 197 additions and 122 deletions

View File

@ -37,6 +37,7 @@ module.exports = {
'no-multi-assign': ['off'], 'no-multi-assign': ['off'],
'no-constant-condition': ['off'], 'no-constant-condition': ['off'],
'no-await-in-loop': ['off'], 'no-await-in-loop': ['off'],
'no-underscore-dangle': ['off'],
}, },
globals: { globals: {
_: 'readonly', _: 'readonly',
@ -44,5 +45,6 @@ module.exports = {
sinon: 'readonly', sinon: 'readonly',
sinonChai: 'readonly', sinonChai: 'readonly',
should: 'readonly', should: 'readonly',
mocha: 'readonly',
}, },
}; };

View File

@ -2,16 +2,20 @@ import { DisplayValue } from './display-value.js';
import { randomID } from '../../util.js'; import { randomID } from '../../util.js';
export class Box { export class Box {
constructor(name, parentEl, elementType = 'div') { constructor(name, parentEl, options = {}) {
this.name = name; this.name = name;
this.el = document.createElement(elementType); this.el = document.createElement('div');
this.el.id = `box_${randomID()}`; this.el.id = `box_${randomID()}`;
this.el.classList.add('box'); this.el.classList.add('box');
if (name) { if (name) {
this.el.setAttribute('box-name', name); this.el.setAttribute('box-name', name);
} }
if (parentEl) { if (parentEl) {
parentEl.appendChild(this.el); if (options.prepend) {
parentEl.prepend(this.el);
} else {
parentEl.appendChild(this.el);
}
} }
} }
@ -35,8 +39,8 @@ export class Box {
return this; return this;
} }
addBox(name, elementType) { addBox(name) {
const box = new Box(name, this.el, elementType); const box = new Box(name, this.el);
return box; return box;
} }

View File

@ -0,0 +1,52 @@
class Button {
constructor(innerHTML, onclick) {
this.el = document.createElement('button');
this.el.innerHTML = innerHTML;
this.el.onclick = onclick;
}
}
export class Controls {
constructor(parentBox) {
this.disableAutoplayButton = new Button('Disable Auto-play', () => {
const url = new URL(window.location.href);
url.searchParams.set('auto', 'false');
window.location.href = url.href;
});
this.enableAutoplayButton = new Button('Enable Auto-play', () => {
const url = new URL(window.location.href);
url.searchParams.delete('auto');
window.location.href = url.href;
});
this.stepButton = new Button('Next Action', () => {
console.log('Next Action button clicked');
document.dispatchEvent(new Event('next-action'));
});
if (window.autoPlay) {
parentBox.el.appendChild(this.disableAutoplayButton.el);
} else {
parentBox.el.appendChild(this.enableAutoplayButton.el);
parentBox.el.appendChild(this.stepButton.el);
// Disable `stepButton` when test is complete
setInterval(() => {
this.stepButton.el.disabled = mocha._state !== 'running';
}, 200);
}
}
}
export async function delayOrWait(delayMs) {
if (window.autoPlay) {
await new Promise((resolve) => {
setTimeout(resolve, delayMs);
});
} else {
await new Promise((resolve) => {
document.addEventListener('next-action', () => {
console.log('next-action event received');
resolve();
}, { once: true });
});
}
}

View File

@ -4,6 +4,8 @@ import { MermaidDiagram } from './mermaid.js';
import { SequenceDiagram } from './sequence.js'; import { SequenceDiagram } from './sequence.js';
import { Table } from './table.js'; import { Table } from './table.js';
import { Flowchart } from './flowchart.js'; import { Flowchart } from './flowchart.js';
import { Controls } from './controls.js';
import { Box } from './box.js';
export class Scene { export class Scene {
constructor(name, rootBox) { constructor(name, rootBox) {
@ -24,6 +26,14 @@ export class Scene {
this.options = { this.options = {
edgeNodeColor: '#4d585c', edgeNodeColor: '#4d585c',
}; };
window.autoPlay = new URL(window.location.href).searchParams.get('auto') !== 'false';
if (!window.disableSceneControls) {
this.topRail = new Box('Top rail', document.body, { prepend: true }).addClass('top-rail');
this.controlsBox = this.topRail.addBox('Controls').addClass('controls');
this.controls = new Controls(this.controlsBox);
}
} }
withSequenceDiagram() { withSequenceDiagram() {

View File

@ -36,6 +36,17 @@ a:visited {
.padded { .padded {
padding: 20px; padding: 20px;
} }
.top-rail {
position: sticky;
top: 0;
left: 0;
width: 100%;
height: 0;
}
.controls {
position: relative;
left: 150px;
}
svg { svg {
width: 800px; width: 800px;
} }
@ -49,3 +60,14 @@ td {
.edge > rect { .edge > rect {
fill: #216262 !important; fill: #216262 !important;
} }
button {
margin: 5px;
margin-top: 1em;
background-color: #c6f4ff;
border-color: #b6b6b6;
border-radius: 5px;
}
button:disabled {
background-color: #2a535e;
color: #919191;
}

View File

@ -12,6 +12,9 @@
<div id="mocha"></div> <div id="mocha"></div>
<div id="scene"></div> <div id="scene"></div>
</body> </body>
<script>
window.disableSceneControls = true;
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js" <script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js"
integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg==" integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script> crossorigin="anonymous" referrerpolicy="no-referrer"></script>
@ -32,12 +35,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', 'vm', 'graph', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
window.should = chai.should(); window.should = chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -26,12 +26,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'requestor', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
window.should = chai.should(); window.should = chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -25,12 +25,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
window.should = chai.should(); window.should = chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -25,12 +25,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', 'vm', 'graph', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
window.should = chai.should(); window.should = chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -26,12 +26,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', 'vm', 'graph', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
window.should = chai.should(); window.should = chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -21,12 +21,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -21,12 +21,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -21,12 +21,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -21,12 +21,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -21,12 +21,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -20,7 +20,6 @@
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script src="./scripts/mocha.test.js"></script> <script src="./scripts/mocha.test.js"></script>

View File

@ -1,10 +1,11 @@
import { Box } from '../../classes/display/box.js'; import { Box } from '../../classes/display/box.js';
import { Scene } from '../../classes/display/scene.js'; import { Scene } from '../../classes/display/scene.js';
import { Expert } from '../../classes/actors/expert.js'; import { Expert } from '../../classes/actors/expert.js';
import { delay } from '../../util.js';
import { DAO } from '../../classes/dao/dao.js'; import { DAO } from '../../classes/dao/dao.js';
import { Public } from '../../classes/actors/public.js'; import { Public } from '../../classes/actors/public.js';
import { PostContent } from '../../classes/util/post-content.js'; import { PostContent } from '../../classes/util/post-content.js';
import { delayOrWait } from '../../classes/display/controls.js';
import { mochaRun } from '../../util.js';
const DELAY_INTERVAL = 100; const DELAY_INTERVAL = 100;
const POOL_DURATION = 200; const POOL_DURATION = 200;
@ -43,7 +44,7 @@ const setup = async () => {
await newExpert(); await newExpert();
requestor = new Public('Public', scene); requestor = new Public('Public', scene);
await delay(DELAY_INTERVAL); await delayOrWait(DELAY_INTERVAL);
// Experts gain initial reputation by submitting a post with fee // Experts gain initial reputation by submitting a post with fee
const { postId: postId1, pool: pool1 } = await experts[0].submitPostWithFee( const { postId: postId1, pool: pool1 } = await experts[0].submitPostWithFee(
@ -54,10 +55,10 @@ const setup = async () => {
tokenLossRatio: 1, tokenLossRatio: 1,
}, },
); );
await delay(POOL_DURATION); await delayOrWait(POOL_DURATION);
await pool1.evaluateWinningConditions(); await pool1.evaluateWinningConditions();
await delay(DELAY_INTERVAL); await delayOrWait(DELAY_INTERVAL);
dao.reputation.valueOwnedBy(experts[0].reputationPublicKey).should.equal(10); dao.reputation.valueOwnedBy(experts[0].reputationPublicKey).should.equal(10);
@ -71,10 +72,10 @@ const setup = async () => {
tokenLossRatio: 1, tokenLossRatio: 1,
}, },
); );
await delay(POOL_DURATION); await delayOrWait(POOL_DURATION);
await pool2.evaluateWinningConditions(); await pool2.evaluateWinningConditions();
await delay(DELAY_INTERVAL); await delayOrWait(DELAY_INTERVAL);
dao.reputation.valueOwnedBy(experts[0].reputationPublicKey).should.equal(15); dao.reputation.valueOwnedBy(experts[0].reputationPublicKey).should.equal(15);
dao.reputation.valueOwnedBy(experts[1].reputationPublicKey).should.equal(5); dao.reputation.valueOwnedBy(experts[1].reputationPublicKey).should.equal(5);
@ -106,7 +107,9 @@ const voteForWorkEvidence = async (worker, pool) => {
} }
}; };
describe('Availability + Business', () => { describe('Availability + Business', function tests() {
this.timeout(0);
before(async () => { before(async () => {
await setup(); await setup();
}); });
@ -122,7 +125,7 @@ describe('Availability + Business', () => {
it('Experts can register their availability for some duration', async () => { it('Experts can register their availability for some duration', async () => {
await experts[0].registerAvailability(1, 10000); await experts[0].registerAvailability(1, 10000);
await experts[1].registerAvailability(1, 10000); await experts[1].registerAvailability(1, 10000);
await delay(DELAY_INTERVAL); await delayOrWait(DELAY_INTERVAL);
}); });
it('Public can submit a work request', async () => { it('Public can submit a work request', async () => {
@ -131,7 +134,7 @@ describe('Availability + Business', () => {
{ fee: 100 }, { fee: 100 },
{ please: 'do some work' }, { please: 'do some work' },
); );
await delay(DELAY_INTERVAL); await delayOrWait(DELAY_INTERVAL);
}); });
it('Expert can submit work evidence', async () => { it('Expert can submit work evidence', async () => {
@ -153,11 +156,11 @@ describe('Availability + Business', () => {
await voteForWorkEvidence(worker, pool3); await voteForWorkEvidence(worker, pool3);
// Wait for validation pool duration to elapse // Wait for validation pool duration to elapse
await delay(POOL_DURATION); await delayOrWait(POOL_DURATION);
// Distribute reputation awards and fees // Distribute reputation awards and fees
await pool3.evaluateWinningConditions(); await pool3.evaluateWinningConditions();
await delay(DELAY_INTERVAL); await delayOrWait(DELAY_INTERVAL);
// This should throw an exception since the pool is already resolved // This should throw an exception since the pool is already resolved
try { try {
@ -167,3 +170,5 @@ describe('Availability + Business', () => {
} }
}).timeout(10000); }).timeout(10000);
}); });
mochaRun();

View File

@ -1,8 +1,10 @@
import { Business } from '../../classes/actors/business.js'; import { Business } from '../../classes/dao/business.js';
import { Scene } from '../../classes/display/scene.js'; import { Scene } from '../../classes/display/scene.js';
import { Box } from '../../classes/display/box.js'; import { Box } from '../../classes/display/box.js';
import { mochaRun } from '../../util.js';
describe('Business', () => { describe('Business', function tests() {
this.timeout(0);
let scene; let scene;
before(async () => { before(async () => {
const rootElement = document.getElementById('scene'); const rootElement = document.getElementById('scene');
@ -14,3 +16,5 @@ describe('Business', () => {
should.exist(business); should.exist(business);
}); });
}); });
mochaRun();

View File

@ -2,7 +2,7 @@ import { Box } from '../../classes/display/box.js';
import { Scene } from '../../classes/display/scene.js'; import { Scene } from '../../classes/display/scene.js';
import { Action } from '../../classes/display/action.js'; import { Action } from '../../classes/display/action.js';
import { Actor } from '../../classes/display/actor.js'; import { Actor } from '../../classes/display/actor.js';
import { debounce, delay } from '../../util.js'; import { debounce, delay, mochaRun } from '../../util.js';
describe('Debounce', () => { describe('Debounce', () => {
let scene; let scene;
@ -70,3 +70,5 @@ describe('Debounce', () => {
await scene.sequence.endSection(); await scene.sequence.endSection();
}); });
}); });
mochaRun();

View File

@ -4,9 +4,12 @@ import { PostContent } from '../../classes/util/post-content.js';
import { Expert } from '../../classes/actors/expert.js'; import { Expert } from '../../classes/actors/expert.js';
import { ForumNode } from '../../classes/forum-network/forum-node.js'; import { ForumNode } from '../../classes/forum-network/forum-node.js';
import { Network } from '../../classes/forum-network/network.js'; import { Network } from '../../classes/forum-network/network.js';
import { delay, randomID } from '../../util.js'; import { mochaRun, randomID } from '../../util.js';
import { delayOrWait } from '../../classes/display/controls.js';
describe('Forum Network', function tests() {
this.timeout(0);
describe('Forum Network', () => {
let scene; let scene;
let author1; let author1;
let author2; let author2;
@ -58,19 +61,21 @@ describe('Forum Network', () => {
1.0, 1.0,
); );
await delay(1000); await delayOrWait(1000);
await author1.submitPostViaNetwork( await author1.submitPostViaNetwork(
forumNode1, forumNode1,
post1, post1,
50, 50,
); );
await delay(1000); await delayOrWait(1000);
await author2.submitPostViaNetwork( await author2.submitPostViaNetwork(
forumNode2, forumNode2,
post2, post2,
100, 100,
); );
await delay(1000); await delayOrWait(1000);
}).timeout(10000); }).timeout(10000);
}); });
mochaRun();

View File

@ -2,9 +2,9 @@ import { Box } from '../../../classes/display/box.js';
import { Scene } from '../../../classes/display/scene.js'; import { Scene } from '../../../classes/display/scene.js';
import { Expert } from '../../../classes/actors/expert.js'; import { Expert } from '../../../classes/actors/expert.js';
import { PostContent } from '../../../classes/util/post-content.js'; import { PostContent } from '../../../classes/util/post-content.js';
import { delay } from '../../../util.js';
import params from '../../../params.js'; import params from '../../../params.js';
import { DAO } from '../../../classes/dao/dao.js'; import { DAO } from '../../../classes/dao/dao.js';
import { delayOrWait } from '../../../classes/display/controls.js';
export class ForumTest { export class ForumTest {
constructor(options) { constructor(options) {
@ -38,10 +38,10 @@ export class ForumTest {
}, },
); );
this.posts.push(postId); this.posts.push(postId);
await delay(this.options.poolDurationMs); await delayOrWait(this.options.poolDurationMs);
await pool.evaluateWinningConditions(); await pool.evaluateWinningConditions();
await this.scene.sequence.endSection(); await this.scene.sequence.endSection();
await delay(this.options.defaultDelayMs); await delayOrWait(this.options.defaultDelayMs);
return postId; return postId;
} }

View File

@ -1,6 +1,9 @@
import { mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js'; import { ForumTest } from './forum.test-util.js';
describe('Forum', () => { describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest(); const forumTest = new ForumTest();
before(async () => { before(async () => {
@ -37,3 +40,5 @@ describe('Forum', () => {
// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);
mochaRun();

View File

@ -1,6 +1,9 @@
import { mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js'; import { ForumTest } from './forum.test-util.js';
describe('Forum', () => { describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest(); const forumTest = new ForumTest();
before(async () => { before(async () => {
@ -37,3 +40,5 @@ describe('Forum', () => {
// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);
mochaRun();

View File

@ -1,6 +1,9 @@
import { mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js'; import { ForumTest } from './forum.test-util.js';
describe('Forum', () => { describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest(); const forumTest = new ForumTest();
before(async () => { before(async () => {
@ -40,3 +43,5 @@ describe('Forum', () => {
// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);
mochaRun();

View File

@ -1,6 +1,9 @@
import { mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js'; import { ForumTest } from './forum.test-util.js';
describe('Forum', () => { describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest(); const forumTest = new ForumTest();
before(async () => { before(async () => {
@ -68,3 +71,5 @@ describe('Forum', () => {
// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);
mochaRun();

View File

@ -1,6 +1,9 @@
import { mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js'; import { ForumTest } from './forum.test-util.js';
describe('Forum', () => { describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest(); const forumTest = new ForumTest();
before(async () => { before(async () => {
@ -57,3 +60,5 @@ describe('Forum', () => {
// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);
mochaRun();

View File

@ -2,8 +2,9 @@ import { Box } from '../../classes/display/box.js';
import { Scene } from '../../classes/display/scene.js'; import { Scene } from '../../classes/display/scene.js';
import { Expert } from '../../classes/actors/expert.js'; import { Expert } from '../../classes/actors/expert.js';
import { PostContent } from '../../classes/util/post-content.js'; import { PostContent } from '../../classes/util/post-content.js';
import { delay } from '../../util.js';
import { DAO } from '../../classes/dao/dao.js'; import { DAO } from '../../classes/dao/dao.js';
import { delayOrWait } from '../../classes/display/controls.js';
import { mochaRun } from '../../util.js';
const POOL_DURATION_MS = 100; const POOL_DURATION_MS = 100;
const DEFAULT_DELAY_MS = 100; const DEFAULT_DELAY_MS = 100;
@ -35,10 +36,11 @@ async function setup() {
await newExpert(); await newExpert();
await newExpert(); await newExpert();
await delay(DEFAULT_DELAY_MS); await delayOrWait(DEFAULT_DELAY_MS);
} }
describe('Validation Pool', () => { describe('Validation Pool', function tests() {
this.timeout(0);
before(async () => { before(async () => {
await setup(); await setup();
}); });
@ -73,9 +75,9 @@ describe('Validation Pool', () => {
} }
} }
await scene.sequence.endSection(); await scene.sequence.endSection();
await delay(POOL_DURATION_MS); await delayOrWait(POOL_DURATION_MS);
await pool.evaluateWinningConditions(); // Vote passes await pool.evaluateWinningConditions(); // Vote passes
await delay(DEFAULT_DELAY_MS); await delayOrWait(DEFAULT_DELAY_MS);
}); });
it('Failure example: second expert can not self-approve', async () => { it('Failure example: second expert can not self-approve', async () => {
@ -85,9 +87,9 @@ describe('Validation Pool', () => {
duration: POOL_DURATION_MS, duration: POOL_DURATION_MS,
tokenLossRatio: 1, tokenLossRatio: 1,
}); });
await delay(POOL_DURATION_MS); await delayOrWait(POOL_DURATION_MS);
await pool.evaluateWinningConditions(); // Quorum not met! await pool.evaluateWinningConditions(); // Quorum not met!
await delay(DEFAULT_DELAY_MS); await delayOrWait(DEFAULT_DELAY_MS);
} catch (e) { } catch (e) {
e.message.should.match(/Quorum is not met/); e.message.should.match(/Quorum is not met/);
} }
@ -104,8 +106,10 @@ describe('Validation Pool', () => {
amount: 4, amount: 4,
lockingTime: 0, lockingTime: 0,
}); });
await delay(POOL_DURATION_MS); await delayOrWait(POOL_DURATION_MS);
await pool.evaluateWinningConditions(); // Stake passes await pool.evaluateWinningConditions(); // Stake passes
await delay(DEFAULT_DELAY_MS); await delayOrWait(DEFAULT_DELAY_MS);
}); });
}); });
mochaRun();

View File

@ -2,6 +2,7 @@ import { Actor } from '../../classes/display/actor.js';
import { Box } from '../../classes/display/box.js'; import { Box } from '../../classes/display/box.js';
import { Scene } from '../../classes/display/scene.js'; import { Scene } from '../../classes/display/scene.js';
import { VM } from '../../classes/supporting/vm.js'; import { VM } from '../../classes/supporting/vm.js';
import { mochaRun } from '../../util.js';
const contractIds = ['contract-id-1', 'contract-id-2']; const contractIds = ['contract-id-1', 'contract-id-2'];
@ -29,7 +30,9 @@ class Repeater extends Actor {
} }
} }
describe('VM', () => { describe('VM', function tests() {
this.timeout(0);
let vm; let vm;
let sender; let sender;
let vmHandle; let vmHandle;
@ -68,3 +71,5 @@ describe('VM', () => {
.should.equal('Repeater world: good day'); .should.equal('Repeater world: good day');
}); });
}); });
mochaRun();

View File

@ -1,12 +1,15 @@
import { Box } from '../../classes/display/box.js'; import { Box } from '../../classes/display/box.js';
import { Scene } from '../../classes/display/scene.js'; import { Scene } from '../../classes/display/scene.js';
import { WDAG } from '../../classes/supporting/wdag.js'; import { WDAG } from '../../classes/supporting/wdag.js';
import { mochaRun } from '../../util.js';
const rootElement = document.getElementById('scene'); const rootElement = document.getElementById('scene');
const rootBox = new Box('rootBox', rootElement).flex(); const rootBox = new Box('rootBox', rootElement).flex();
window.scene = new Scene('WDAG test', rootBox); window.scene = new Scene('WDAG test', rootBox);
describe('Query the graph', () => { describe('Query the graph', function tests() {
this.timeout(0);
let graph; let graph;
before(() => { before(() => {
@ -43,3 +46,5 @@ describe('Query the graph', () => {
]); ]);
}); });
}); });
mochaRun();

View File

@ -25,12 +25,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -21,12 +21,6 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['vm', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
window.should = chai.should(); window.should = chai.should();
</script> </script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -21,13 +21,7 @@
<script defer class="mocha-init"> <script defer class="mocha-init">
mocha.setup({ mocha.setup({
ui: 'bdd', ui: 'bdd',
globals: ['graph', '__REACT_DEVTOOLS_*'],
}); });
mocha.checkLeaks();
chai.should(); chai.should();
</script> </script>
<script type="module" src="./scripts/wdag.test.js"></script> <script type="module" src="./scripts/wdag.test.js"></script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -38,3 +38,9 @@ export const displayNumber = (value, decimals = 2) => (value.toString().length >
: value); : value);
export const randomID = () => CryptoUtil.randomUUID().replaceAll('-', '').slice(0, 8); export const randomID = () => CryptoUtil.randomUUID().replaceAll('-', '').slice(0, 8);
export const mochaRun = () => {
if (mocha._state !== 'running') {
mocha.run();
}
};