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 bb25019
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions lively.server/plugins/test-runner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HeadlessSession } from 'lively.headless';
import { promise } from 'lively.lang';

export default class TestRunner {
async setup (livelyServer) {
Expand All @@ -8,35 +9,50 @@ 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'
let attempts = 1;
while (true) {
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`));
} catch (err) {
if (attempts < 3) {
attempts++;
await this.headlessSession.dispose();
await promise.delay(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 bb25019

Please sign in to comment.