1
0

TestRegistry.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module.exports = class TestRegistry {
  2. constructor (t) {
  3. this.t = t;
  4. this.sdks = {};
  5. this.tests = {};
  6. this.benches = {};
  7. }
  8. add_test_sdk (id, instance) {
  9. this.t.sdks[id] = instance;
  10. }
  11. add_test (id, testDefinition) {
  12. this.tests[id] = testDefinition;
  13. }
  14. add_bench (id, benchDefinition) {
  15. this.benches[id] = benchDefinition;
  16. }
  17. async run_all_tests () {
  18. for ( const id in this.tests ) {
  19. const testDefinition = this.tests[id];
  20. await this.t.runTestPackage(testDefinition);
  21. }
  22. }
  23. // copilot was able to write everything below this line
  24. // and I think that's pretty cool
  25. async run_all_benches () {
  26. for ( const id in this.benches ) {
  27. const benchDefinition = this.benches[id];
  28. await this.t.runBenchmark(benchDefinition);
  29. }
  30. }
  31. async run_all () {
  32. await this.run_all_tests();
  33. await this.run_all_benches();
  34. }
  35. async run_test (id) {
  36. const testDefinition = this.tests[id];
  37. if ( ! testDefinition ) {
  38. throw new Error(`Test not found: ${id}`);
  39. }
  40. await this.t.runTestPackage(testDefinition);
  41. }
  42. async run_bench (id) {
  43. const benchDefinition = this.benches[id];
  44. if ( ! benchDefinition ) {
  45. throw new Error(`Bench not found: ${id}`);
  46. }
  47. await this.t.runBenchmark(benchDefinition);
  48. }
  49. async run (id) {
  50. if ( this.tests[id] ) {
  51. await this.run_test(id);
  52. } else if ( this.benches[id] ) {
  53. await this.run_bench(id);
  54. } else {
  55. throw new Error(`Test or bench not found: ${id}`);
  56. }
  57. }
  58. }