UNPKG

locklift

Version:

Node JS framework for working with Ever contracts. Inspired by Truffle and Hardhat. Helps you to build, test, run and maintain your smart contracts.

96 lines (95 loc) 4.32 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const mocha_1 = __importDefault(require("mocha")); require("ts-mocha"); const path_1 = __importDefault(require("path")); const directory_tree_1 = __importDefault(require("directory-tree")); const config_1 = require("../../config"); const index_1 = require("../../../index"); const utils = __importStar(require("../builder/utils")); const build_1 = require("../steps/build"); const program = new commander_1.Command(); program .name("test") .description("Run mocha tests") .option("--disable-build", "Disable automatic contracts build", false) .option("-t, --test <test>", "Path to Mocha test folder", "test") .option("-c, --contracts <contracts>", "Path to the contracts folder", "contracts") .option("-b, --build <build>", "Path to the build folder", "build") .option("-f, --force", "Force build contracts", false) .option("--disable-include-path", "Disables including node_modules. Use this with old compiler versions", false) .option("-n, --network <network>", "Network to use, choose from configuration", config_1.LOCKLIFT_NETWORK_NAME) .addOption(new commander_1.Option("--config <config>", "Path to the config file") .default(() => (0, config_1.loadConfig)("locklift.config.ts")) .argParser(config => () => (0, config_1.loadConfig)(config))) .option("--tests [tests...]", "Set of tests to run, separated by comma") .allowUnknownOption() .action(async (options) => { const config = options.config(); if (config.networks[options.network] === undefined) { console.error(`Can't find configuration for ${options.network} network!`); process.exit(1); } if (!options.disableBuild) { await (0, build_1.buildStep)(config, options, options.force); } // Initialize Locklift and pass it into tests context const locklift = await index_1.Locklift.setup(config, options.network); //@ts-ignore global.locklift = locklift; // Run mocha tests if (config.mocha?.tsconfig) { process.env.TS_NODE_PROJECT = config.mocha?.tsconfig; process.env.TS_CONFIG_PATHS = "true"; } const mocha = new mocha_1.default({ ...config.mocha }); // Run all .js files in tests or only specified tests let testFiles; if (Array.isArray(options.tests)) { testFiles = options.tests; } else { const testNestedTree = (0, directory_tree_1.default)(path_1.default.resolve(process.cwd(), options.test), { extensions: /\.(js|ts)/ }); testFiles = utils.flatDirTree(testNestedTree)?.map(t => t.path) || []; } testFiles.forEach((file) => mocha.addFile(file)); mocha.run(fail => process.exit(fail ? 1 : 0)); }); exports.default = program;