Skip to content

Commit f6759c1

Browse files
authored
✨ Refactor out mocha/chai (#12)
* Remove loaded check * πŸ› Fix arduino staging * Remove mocha and chai * Add parallel execution * Update reporter * Restore archiver * Update colour output * Fix parallel + dependence schedule * Fix scenario reporting * Add deep equal * Fix reporter * Fix parallel * Fix forest * Fix dependence schedule * Fix parallel schedule (hybrid) * Move testbed shutdown to end * Add recovery code * Add errors to reporter * Fix skipped + scheduling * Skip unnecessary reupload * Change parallel
1 parent 85ef8b4 commit f6759c1

9 files changed

Lines changed: 1004 additions & 1172 deletions

File tree

β€Žpackage-lock.jsonβ€Ž

Lines changed: 311 additions & 894 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir dist/cjs && npx convert-extension cjs dist/cjs/ && rm -f dist/cjs/*.map",
2323
"watch": "tsc -watch -p ./",
2424
"lint": "eslint src --ext ts",
25-
"test": "npx latch test/test.ts"
25+
"test": "npx ts-node test/test.ts",
26+
"debugtest": "npx ts-node test/debugger.test.ts",
27+
"spectest": "npx ts-node test/spec.ts"
2628
},
2729
"dependencies": {
28-
"chai": "^4.3.6",
30+
"ansi-colors": "^4.1.3",
2931
"ieee754": "^1.2.1",
30-
"mocha": "10.1.0",
32+
"ora": "^8.0.1",
3133
"source-map": "^0.7.4",
3234
"ts-node": "^10.5.0"
3335
},

β€Žsrc/framework/Framework.tsβ€Ž

Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import {Testee} from './Testee';
1+
import {Testee, timeout} from './Testee';
22
import {HybridScheduler, Scheduler} from './Scheduler';
33
import {TestScenario} from './scenario/TestScenario';
44

55
import {TestbedSpecification} from '../testbeds/TestbedSpecification';
6+
import {Reporter, SuiteResults} from './Reporter';
67

78
export interface Suite {
89

@@ -30,12 +31,15 @@ export class Suite {
3031
public scenarios: TestScenario[] = [];
3132
public testees: Testee[] = [];
3233

33-
public constructor(title: string) {
34+
public scheduler: Scheduler;
35+
36+
public constructor(title: string, scheduler: Scheduler = new HybridScheduler()) {
3437
this.title = title;
38+
this.scheduler = scheduler;
3539
}
3640

37-
public testee(name: string, specification: TestbedSpecification, scheduler: Scheduler = new HybridScheduler(), options: TesteeOptions = {}) {
38-
const testee = new Testee(name, specification, scheduler, options.timeout ?? 2000, options.connectionTimout ?? 5000);
41+
public testee(name: string, specification: TestbedSpecification, options: TesteeOptions = {}) {
42+
const testee = new Testee(name, specification, options.timeout ?? 2000, options.connectionTimout ?? 5000);
3943
if (options.disabled) {
4044
testee.skipall();
4145
}
@@ -61,11 +65,13 @@ export class Framework {
6165

6266
private scheduled: Suite[] = [];
6367

68+
public readonly reporter: Reporter = new Reporter();
69+
6470
private constructor() {
6571
}
6672

67-
public suite(title: string): Suite {
68-
return new Suite(title);
73+
public suite(title: string, scheduler: Scheduler = new HybridScheduler()): Suite {
74+
return new Suite(title, scheduler);
6975
}
7076

7177
public suites(): Suite[] {
@@ -80,45 +86,84 @@ export class Framework {
8086
return this.outputStyle;
8187
}
8288

83-
public run(suites: Suite[], cores: number = 1) { // todo remove cores
89+
public async sequential(suites: Suite[]) {
90+
this.scheduled.concat(suites);
91+
this.reporter.general();
92+
const t0 = performance.now();
93+
for (const suite of suites) {
94+
for (const testee of suite.testees) {
95+
const order: TestScenario[] = suite.scheduler.sequential(suite);
96+
const result: SuiteResults = new SuiteResults(suite, testee);
97+
98+
const first: TestScenario = order[0];
99+
await timeout<Object | void>('Initialize testbed', testee.connector.timeout, testee.initialize(first.program, first.args ?? []).catch((e: Error) => result.error = e));
100+
101+
await this.runSuite(result, testee, order);
102+
this.reporter.report(result);
103+
}
104+
}
105+
const t1 = performance.now();
106+
this.reporter.results(t1 - t0);
107+
}
108+
109+
public async run(suites: Suite[]) {
84110
this.scheduled.concat(suites);
85-
suites.forEach((suite: Suite) => {
86-
suite.testees.forEach((testee: Testee) => {
87-
const order: TestScenario[] = testee.scheduler.schedule(suite);
111+
this.reporter.general();
112+
const t0 = performance.now();
113+
await Promise.all(suites.map(async (suite: Suite) => {
114+
await Promise.all(suite.testees.map(async (testee: Testee) => {
115+
const order: TestScenario[] = suite.scheduler.sequential(suite);
116+
const result: SuiteResults = new SuiteResults(suite, testee);
117+
88118
const first: TestScenario = order[0];
89-
before('Initialize testbed', async function () {
90-
this.timeout(testee.connector.timeout);
91-
await testee.initialize(first.program, first.args ?? []).catch((e) => Promise.reject(e));
92-
});
93-
94-
describe(`${testee.name}: ${suite.title}`, () => {
95-
// todo add parallelism
96-
97-
// if (!bed.disabled) { // TODO necessary? isn't this done in de test itself?
98-
//
99-
// after('Shutdown debugger', async function () {
100-
// if (bed.describer.instance) {
101-
// await bed.connection.kill();
102-
// }
103-
// });
104-
// }
105-
106-
order.forEach((test: TestScenario) => {
107-
testee.describe(test, this.runs);
108-
});
109-
});
110-
111-
after('Shutdown testbed', async function () {
112-
await testee.shutdown();
113-
});
114-
});
115-
});
119+
await timeout<Object | void>('Initialize testbed', testee.connector.timeout, testee.initialize(first.program, first.args ?? []).catch((e: Error) => result.error = e));
120+
121+
await this.runSuite(result, testee, order);
122+
this.reporter.report(result);
123+
}))
124+
}))
125+
const t1 = performance.now();
126+
this.reporter.results(t1 - t0);
127+
}
128+
129+
public async parallel(suites: Suite[]) {
130+
this.scheduled.concat(suites);
131+
this.reporter.general();
132+
const t0 = performance.now();
133+
await Promise.all(suites.map(async (suite: Suite) => {
134+
const order: TestScenario[][] = suite.scheduler.parallel(suite, suite.testees.length);
135+
await Promise.all(suite.testees.map(async (testee: Testee, i: number) => {
136+
// console.log(`scheduling on ${testee.name}`)
137+
const result: SuiteResults = new SuiteResults(suite, testee);
138+
139+
const first: TestScenario = order[i][0];
140+
await timeout<Object | void>('Initialize testbed', testee.connector.timeout, testee.initialize(first.program, first.args ?? []).catch((e: Error) => result.error = e));
141+
142+
for (let j = i; j < order.length; j += suite.testees.length) {
143+
await this.runSuite(result, testee, order[j]);
144+
}
145+
this.reporter.report(result);
146+
}))
147+
148+
await Promise.all(suite.testees.map(async (testee: Testee) => {
149+
await timeout<Object | void>('Shutdown testbed', testee.timeout, testee.shutdown());
150+
}))
151+
}))
152+
153+
const t1 = performance.now();
154+
this.reporter.results(t1 - t0);
155+
}
156+
157+
private async runSuite(result: SuiteResults, testee: Testee, order: TestScenario[]) {
158+
for (const test of order) {
159+
await testee.describe(test, result, this.runs);
160+
}
116161
}
117162

118163
// Analyse flakiness
119-
public analyse(suite: Suite[], runs: number = 3, cores: number = 1) {
164+
public analyse(suite: Suite[], runs: number = 3) {
120165
this.runs = runs;
121-
this.run(suite, cores);
166+
this.run(suite);
122167
}
123168

124169
public static getImplementation() {

β€Žsrc/framework/MochaReporter.tsβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ interface Result {
4949

5050
class MochaReporter extends reporters.Base {
5151
private readonly framework: Framework;
52-
private coreReporter: Reporter;
5352

5453
private archiver: Archiver;
5554

@@ -72,7 +71,6 @@ class MochaReporter extends reporters.Base {
7271
super(runner, options);
7372

7473
this.framework = Framework.getImplementation();
75-
this.coreReporter = new Reporter(this.framework);
7674

7775
this.archiver = new Archiver(`${process.env.TESTFILE?.replace('.asserts.wast', '.wast') ?? 'suite'}.${Date.now()}.log`);
7876
this.archiver.set('date', new Date(Date.now()).toISOString());

0 commit comments

Comments
Β (0)