UNPKG

@jawis/jates

Version:
106 lines (105 loc) 3.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestListController = void 0; const _jab_1 = require("@jawis/jab"); const _state_waiter_1 = require("state-waiter"); /** * - Re-form test queue, based on events from the user. * - Sort test cases by execution time. * - Send test selection structure to client, and ask TEC to execute the tests. * * Test selection structure * - Defines which tests the client presents to the user. * - Defines a prioritisation of the tests. E.g. sorted by exec time. * - Contains unselected tests as last level. * - It's ok to have the client present tests, that aren't going to execute. The user might be * interested in seeing the unselected tests. * * Test execution list * - A subset of the selection structure. The tests that will execute. * * choice: * - TEC guarantees not to send results, that are not in the test list. So we call tec.setTestList in same * tick as sending new test selection structure to the client. And the client is guranteed only ever to * receive test results in that list. The price is, that TEC drops the test result of the currently executing test. * small price for a conceptually simple management of test list switches. * - Otherwise we would have to filter tests, the client doesn't understand. Or give the client a list of all tests, so * it can filter tests not in the selection structure. Maybe that's no problem, after all. */ class TestListController { /** * */ constructor(deps) { this.deps = deps; /** * */ this.onRunAllTests = () => { const state = this.waiter.getState(); switch (state) { case "fetching": throw (0, _jab_1.err)("not impl."); case "idle": this.waiter.set("fetching"); this.deps.testFramework.getTestIds().then(this.onFetchDone); break; case "stopping": case "done": throw (0, _jab_1.err)("Not active."); default: (0, _jab_1.assertNever)(state); } }; /** * */ this.onRunCurrentSelection = () => { const state = this.waiter.getState(); switch (state) { case "fetching": throw (0, _jab_1.err)("not impl."); case "idle": this.waiter.set("fetching"); this.deps.testFramework .getCurrentSelectionTestIds() .then(this.onFetchDone); break; case "stopping": case "done": throw (0, _jab_1.err)("Not active."); default: (0, _jab_1.assertNever)(state); } }; /** * */ this.onFetchDone = (ids) => { const state = this.waiter.getState(); switch (state) { case "fetching": { this.waiter.set("idle"); const sortedIds = this.deps.ta.sortTests(ids); this.deps.onTestSelectionReady([sortedIds]); this.deps.setTestExecutionList(sortedIds); return; } case "idle": case "stopping": case "done": (0, _jab_1.err)("Impossible: " + state); return false; default: return (0, _jab_1.assertNever)(state); } }; this.waiter = new _state_waiter_1.Waiter({ onError: this.deps.onError, startState: "idle", stoppingState: "stopping", endState: "done", }); } } exports.TestListController = TestListController;