@ply-ct/ply
Version:
REST API Automated Testing
60 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.after = exports.before = exports.test = exports.suite = void 0;
const names_1 = require("./names");
function suite(nameOrTarget) {
if (typeof nameOrTarget === 'string') {
// with decorator args: function params are dec args, return callback taking Target
return function (target) {
// class name is target.name
if (target[names_1.SUITE]) {
throw new Error(`@suite ${target.name} must not extend another @suite-decorated class.`);
}
target[names_1.SUITE] = { name: nameOrTarget };
};
}
else {
// no decorator args: first function param is ClassTarget
if (nameOrTarget[names_1.SUITE]) {
throw new Error(`@suite ${nameOrTarget.name} must not extend another @suite-decorated class.`);
}
nameOrTarget[names_1.SUITE] = { name: nameOrTarget.name };
}
}
exports.suite = suite;
function test(nameOrTarget, propertyKey, _descriptor) {
if (typeof nameOrTarget === 'string') {
return function (target, propertyKey, _descriptor) {
// with decorator args: function params are dec args, return callback taking Target, etc
target[propertyKey][names_1.TEST] = { name: nameOrTarget };
};
}
else {
// no decorator args: first function param is target, second is propKey, etc
nameOrTarget[propertyKey][names_1.TEST] = { name: propertyKey };
}
}
exports.test = test;
function before(testsOrTarget, propertyKey, _descriptor) {
if (typeof testsOrTarget === 'string') {
return function (target, propertyKey, _descriptor) {
target[propertyKey][names_1.BEFORE] = { name: propertyKey, tests: testsOrTarget };
};
}
else {
testsOrTarget[propertyKey][names_1.BEFORE] = { name: propertyKey };
}
}
exports.before = before;
function after(testsOrTarget, propertyKey, _descriptor) {
if (typeof testsOrTarget === 'string') {
return function (target, propertyKey, _descriptor) {
target[propertyKey][names_1.AFTER] = { name: propertyKey, tests: testsOrTarget };
};
}
else {
testsOrTarget[propertyKey][names_1.AFTER] = { name: propertyKey };
}
}
exports.after = after;
//# sourceMappingURL=decorators.js.map