UNPKG

@academyjs/rover

Version:

Rover allows you to learn programming interactively.

70 lines 2.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const base_1 = __importDefault(require("./base")); const runner_1 = require("../runner"); const { EVENT_SUITE_BEGIN, EVENT_SUITE_END, EVENT_TEST_END, EVENT_RUN_END } = runner_1.constants; class JSONAllReporter extends base_1.default { /** * Constructs a new `JSON` reporter instance. * * @param runner - Instance triggers reporter actions. * @param options - runner options */ constructor(runner, options = {}) { super(runner, options); const rootSuites = []; const cachedSuites = {}; const stackedSuites = []; const suites = {}; runner.on(EVENT_SUITE_BEGIN, (suite) => { const { id, file, title, handle, description, tags } = suite; const newRecord = { id, file, title, handle, description, tags, tests: [], suites: [], }; if (!suite.parent) { rootSuites.push(newRecord); } else { cachedSuites[suite.parent.id].suites.push(newRecord); } cachedSuites[suite.id] = newRecord; if (suite.handle) { suites[suite.handle] = newRecord; } stackedSuites.push(newRecord); }); runner.on(EVENT_SUITE_END, (suite) => { stackedSuites.pop(); }); runner.on(EVENT_TEST_END, (test) => { const { title, description } = test; const currentSuite = stackedSuites[stackedSuites.length - 1]; currentSuite.tests.push({ title, description, }); }); runner.once(EVENT_RUN_END, () => { const result = { suites: rootSuites, stats: this.stats, }; runner.testResults = result; this.options.reporterOption.onComplete && this.options.reporterOption.onComplete(result, suites); }); } } JSONAllReporter.description = "single JSON object"; exports.default = JSONAllReporter; //# sourceMappingURL=json-all.js.map