Skip to content

Commit

Permalink
👔: prevent protocol timeout error from crashing test run
Browse files Browse the repository at this point in the history
  • Loading branch information
merryman committed Dec 16, 2024
1 parent 63a284d commit 93a1698
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions lively.server/plugins/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,49 @@ export default class TestRunner {
async run (module_to_test) {
let results;
try {
this.headlessSession = new HeadlessSession();
await this.headlessSession.open('http://localhost:9011/worlds/load?name=__newWorld__&askForWorldName=false&fastLoad=false', (sess) => sess.runEval(`typeof $world !== 'undefined' && $world.name == 'aLivelyWorld' && $world._uiInitialized`));
results = await this.headlessSession.runEval(`
const { resource } = await System.import("lively.resources");
const { promise } = await System.import('lively.lang')
const { localInterface } = await System.import("lively-system-interface");
const { loadPackage } = await System.import("lively-system-interface/commands/packages.js");
const packageToTestLoaded = localInterface.coreInterface.getPackages().find(pkg => pkg.name === '${module_to_test}');
if (!packageToTestLoaded){
await loadPackage(localInterface.coreInterface, {
name: '${module_to_test}',
address: 'http://localhost:9011/local_projects/${module_to_test}',
type: 'package'
this.headlessSession = new HeadlessSession();
let attempts = 1;
while (true) {
try {
await this.headlessSession.open('http://localhost:9011/worlds/load?name=__newWorld__&askForWorldName=false&fastLoad=false', (sess) => sess.runEval(`typeof $world !== 'undefined' && $world.name == 'aLivelyWorld' && $world._uiInitialized`));
} catch (err) {
if (attempts < 3) {
attempts++;
await sleep(1000);
console.log('Failed to load browser, retrying...')
continue;
}
else throw err;
}
break;
}
results = await this.headlessSession.runEval(`
const { resource } = await System.import("lively.resources");
const { promise } = await System.import('lively.lang')
const { localInterface } = await System.import("lively-system-interface");
const { loadPackage } = await System.import("lively-system-interface/commands/packages.js");
const packageToTestLoaded = localInterface.coreInterface.getPackages().find(pkg => pkg.name === '${module_to_test}');
if (!packageToTestLoaded){
await loadPackage(localInterface.coreInterface, {
name: '${module_to_test}',
address: 'http://localhost:9011/local_projects/${module_to_test}',
type: 'package'
});
}
$world.handForPointerId(1);
await System.import('mocha-es6/index.js');
await promise.waitFor(()=> !!window.chai && !!window.Mocha);
const { default: TestRunner } = await System.import("lively.ide/test-runner.js");
const runner = new TestRunner();
const results = await runner.runTestsInPackage('${module_to_test}');
results.forEach(r => {
r.tests?.forEach(t => {
if (t.error) t.error = true
else t.error = false;
})
});
}
$world.handForPointerId(1);
await System.import('mocha-es6/index.js');
await promise.waitFor(()=> !!window.chai && !!window.Mocha);
const { default: TestRunner } = await System.import("lively.ide/test-runner.js");
const runner = new TestRunner();
const results = await runner.runTestsInPackage('${module_to_test}');
results.forEach(r => {
r.tests?.forEach(t => {
if (t.error) t.error = true
else t.error = false;
})
});
JSON.stringify(results);
`)
JSON.stringify(results);
`)
} catch (err) {
results = JSON.stringify({ error: err.message });
} finally {
Expand Down

0 comments on commit 93a1698

Please sign in to comment.