Spaces:
Sleeping
Sleeping
File size: 2,962 Bytes
61d39e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
module.exports = class TestRegistry {
constructor (t) {
this.t = t;
this.sdks = {};
this.tests = {};
this.benches = {};
}
add_test_sdk (id, instance) {
this.t.sdks[id] = instance;
}
add_test (id, testDefinition) {
this.tests[id] = testDefinition;
}
add_bench (id, benchDefinition) {
this.benches[id] = benchDefinition;
}
async run_all_tests(suiteName) {
// check if "suiteName" is valid
if (suiteName && !Object.keys(this.tests).includes(suiteName)) {
throw new Error(`Suite not found: ${suiteName}, valid suites are: ${Object.keys(this.tests).join(', ')}`);
}
for ( const id in this.tests ) {
if (suiteName && id !== suiteName) {
continue;
}
const testDefinition = this.tests[id];
try {
await this.t.runTestPackage(testDefinition);
} catch (e) {
// If stopOnFailure is enabled, the process will have already exited
// This catch block is just for safety
if (this.t.options.stopOnFailure) {
throw e;
}
}
}
}
// copilot was able to write everything below this line
// and I think that's pretty cool
async run_all_benches (suiteName) {
// check if "suiteName" is valid
if (suiteName && !Object.keys(this.benches).includes(suiteName)) {
throw new Error(`Suite not found: ${suiteName}, valid suites are: ${Object.keys(this.benches).join(', ')}`);
}
for ( const [id, bench_definition] of Object.entries(this.benches) ) {
if (suiteName && id !== suiteName) {
continue;
}
console.log(`running bench: ${id}`);
// reset the working directory
await this.t.init_working_directory();
await this.t.runBenchmark(bench_definition);
}
}
async run_all () {
await this.run_all_tests();
await this.run_all_benches();
}
async run_test (id) {
const testDefinition = this.tests[id];
if ( ! testDefinition ) {
throw new Error(`Test not found: ${id}`);
}
await this.t.runTestPackage(testDefinition);
}
async run_bench (id) {
const benchDefinition = this.benches[id];
if ( ! benchDefinition ) {
throw new Error(`Bench not found: ${id}`);
}
await this.t.runBenchmark(benchDefinition);
}
async run (id) {
if ( this.tests[id] ) {
await this.run_test(id);
} else if ( this.benches[id] ) {
await this.run_bench(id);
} else {
throw new Error(`Test or bench not found: ${id}`);
}
}
}
|