aft-mocha-reporter
Version:
Automated Functional Testing (AFT) Reporter for use with Mocha Test Framework
78 lines • 3.98 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 });
const chai_1 = require("chai");
const src_1 = require("../src");
const sinon = require("sinon");
const aft_core_1 = require("aft-core");
describe('AftMochaReporter', () => {
it('passes a Mocha Test to the test that can be used by AftMochaTest', function () {
return __awaiter(this, void 0, void 0, function* () {
this.timeout(10000);
const t = new src_1.AftMochaTest(this);
const shouldRun = yield t.shouldRun();
if (!shouldRun.result) {
yield t.pending(shouldRun.message);
}
(0, chai_1.expect)(t).to.exist;
(0, chai_1.expect)(t.reporter).to.exist;
(0, chai_1.expect)(t.reporter.name).to.equal(t.description);
yield t.reporter.trace('sample log message');
});
});
it('can skip a test during execution', function () {
return __awaiter(this, void 0, void 0, function* () {
this.timeout(10000);
const t = new src_1.AftMochaTest(this);
sinon.stub(t, 'shouldRun').callsFake(() => Promise.resolve({ result: false, message: 'fake' }));
const shouldRun = yield t.shouldRun();
if (!shouldRun.result) {
this.skip();
}
(0, chai_1.expect)(true).to.be.false;
});
});
it('still works if using an arrow function', () => __awaiter(void 0, void 0, void 0, function* () {
const t = new src_1.AftMochaTest(this);
(0, chai_1.expect)(t).to.exist;
(0, chai_1.expect)(t.reporter).to.exist;
(0, chai_1.expect)(t.description).to.contain(src_1.AftMochaTest.name);
// NOTE: arrow functions have no `this` so `this.test.fullTitle()` doesn't exist
(0, chai_1.expect)(t.reporter.name).to.equal(t.description);
yield t.reporter.trace('sample log message from aft-mocha-reporter.spec with arrow function');
}));
it('[C1234] provides a AftMochaTest instance for use in test control', function () {
return __awaiter(this, void 0, void 0, function* () {
this.timeout(10000);
yield (0, src_1.aftMochaTest)(this, (v) => __awaiter(this, void 0, void 0, function* () {
yield v.verify(v.description, 'AftMochaReporter [C1234] provides a AftMochaTest instance for use in test control');
yield v.verify(v.testIds, (0, aft_core_1.containing)('C1234'), 'expected to parse test ID from description');
}));
});
});
it('[C9999] allows retry to be wrapped around the aftMochaTest', function () {
return __awaiter(this, void 0, void 0, function* () {
let index = 0;
yield (0, aft_core_1.retry)((r) => (0, src_1.aftMochaTest)(this, (t) => __awaiter(this, 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');
});
});
});
//# sourceMappingURL=aft-mocha-reporter.spec.js.map