Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lively.headless/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class HeadlessSession {
return this;
} catch (err) {
console.error(`[lively.headless] ${err.stack}`);
try { this.close(); } catch (err) {}
try { await this.close(); } catch (err) {}
this.state = SESSION_STATE.ERRORED;
this.error = String(err.stack);
throw err;
Expand Down
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