UNPKG

japa

Version:

Lean test runner for Node.js

152 lines (151 loc) 4.5 kB
"use strict"; /** * @module Core */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isCoreException = exports.TestsStore = void 0; /* * japa * * (c) Harminder Virk <virk@adonisjs.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ const time_span_1 = __importDefault(require("time-span")); const Contracts_1 = require("../Contracts"); const exceptions = __importStar(require("../Exceptions")); /** * Tests store class records the tests being executed and * returns a report to be used by the reporters. */ class TestsStore { constructor() { this._store = { passedCount: 0, skippedCount: 0, failedCount: 0, todoCount: 0, regressionCount: 0, total: 0, groups: [], duration: 0, }; } /** * Returns the currently active group */ get activeGroup() { return this._store.groups[this._store.groups.length - 1]; } /** * Record the group */ recordGroup(group) { this.open(); this._store.groups.push({ title: group.title, failedTests: [], failedHooks: [] }); } /** * End the group and record failed hooks */ endGroup(group) { if (group.status === Contracts_1.IGroupStatus.FAILED && this.activeGroup.title === group.title) { const error = group.error; this.activeGroup.failedHooks.push({ title: error.fnName || error.lifecycle, error }); } } /** * Record the test */ recordTest(test) { this.open(); /** * Store reference to test and the group when test has been * failed */ if (test.status === Contracts_1.ITestStatus.FAILED) { this.activeGroup.failedTests.push({ title: test.title, error: test.error }); } /** * Increment the total counter */ this._store.total++; /** * Increment individual test statuses counters */ switch (test.status) { case Contracts_1.ITestStatus.FAILED: this._store.failedCount++; break; case Contracts_1.ITestStatus.PASSED: this._store.passedCount++; break; case Contracts_1.ITestStatus.SKIPPED: this._store.skippedCount++; break; case Contracts_1.ITestStatus.TODO: this._store.todoCount++; break; } /** * Increment the regression counter */ if (test.regression) { this._store.regressionCount++; } } /** * Open store */ open() { if (!this._processStart) { this._processStart = (0, time_span_1.default)(); } } /** * Close store */ close() { if (!this._store.duration) { this._store.duration = this._processStart.rounded(); } } /** * Return store report */ getReport() { this.close(); return this._store; } } exports.TestsStore = TestsStore; /** * Returns a boolean telling if exception is part of core exceptions or * not. */ function isCoreException(error) { return !!Object.keys(exceptions).find((e) => error instanceof exceptions[e]); } exports.isCoreException = isCoreException;