@academyjs/rover
Version:
Rover allows you to learn programming interactively.
87 lines • 2.73 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = exports.styleInterface = void 0;
const test_1 = __importDefault(require("../test"));
const suite_1 = require("../suite");
const common_1 = __importDefault(require("./common"));
const { EVENT_FILE_PRE_REQUIRE } = suite_1.constants;
/**
* QUnit-style interface:
*
* suite('Array');
*
* test('#length', function() {
* var arr = [1,2,3];
* ok(arr.length == 3);
* });
*
* test('#indexOf()', function() {
* var arr = [1,2,3];
* ok(arr.indexOf(1) == 0);
* ok(arr.indexOf(2) == 1);
* ok(arr.indexOf(3) == 2);
* });
*
* suite('String');
*
* test('#length', function() {
* ok('foo'.length == 3);
* });
*
* @param {Suite} suite Root suite.
*/
function styleInterface(suite) {
const suites = [suite];
suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
const common = (0, common_1.default)(suites, context, mocha);
context.before = common.before;
context.after = common.after;
context.beforeEach = common.beforeEach;
context.afterEach = common.afterEach;
context.run = mocha.options.delay && common.runWithSuite(suite);
/**
* Describe a "suite" with the given `title`.
*/
context.suite = (options) => {
if (suites.length > 1) {
suites.shift();
}
return common.suite.create(Object.assign({ file, fn: false }, options));
};
/**
* Exclusive Suite.
*/
context.suite.only = (title) => {
if (suites.length > 1) {
suites.shift();
}
return common.suite.only({
title: title,
file: file,
fn: false,
});
};
/**
* Describe a specification or test-case
* with the given `title` and callback `fn`
* acting as a thunk.
*/
context.test = (title, description, fn) => {
const test = new test_1.default(title, description, fn);
test.file = file;
suites[0].addTest(test);
return test;
};
/**
* Exclusive test-case.
*/
context.test.only = (title, fn) => common.test.only(mocha, context.test(title, fn));
context.test.skip = common.test.skip;
});
}
exports.styleInterface = styleInterface;
exports.description = "QUnit style";
//# sourceMappingURL=qunit.js.map