Add --config and --help command options (#390)

truffle-plugin
cgewecke 5 years ago
parent c0c554a31e
commit 07ca4d3f02
  1. 16
      dist/truffle.plugin.js
  2. 7
      lib/ui.js
  3. 38
      test/units/app.js
  4. 7
      test/util/integration.truffle.js

@ -41,20 +41,26 @@ async function plugin(truffleConfig){
let truffle;
let testsErrored = false;
let coverageConfig;
let coverageConfigPath;
let solcoverjs;
// Load truffle lib, .solcover.js & launch app
try {
truffle = loadTruffleLibrary();
coverageConfigPath = path.join(truffleConfig.working_directory, '.solcover.js');
coverageConfig = req.silent(coverageConfigPath) || {};
(truffleConfig.solcoverjs)
? solcoverjs = path.join(truffleConfig.working_directory, truffleConfig.solcoverjs)
: solcoverjs = path.join(truffleConfig.working_directory, '.solcover.js');
coverageConfig = req.silent(solcoverjs) || {};
coverageConfig.cwd = truffleConfig.working_directory;
coverageConfig.originalContractsDir = truffleConfig.contracts_directory;
app = new App(coverageConfig);
if (truffleConfig.help){
return app.ui.report('truffle-help')
}
truffle = loadTruffleLibrary();
} catch (err) {
throw err;
}

@ -23,6 +23,11 @@ class UI {
const kinds = {
'truffle-help': `Usage: truffle run coverage [options]\n\n` +
`Options:\n` +
` --file: path (or glob) to run subset of JS test files\n` +
` --solcoverjs: relative path to .solcover.js (ex: ./../.solcover.js)\n`,
'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`,
'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`,
@ -33,7 +38,7 @@ class UI {
`\n${c.bold('=====================')}\n`,
'instr-item': `${ct} ${args[0]}`,
'instr-skipped': `${ds} ${c.grey(args[0])}`
'instr-skipped': `${ds} ${c.grey(args[0])}`,
}
this.log(emoji.emojify(kinds[kind]));

@ -54,11 +54,13 @@ function getOutput(truffleConfig){
describe('app', function() {
let truffleConfig;
let solcoverConfig;
let collector;
beforeEach(() => {
mock.clean();
truffleConfig = mock.getDefaultTruffleConfig();
solcoverConfig = {};
truffleConfig = mock.getDefaultTruffleConfig();
if (process.env.SILENT)
solcoverConfig.silent = true;
@ -145,6 +147,40 @@ describe('app', function() {
await plugin(truffleConfig);
});
it('truffle run coverage --config ../.solcover.js', async function() {
assertCleanInitialState();
solcoverConfig = {
silent: process.env.SILENT ? true : false,
istanbulReporter: ['json-summary', 'text']
};
fs.writeFileSync('.solcover.js', `module.exports=${JSON.stringify(solcoverConfig)}`);
// This relative path has to be ./ prefixed
// (because it's path.joined to truffle's working_directory)
truffleConfig.solcoverjs = './../.solcover.js';
mock.install('Simple', 'simple.js');
await plugin(truffleConfig);
// The relative solcoverjs uses the json-summary reporter which
// this assertion requires
const expected = [{
file: pathToContract(truffleConfig, 'Simple.sol'),
pct: 100
}];
assertLineCoverage(expected);
shell.rm('.solcover.js');
});
it('truffle run coverage --help', async function(){
assertCleanInitialState();
truffleConfig.help = "true";
mock.install('Simple', 'simple.js', solcoverConfig);
await plugin(truffleConfig);
})
it('truffle run coverage --file test/<fileName>', async function() {
assertCleanInitialState();

@ -97,7 +97,9 @@ function install(
noMigrations
) {
const configjs = getSolcoverJS(config);
let configjs;
if(config) configjs = getSolcoverJS(config);
const trufflejs = getTruffleConfigJS(_truffleConfig);
const migration = deploySingle(contract);
@ -116,7 +118,7 @@ function install(
// Configs
fs.writeFileSync(`${temp}/${truffleConfigName}`, trufflejs);
fs.writeFileSync(configPath, configjs);
if(config) fs.writeFileSync(configPath, configjs);
decacheConfigs();
@ -169,6 +171,7 @@ function clean() {
shell.rm('-Rf', temp);
shell.rm('-Rf', 'coverage');
shell.rm('coverage.json');
shell.rm('.solcover.js');
shell.config.silent = false;
};

Loading…
Cancel
Save