UNPKG

@platform/ts

Version:

TypesScript build, prepare and publish toolchain.

67 lines (66 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.test = void 0; var tslib_1 = require("tslib"); var common_1 = require("../common"); function test(args) { if (args === void 0) { args = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var silent, watch, log, dir, _a, flags, _b, suffix, pattern, cmd, done, res, error_1; return tslib_1.__generator(this, function (_c) { switch (_c.label) { case 0: silent = args.silent, watch = args.watch; log = (0, common_1.getLog)(silent); _a = args.dir; if (_a) return [3, 2]; return [4, common_1.paths.closestParentOf('package.json')]; case 1: _a = (_c.sent()); _c.label = 2; case 2: dir = _a; if (!dir) { return [2, common_1.result.fail("A module root with [package.json] could not be found.")]; } flags = ''; flags += "--require ts-node/register \\"; if (watch) { flags += "--reporter min \\"; flags += "--watch-extensions ts,tsx \\"; flags += "--watch \\"; } _b = args.suffix, suffix = _b === void 0 ? 'TEST,test' : _b; suffix = suffix.includes(',') ? "{".concat(suffix, "}") : suffix; pattern = "src/**/*.".concat(suffix, ".ts{,x}"); if (!watch) { log.info(pattern); } cmd = "\n export NODE_ENV=test\n export TS_NODE_TRANSPILE_ONLY=true\n export TS_NODE_FAST=true\n export TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\" }'\n \n mocha \\\n ".concat(flags, "\n '").concat(pattern, "' \\\n "); done = function (res) { return res.code === 0 ? res : common_1.result.fail("Tests failed.", res.code); }; _c.label = 3; case 3: _c.trys.push([3, 5, , 6]); return [4, common_1.exec.cmd.run(cmd, { silent: silent, cwd: common_1.fs.resolve(dir) })]; case 4: res = _c.sent(); if (!res.ok && res.errors.some(function (line) { return line.includes('Error: No test files found'); })) { log.info("No tests found.\n"); return [2, done({ ok: true, code: 0 })]; } if (!res.ok && res.errors.length > 0) { res.errors.forEach(function (line) { return log.info(line); }); log.info(); } return [2, done(res)]; case 5: error_1 = _c.sent(); return [2, common_1.result.fail(error_1)]; case 6: return [2]; } }); }); } exports.test = test;