UNPKG

@forzalabs/remora

Version:

A powerful CLI tool for seamless data translation.

114 lines (113 loc) 5.39 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const Affirm_1 = __importDefault(require("../Affirm")); const fs = __importStar(require("fs")); const path_1 = __importDefault(require("path")); /** * This class is used to abstract away all calls that are non-deterministic. * As of now they just return non-deterministic values, but in the future the implementation can be easily replaced with deterministic code */ class DeterministicSimulationTestingEngine { constructor() { this.init = (options) => { (0, Affirm_1.default)(options, 'Invalid options'); this._options = options; }; /** * returns a random number between 0 and 1 */ this.random = () => Math.random(); this.now = () => new Date(); this.simulate = () => { const dir = __dirname; const root = path_1.default.join(dir, '..', '..', '..'); const folders = fs.readdirSync(root); const testFolder = folders.find(x => x === '_tests'); if (testFolder) { const baseCommand = `npx tsx ./${testFolder}`; const testFiles = fs.readdirSync(testFolder); for (let i = 0; i < testFiles.length; i++) { const testFile = testFiles[i]; const command = `${baseCommand}/${testFile}`; console.log('starting command', command); const tt = (0, child_process_1.execSync)(command); console.log('completed command', tt); // TODO: I can't get the output back from this execution and not even the console gets logged } } }; this.tests = (tests) => __awaiter(this, void 0, void 0, function* () { const results = yield Promise.all(tests); console.log(results.map(x => `- ${x.message}`).join('\n')); const count = results.length; const successCount = results.filter(x => x.success).length; const failCount = results.filter(x => !x.success).length; console.log(`\nTests summary:\n- test count: ${count}\n- successes: \x1b[42m${successCount}\x1b[0m\n- failures: \x1b[41m${failCount}\x1b[0m`); }); this.test = (name, fn) => __awaiter(this, void 0, void 0, function* () { try { const res = yield Promise.resolve(fn()); if (!res) return { message: `test "${name}"\x1b[41m failed.\x1b[0m`, success: false }; else return { message: `test "${name}"\x1b[42m succeded.\x1b[0m`, success: true }; } catch (error) { const myerror = error; return { message: `test "${name}"\x1b[41m crashed\x1b[0m with message: ${myerror.message}; trace: ${myerror.stack}`, success: false }; } }); } } /** * Deterministic Simulation Testing Engine */ const DSTE = new DeterministicSimulationTestingEngine(); DSTE.init({ seed: 0 }); // this is going to bite me in the butt... exports.default = DSTE;