UNPKG

create-tezos-smart-contract

Version:

Node.js toolset to write, test and deploy Tezos smart contracts

80 lines (79 loc) 3.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.testWithJest = void 0; const chalk_1 = __importDefault(require("chalk")); const child_process_1 = require("child_process"); const console_1 = require("../../console"); const config_1 = require("../config"); const flextesa_1 = require("../flextesa"); const start_sandbox_1 = require("../../commands/start-sandbox"); const launchTests = async (options) => { return new Promise(async (resolve, reject) => { const initMillis = (new Date()).getTime(); const cwd = (0, console_1.getCWD)(); const args = [ "--colors", ]; if (options.e2e) { args.push("--testMatch='**/*.e2e.js'", "--runInBand"); } const env = { ...process.env, TEZOS_NETWORK: options.network, USE_OLD_BUILD: options.oldBuild ? 'true' : 'false', }; if (options.deployedContracts) { env.DEPLOYED_CONTRACTS = Object.keys(options.deployedContracts) .map(contract => `${contract}:${options.deployedContracts?.[contract]}`) .join(';'); } console.log(chalk_1.default.reset()); try { const npmJest = (0, child_process_1.spawn)("jest", args, { cwd, env }); npmJest.on('error', (err) => { (0, console_1.error)(`ERROR Starting Jest: ${err}`); }); npmJest.on("close", async (code) => { if (code) { process.exit(code); } const finishMillis = (new Date()).getTime(); (0, console_1.debug)(`✅ Testing process done in ${(finishMillis - initMillis) / 1000} s.`); // resolve(); process.exit(0); }); npmJest.stdout.on("data", (data) => { process.stdout.write(data); }); npmJest.stderr.on("data", (data) => { process.stderr.write(data); }); } catch (err) { (0, console_1.error)(`ERROR Starting Jest, ${err}`); } }); }; const testWithJest = async (bundle, options) => { let internalSandbox = false; if (options.network === config_1.ToolchainNetworks.SANDBOX) { if (!await (0, flextesa_1.isFlextesaRunning)()) { const config = await bundle.readConfigFile(); if (!config.autoSandbox) { (0, console_1.error)(`ERROR: Unable to find a running Sandbox to deploy testing contracts.\nYou can turn on "autoSandbox" in config.json to make it automatically start/stop during tests,\nor control it yourself with the start-sandbox command.`); process.exit(1); } internalSandbox = true; // Await sandbox preparation await new Promise((resolve) => (0, start_sandbox_1.startSandbox)({}, resolve)); } } await launchTests(options); if (internalSandbox) { await (0, flextesa_1.stopFlextesa)(); } }; exports.testWithJest = testWithJest;