UNPKG

jest-test-each

Version:

run parametrised tests easily [typesafe] without text tables or arrays of arrays.

84 lines (83 loc) 3.02 kB
"use strict"; 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 }); exports.createTest = exports.waitFinished = exports.cleanup = exports.result = void 0; const test_each_1 = require("../../test-each"); const index_1 = require("../../index"); const utils_1 = require("./utils"); const stripAnsi = require('strip-ansi'); const TestEachTesting = (env) => (desc) => { index_1.TestEachEnv(env); return new test_each_1.TestEach(desc); }; exports.result = { failures: [], passes: [], totalEntities: 0, suites: [], tests: [], skips: [], }; const started = { s: [] }; // todo think const cleanup = () => { started.s = []; exports.result.failures = []; exports.result.passes = []; exports.result.totalEntities = 0; exports.result.suites = []; exports.result.tests = []; exports.result.skips = []; index_1.TestEachSetup({ groupBySuites: true, numericCases: false }); }; exports.cleanup = cleanup; const suiteRunner = (name, body) => { // console.log('Suite started: ' + name); exports.result.totalEntities++; exports.result.suites.push(name); body(); }; const waitFinished = () => __awaiter(void 0, void 0, void 0, function* () { for (let i = 0; i < 1000; i++) { if (started.s.length === 0) { break; } yield utils_1.delay(1); } }); exports.waitFinished = waitFinished; const testRunner = ((name, body) => { var _a; started.s.push(name); exports.result.totalEntities++; exports.result.tests.push(name); const resultBody = body(); if ((_a = resultBody) === null || _a === void 0 ? void 0 : _a.then) { resultBody .then(k => exports.result.passes.push({ name: name })) .catch(err => exports.result.failures.push({ name, message: stripAnsi(err.message) })) .finally(() => started.s.pop()); } }); testRunner.only = testRunner; testRunner.concurrent = testRunner; /*testRunner.skip = ((name: string, body: () => Promise<void>) => { result.skips.push(stripAnsi(name || 'no reason')); }) as TestRunner;*/ const pending = (reason) => { exports.result.skips.push(stripAnsi(reason || 'no reason')); }; const createTest = (desc) => TestEachTesting({ describe: suiteRunner, it: testRunner, pending, })(desc); exports.createTest = createTest;