const c = require('chalk'); const emoji = require('node-emoji'); /** * Coverage tool output handler. This is where any logging solidity-coverage does on its * own behalf is managed. NB, most output is generated by the host dev stack (e.g. truffle, * buidler or by the coverage generator (e.g. Istanbul). * ) */ class UI { constructor(log){ this.log = log || console.log; } /** * Writes a formatted message to console * @param {String} kind message selector * @param {String[]} args info to inject into template */ report(kind, args=[]){ const ct = c.bold.green('>'); const ds = c.bold.yellow('>'); const kinds = { 'vm-fail': `:warning: ${c.red('There was a problem attaching to the ganache-core VM.')} `+ `${c.red('Check the provider option syntax in solidity-coverage docs.')}\n`+ `:warning: ${c.red('Using ganache-core-sc (eq. core v2.7.0) instead.')}\n`, 'truffle-local': `\n${ct} ${c.grey('Using Truffle library from local node_modules.')}\n`, 'truffle-global': `\n${ct} ${c.grey('Using Truffle library from global node_modules.')}\n`, 'truffle-warn': `:warning: ${c.red('Unable to require Truffle library locally or globally. ')} `+ `${c.red('Expected to find installed Truffle >= v5.0.31 ...')}\n` + `:warning: ${c.red('Using fallback Truffle library instead (v5.0.31)')}\n`, 'truffle-help': `Usage: truffle run coverage [options]\n\n` + `Options:\n` + ` --file: path (or glob) to subset of JS test files. (Quote your globs)\n` + ` --solcoverjs: relative path to .solcover.js (ex: ./../.solcover.js)\n` + ` --version: version info\n`, 'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`, 'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`, 'coverage-version': `${ct} ${c.bold('solidity-coverage')}: v${args[0]}`, 'instr-start': `\n${c.bold('Instrumenting for coverage...')}` + `\n${c.bold('=============================')}\n`, 'instr-skip': `\n${c.bold('Coverage skipped for:')}` + `\n${c.bold('=====================')}\n`, 'instr-item': `${ct} ${args[0]}`, 'instr-skipped': `${ds} ${c.grey(args[0])}`, } this.log(emoji.emojify(kinds[kind])); } /** * Returns a formatted message. Useful for error message. * @param {String} kind message selector * @param {String[]} args info to inject into template * @return {String} message */ generate(kind, args=[]){ const kinds = { 'truffle-fail': `${c.red('Unable to load fail-safe Truffle library. Caught: ')} ${args[0]}\n` + `:x: ${c.red('Try installing Truffle >= v5.0.31 locally or globally.\n')}`, } return emoji.emojify(kinds[kind]) } } module.exports = UI;