@academyjs/rover
Version:
Rover allows you to learn programming interactively.
122 lines • 4.37 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const runnable_1 = __importDefault(require("./runnable"));
const utils = __importStar(require("./utils"));
const errors = __importStar(require("./errors"));
const { createInvalidArgumentTypeError } = errors;
const { isString } = utils;
const { MOCHA_ID_PROP_NAME } = utils.constants;
class Test extends runnable_1.default {
/**
* Initialize a new `Test` with the given `title` and callback `fn`.
*
* @public
* @class
* @extends Runnable
* @param {String} title - Test title (required)
* @param {Function} [fn] - Test callback. If omitted, the Test is considered "pending"
*/
constructor(title, description, fn) {
super(title, description, fn);
/**
* Set or get retried test
*
* @private
*/
this.retriedTest = function (n) {
if (!arguments.length) {
return this._retriedTest;
}
this._retriedTest = n;
};
/**
* Add test to the list of tests marked `only`.
*
* @private
*/
this.markOnly = function () {
this.parent.appendOnlyTest(this);
};
this.clone = function () {
const test = new Test(this.title, "<unavailable>", this.fn);
test.timeout(this.timeout());
test.slow(this.slow());
test.retries(this.retries());
test.currentRetry(this.currentRetry());
test.retriedTest(this.retriedTest() || this);
test.globals(this.globals());
test.parent = this.parent;
test.file = this.file;
test.ctx = this.ctx;
return test;
};
/**
* Returns an minimal object suitable for transmission over IPC.
* Functions are represented by keys beginning with `$$`.
* @private
* @returns {Object}
*/
this.serialize = function seridfalize() {
return {
$$currentRetry: this._currentRetry,
$$fullTitle: this.fullTitle(),
$$isPending: Boolean(this.pending),
$$retriedTest: this._retriedTest || null,
$$slow: this._slow,
$$titlePath: this.titlePath(),
body: this.body,
duration: this.duration,
err: this.err,
parent: {
$$fullTitle: this.parent.fullTitle(),
[MOCHA_ID_PROP_NAME]: this.parent.id,
},
speed: this.speed,
state: this.state,
title: this.title,
type: this.type,
file: this.file,
[MOCHA_ID_PROP_NAME]: this.id,
};
};
if (!isString(title)) {
throw createInvalidArgumentTypeError('Test argument "title" should be a string. Received type "' +
typeof title +
'"', "title", "string");
}
this.type = "test";
this.reset();
}
/**
* Resets the state initially or for a next run.
*/
reset() {
super.reset();
this.pending = !this.fn;
delete this.state;
}
}
exports.default = Test;
//# sourceMappingURL=test.js.map