create-tezos-smart-contract
Version:
Node.js toolset to write, test and deploy Tezos smart contracts
60 lines (59 loc) • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.test = exports.addE2ETestCommand = void 0;
const console_1 = require("../../console");
const bundle_1 = require("../../modules/bundle");
const config_1 = require("../../modules/config");
const jest_1 = require("../../modules/jest");
const addE2ETestCommand = (program, debugHook) => {
program
.command('e2e-test')
.description('Perform end-to-end tests on smart contracts with Jest.')
.option('-n, --network <network>', `Choose to run test either in ${config_1.ToolchainNetworks.SANDBOX} or ${config_1.ToolchainNetworks.TESTNET} networks`)
.option('-c, --contracts <contracts>', 'Run E2E tests on a specific contract, rather than deploying it. Argument must be in the form of \"filename.ext:contractAddress\". You can pass more than one file:contract pairs separated by a semicolon (;)')
.option('--old-build', 'Use the latest contract build found instead of stopping/rebuilding')
.action((options) => {
(0, exports.test)(program, options);
})
.hook('preAction', debugHook);
};
exports.addE2ETestCommand = addE2ETestCommand;
// Lauch Jest to run unit tests
const test = async (program, options) => {
(0, console_1.em)(`Perform E2E tests...\n`);
// Read configfile
const contractsBundle = new bundle_1.ContractsBundle((0, console_1.getCWD)());
// Extract options from CLI
const { contracts, ...otherOptions } = options;
// Prepare options
const defaultOptions = {
network: config_1.ToolchainNetworks.SANDBOX,
};
// Build final options
const testOptions = Object.assign({}, defaultOptions, otherOptions);
// Force E2E testing
testOptions.e2e = true;
// Read the config so contracts folder settings will be there later
await contractsBundle.readConfigFile();
if (contracts) {
const contractNames = await contractsBundle.getContractsFiles();
const deployedContracts = {};
const pairs = contracts.split(';');
for (const pair of pairs) {
const tokens = pair.split(':');
if (tokens.length !== 2) {
(0, console_1.error)(`Contracts argument is in the wrong format: "${pair}" is not in the form "filename.ext:contractAddress!"`);
process.exit(1);
}
if (!contractNames.find(x => x === tokens[0])) {
(0, console_1.error)(`Contracts argument specifies a contract which is not part of this repository: "${tokens[0]}"`);
process.exit(1);
}
deployedContracts[tokens[0]] = tokens[1];
}
testOptions.deployedContracts = deployedContracts;
}
(0, console_1.log)(`Working on "${testOptions.network}" network`);
await (0, jest_1.testWithJest)(contractsBundle, testOptions);
};
exports.test = test;