aft-jest-reporter
Version:
Automated Functional Testing (AFT) Reporter for use with Jest Test Framework
114 lines • 5.01 kB
JavaScript
;
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.aftJestTest = exports.AftJestTest = void 0;
const aft_core_1 = require("aft-core");
/**
* expects to be passed a context scope from an executing Jest
* test. for Jest, the `JestExpect` type contains this so you
* can use an `expect` like follows:
*
* ```typescript
* test('perform some testing', () => {
* const t = new AftJestTest(expect, () => doStuff());
* })
* ```
* @param scope the `expect` object from within a Jest `test`
*/
class AftJestTest extends aft_core_1.AftTest {
/**
* expects to be passed a context scope from an executing Jest
* test. for Jest, the `JestExpect` type contains this so you
* can use an `expect` like follows:
*
* ```typescript
* test('perform some testing', () => {
* const t = new AftJestTest(expect, () => doStuff());
* })
* ```
* @param scope the `expect` object from within a Jest `test`
*/
constructor(scope, testFunction, options) {
let test;
let description;
if (typeof scope === 'string') {
description = scope;
}
else if (scope === null || scope === void 0 ? void 0 : scope.fullName) {
// 'scope' is a 'TestCaseResult'
test = scope;
description = test.fullName;
}
else if (scope === null || scope === void 0 ? void 0 : scope.getState) {
// 'scope' is an 'expect' object
const state = scope.getState();
description = state.currentTestName;
}
else {
description = `${AftJestTest.name}_${aft_core_1.rand.getString(8, true, true)}`;
}
testFunction !== null && testFunction !== void 0 ? testFunction : (testFunction = () => null);
options !== null && options !== void 0 ? options : (options = {});
options._cacheResultsToFile = true;
super(description, testFunction, options);
this.test = test;
}
/**
* see: `pending`
* @param reason the reason for skipping this test
*/
skipped(reason) {
return __awaiter(this, void 0, void 0, function* () {
return this.pending(reason);
});
}
_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.AftJestTest = AftJestTest;
/**
* creates a new `AftJestTest` instace to be used for executing some Functional
* Test Assertion and calls the `run` function to execute the `testFunction`.
*
* ex:
* ```typescript
* test('[C1234] example usage for AftTest', () => {
* await aftJestTest(expect, async (v: AftJestTest) => {
* 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 expect a `JestExpect` or `jest.Expect` containing a `fullName` property used
* as the test description or a `string` description
* @param testFunction the `Func<AftJestTest, void | PromiseLike<void>>` function to be
* executed by this `AftJestTest`
* @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 aftJestTest = (expect, testFunction, options) => __awaiter(void 0, void 0, void 0, function* () {
return new AftJestTest(expect, testFunction, options).run();
});
exports.aftJestTest = aftJestTest;
//# sourceMappingURL=aft-jest-test.js.map