UNPKG

aft-jest-reporter

Version:

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

61 lines 3.82 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 }); const globals_1 = require("@jest/globals"); const aft_core_1 = require("aft-core"); const src_1 = require("../src"); describe('AftJestReporter', () => { (0, globals_1.test)('can create an AftJestTest instance', () => __awaiter(void 0, void 0, void 0, function* () { const aft = new src_1.AftJestTest(globals_1.expect); yield aft.reporter.info('starting AftJestReporter test...'); (0, globals_1.expect)(aft.test).not.toBeDefined(); // only defined inside the Jest Reporter (0, globals_1.expect)(aft.description).toEqual('AftJestReporter can create an AftJestTest instance'); yield aft.reporter.info('completed AftJestReporter test.'); })); (0, globals_1.test)('can check if test should be run [C1234]', () => __awaiter(void 0, void 0, void 0, function* () { const t = new src_1.AftJestTest(globals_1.expect); const shouldRunSpy = globals_1.jest.spyOn(t, 'shouldRun').mockImplementation(() => Promise.resolve({ result: true, message: 'fake' })); const shouldRun = yield t.shouldRun(); (0, globals_1.expect)(shouldRun.result).toBeTruthy(); (0, globals_1.expect)(shouldRunSpy).toBeCalledTimes(1); })); (0, globals_1.test)('can skip test [C4567] if should not be run', () => __awaiter(void 0, void 0, void 0, function* () { const t = new src_1.AftJestTest(globals_1.expect); globals_1.jest.spyOn(t, 'shouldRun').mockImplementation(() => Promise.resolve({ result: false, message: 'fake' })); const shouldRun = yield t.shouldRun(); if (!shouldRun.result) { yield aft_core_1.Err.handleAsync(() => t.pending(shouldRun.message), { errLevel: 'none' }); return; // Jest doesn't support programmic skip https://github.com/jestjs/jest/issues/7245 } (0, globals_1.expect)(true).toBe(false); })); (0, globals_1.test)('[C1234] provides a AftJestTest instance for use in test control', () => __awaiter(void 0, void 0, void 0, function* () { yield (0, src_1.aftJestTest)(globals_1.expect, (v) => __awaiter(void 0, void 0, void 0, function* () { yield v.verify(v.description, 'AftJestReporter [C1234] provides a AftJestTest instance for use in test control'); yield v.verify(v.testIds, (0, aft_core_1.containing)('C1234'), 'expected to parse test ID from description'); })); })); (0, globals_1.test)('[C9999] allows retry to be wrapped around the aftJestTest', () => __awaiter(void 0, void 0, void 0, function* () { let index = 0; yield (0, aft_core_1.retry)((r) => (0, src_1.aftJestTest)(globals_1.expect, (t) => __awaiter(void 0, void 0, void 0, function* () { yield t.verify(index++, 2, '[C9999]'); }), { additionalMetadata: { attempt: r.totalAttempts } }), { delay: 10, backOffType: 'linear', maxDuration: 5000 }).until((t) => t.status === 'passed'); }), 6000); }); //# sourceMappingURL=aft-jest-reporter.spec.js.map