UNPKG

@academyjs/rover

Version:

Rover allows you to learn programming interactively.

66 lines 2.28 kB
"use strict"; 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 suite_1 = __importDefault(require("../suite")); const test_1 = __importDefault(require("../test")); /** * Exports-style (as Node.js module) interface: * * exports.Array = { * '#indexOf()': { * 'should return -1 when the value is not present': function() { * * }, * * 'should return the correct index when the value is present': function() { * * } * } * }; * * @param suite * Root suite */ const styleInterface = (suite) => { const suites = [suite]; const visit = (object, file) => { // eslint-disable-next-line no-restricted-syntax for (const key of Object.keys(object)) { if (typeof object[key] === "function") { const callback = object[key]; switch (key) { case "before": suites[0].beforeAll(callback); break; case "after": suites[0].afterAll(callback); break; case "beforeEach": suites[0].beforeEach(callback); break; case "afterEach": suites[0].afterEach(callback); break; default: { const test = new test_1.default(key, "<unavailable>", callback); test.file = file; suites[0].addTest(test); } } } else { const newSuite = suite_1.default.create(suites[0], key); suites.unshift(newSuite); visit(object[key], file); suites.shift(); } } }; suite.on(suite_1.default.constants.EVENT_FILE_REQUIRE, visit); }; exports.styleInterface = styleInterface; exports.description = 'Node.js module ("exports") style'; //# sourceMappingURL=exports.js.map