UNPKG

soda-test

Version:

Package for Unit and API tests

68 lines 2.92 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.createTestPlan = void 0; const glob = require("glob"); const fs = require('fs'); // eslint-disable-line @typescript-eslint/no-var-requires const test_lib_1 = require("./test-lib"); const testplan_1 = require("./test-lib/testplan"); const ts_import_1 = require("ts-import"); const compiler = new ts_import_1.Compiler({ compilerOptions: { downlevelIteration: true, emitDecoratorMetadata: true, experimentalDecorators: true, module: "commonjs", resolveJsonModule: true, skipLibCheck: true, target: "ES6" }, fallback: false, logger: undefined, }); // since ts-import is using fs.promises.rm, that does not exist, we set it to fs.promises.unlink that // does the same job. if (!fs.promises.rm) { fs.promises.rm = fs.promises.unlink; } function createTestPlan(argv) { return __awaiter(this, void 0, void 0, function* () { if (argv.length < 3 || argv.length > 4 || argv[0].indexOf('node') < 0 || argv[1].indexOf('plan') < 0) { console.error('Invalid script command'); return; } test_lib_1.environment.PLAN_MODE = 'YES'; const filesPattern = argv[2]; const matches = yield new Promise((resolve, reject) => glob(filesPattern, { absolute: true }, (err, matches) => (err) ? reject(err) : resolve(matches))); (0, testplan_1.PlanReset)(); for (const match of matches) { console.info(`analizing ${match}`); if (match.endsWith('.ts')) { yield compiler.compile(match); } else { require(match); } } const testplan = (0, testplan_1.GetPlan)(); if (argv.length < 4) { console.log(JSON.stringify(testplan, null, 2)); return; } // save the target json fs.writeFileSync(argv[3], JSON.stringify(testplan, null, 2)); }); } exports.createTestPlan = createTestPlan; if (!test_lib_1.environment.SKIP_CREATE_TESTPLAN) { createTestPlan(process.argv); } //# sourceMappingURL=plan.js.map