UNPKG

aft-mocha-reporter

Version:

Automated Functional Testing (AFT) Reporter for use with Mocha Test Framework

105 lines 4.77 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.aftMochaTest = exports.AftMochaTest = void 0; const aft_core_1 = require("aft-core"); /** * expects to be passed the scope from an executing Mocha * test (i.e. the `this` argument) * > **NOTE:** * > * > the Mocha `this` scope is only available when tests * are written using * > * > `it('description', function() {...})` * > * > and _not_ when using * > * > `it('description', () => {...})` * > * @param scope the `this` scope from within a Mocha `it` */ class AftMochaTest extends aft_core_1.AftTest { /** * expects to be passed the scope from an executing Mocha * test (i.e. the `this` argument) * #### NOTE: * > the Mocha `this` scope is only available when tests * are written using * > * > `it('description', function() {...})` * > * > and _not_ when using * > * > `it('description', () => {...})` * > * @param scope the `this` scope from within a Mocha `it` */ constructor(scope, testFunction, options) { var _a, _b; testFunction !== null && testFunction !== void 0 ? testFunction : (testFunction = () => null); options !== null && options !== void 0 ? options : (options = {}); options._cacheResultsToFile = true; let description; if ((_a = scope === null || scope === void 0 ? void 0 : scope.test) === null || _a === void 0 ? void 0 : _a.fullTitle) { description = (_b = scope === null || scope === void 0 ? void 0 : scope.test) === null || _b === void 0 ? void 0 : _b.fullTitle(); } else if (typeof scope === 'string') { description = scope; } else { description = `${AftMochaTest.name}_${aft_core_1.rand.getString(8, true, true)}`; } super(description, testFunction, options); this.test = scope === null || scope === void 0 ? void 0 : scope.test; } _generateTestResult(status, resultMessage, testId) { const _super = Object.create(null, { _generateTestResult: { get: () => super._generateTestResult } }); var _a, _b; return __awaiter(this, void 0, void 0, function* () { const result = yield _super._generateTestResult.call(this, status, resultMessage, testId); if (((_a = result === null || result === void 0 ? void 0 : result.metadata) === null || _a === void 0 ? void 0 : _a['durationMs']) && ((_b = this.test) === null || _b === void 0 ? void 0 : _b.duration) > 0) { result.metadata['durationMs'] = this.test.duration; } return result; }); } } exports.AftMochaTest = AftMochaTest; /** * creates a new `AftMochaTest` instace to be used for executing some Functional * Test Assertion and calls the `run` function to execute the `testFunction`. * * ex: * ```typescript * it('[C1234] example usage for AftTest', async function() { * await aftMochaTest(this, async (v: AftMochaTest) => { * await v.reporter.info('doing some testing...'); * const feature = new FeatureObj(); * await v.verify(() => feature.returnExpectedValueAsync(), equaling('expected value')); * }); // if PolicyManager.shouldRun('C1234') returns `false` the assertion is not run * }) * ``` * @param context a `this` representing the current `Mocha.Context` containing the * `Mocha.Test` used to get the test description or a `string` description * @param testFunction the `Func<AftMochaTest, void | PromiseLike<void>>` function to be * executed by this `AftMochaTest` * @param options an optional `AftTestOptions` object containing overrides to internal * configuration and settings * @returns an async `Promise<void>` that runs the passed in `testFunction` */ const aftMochaTest = (context, testFunction, options) => __awaiter(void 0, void 0, void 0, function* () { return new AftMochaTest(context, testFunction, options).run(); }); exports.aftMochaTest = aftMochaTest; //# sourceMappingURL=aft-mocha-test.js.map