Add UI reporter class (#389)

* Add truffle.library.js (5.0.31) as fail-safe for require('truffle')
* Report truffle and ganache-core versions
pull/390/head
cgewecke 5 years ago committed by GitHub
parent cc3e18a34a
commit 0b54cf39eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 493393
      dist/truffle.library.js
  2. 16
      dist/truffle.plugin.js
  3. 24
      lib/app.js
  4. 53
      lib/ui.js
  5. 2
      package.json
  6. 12
      yarn.lock

493393
dist/truffle.library.js vendored

File diff suppressed because one or more lines are too long

@ -63,6 +63,16 @@ async function plugin(truffleConfig){
try {
death(app.cleanUp);
// Launch in-process provider
const provider = await app.provider(ganache);
const web3 = new Web3(provider);
const accounts = await web3.eth.getAccounts();
const nodeInfo = await web3.eth.getNodeInfo();
const ganacheVersion = nodeInfo.split('/')[1];
app.ui.report('truffle-version', [truffle.version]);
app.ui.report('ganache-version', [ganacheVersion]);
// Write instrumented sources to temp folder
app.instrument();
@ -81,9 +91,6 @@ async function plugin(truffleConfig){
// Launch in-process provider
const networkName = 'soliditycoverage';
const provider = await app.provider(ganache);
const accounts = await (new Web3(provider)).eth.getAccounts();
truffleConfig.network = networkName;
// Truffle alternately complains that fields are and
@ -136,11 +143,10 @@ function tests(truffle){
function loadTruffleLibrary(){
try { return require("truffle") } catch(err) {};
try { return require("./truffle.library")} catch(err) {};
throw new Error('Missing truffle lib...')
// TO DO: throw error? This point should never be reached.
}
/**

@ -7,6 +7,7 @@ const util = require('util');
const Instrumenter = require('./instrumenter');
const Coverage = require('./coverage');
const DataCollector = require('./collector');
const UI = require('./ui');
const isWin = /^win/.test(process.platform);
@ -36,7 +37,7 @@ class App {
this.skippedFolders = [];
this.skipFiles = config.skipFiles || [];
this.log = config.logger || console.log;
this.log = config.logger ? config.logger.log : console.log;
this.setLoggingLevel(config.silent);
this.gasLimit = 0xfffffffffff;
@ -44,6 +45,7 @@ class App {
this.gasPrice = 0x01;
this.istanbulReporter = config.istanbulReporter || ['html', 'lcov', 'text'];
this.ui = new UI(this.log);
}
// -------------------------------------- Methods -----------------------------------------------
@ -52,6 +54,8 @@ class App {
*/
instrument() {
let currentFile;
let started = false;
let skipped = [];
try {
this.sanityCheckContext();
@ -64,15 +68,18 @@ class App {
currentFile = file;
if (!this.shouldSkip(file)) {
this.log('Instrumenting ', file);
!started && this.ui.report('instr-start');
started = true;
// Remember the real path
const contractPath = this.platformNeutralPath(file);
const relativePath = contractPath.split(`/${this.contractsDirName}`)[1]
const canonicalPath = path.join(
this.originalContractsDir,
contractPath.split(`/${this.contractsDirName}`)[1]
relativePath
);
this.ui.report('instr-item', [relativePath])
// Instrument contract, save, add to coverage map
const contract = this.loadContract(contractPath);
@ -81,13 +88,22 @@ class App {
this.coverage.addContract(instrumented, canonicalPath);
} else {
this.log('Skipping instrumentation of ', file);
skipped.push(file);
}
});
} catch (err) {
const msg = `There was a problem instrumenting ${currentFile}: `;
this.cleanUp(msg + err);
}
if (skipped.length > 0){
this.ui.report('instr-skip');
skipped.forEach(item => {
item = item.split(`/${this.contractsDirName}`)[1]
this.ui.report('instr-skipped', [item])
});
}
}
/**

@ -0,0 +1,53 @@
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 = {
'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`,
'ganache-version': `${ct} ${c.bold('ganache-core')}: ${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){
}
}
module.exports = UI;

@ -21,11 +21,13 @@
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^2.4.2",
"death": "^1.1.0",
"ganache-core-sc": "2.7.0-sc.0",
"globby": "^10.0.1",
"istanbul": "^0.4.5",
"node-dir": "^0.1.17",
"node-emoji": "^1.10.0",
"req-cwd": "^1.0.1",
"shelljs": "^0.8.3",
"solidity-parser-antlr": "^0.4.7",

@ -5285,6 +5285,11 @@ lodash.flattendeep@^4.4.0:
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=
lodash.toarray@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.toarray/-/lodash.toarray-4.4.0.tgz#24c4bfcd6b2fba38bfd0594db1179d8e9b656561"
integrity sha1-JMS/zWsvuji/0FlNsRedjptlZWE=
lodash@4.17.14:
version "4.17.14"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
@ -5809,6 +5814,13 @@ node-dir@^0.1.17:
dependencies:
minimatch "^3.0.2"
node-emoji@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.10.0.tgz#8886abd25d9c7bb61802a658523d1f8d2a89b2da"
integrity sha512-Yt3384If5H6BYGVHiHwTL+99OzJKHhgp82S8/dktEK73T26BazdgZ4JZh92xSVtGNJvz9UbXdNAc5hcrXV42vw==
dependencies:
lodash.toarray "^4.4.0"
node-fetch-npm@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/node-fetch-npm/-/node-fetch-npm-2.0.2.tgz#7258c9046182dca345b4208eda918daf33697ff7"

Loading…
Cancel
Save