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

pull/391/head
cgewecke 5 years ago committed by GitHub
parent 0b54cf39eb
commit 57033fa764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 truffle;
let testsErrored = false; let testsErrored = false;
let coverageConfig; let coverageConfig;
let coverageConfigPath; let solcoverjs;
// Load truffle lib, .solcover.js & launch app // Load truffle lib, .solcover.js & launch app
try { try {
truffle = loadTruffleLibrary(); (truffleConfig.solcoverjs)
? solcoverjs = path.join(truffleConfig.working_directory, truffleConfig.solcoverjs)
coverageConfigPath = path.join(truffleConfig.working_directory, '.solcover.js'); : solcoverjs = path.join(truffleConfig.working_directory, '.solcover.js');
coverageConfig = req.silent(coverageConfigPath) || {};
coverageConfig = req.silent(solcoverjs) || {};
coverageConfig.cwd = truffleConfig.working_directory; coverageConfig.cwd = truffleConfig.working_directory;
coverageConfig.originalContractsDir = truffleConfig.contracts_directory; coverageConfig.originalContractsDir = truffleConfig.contracts_directory;
app = new App(coverageConfig); app = new App(coverageConfig);
if (truffleConfig.help){
return app.ui.report('truffle-help')
}
truffle = loadTruffleLibrary();
} catch (err) { } catch (err) {
throw err; throw err;
} }

@ -23,6 +23,11 @@ class UI {
const kinds = { 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]}`, 'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`,
'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`, 'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`,
@ -33,7 +38,7 @@ class UI {
`\n${c.bold('=====================')}\n`, `\n${c.bold('=====================')}\n`,
'instr-item': `${ct} ${args[0]}`, '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])); this.log(emoji.emojify(kinds[kind]));

@ -54,11 +54,13 @@ function getOutput(truffleConfig){
describe('app', function() { describe('app', function() {
let truffleConfig; let truffleConfig;
let solcoverConfig; let solcoverConfig;
let collector;
beforeEach(() => { beforeEach(() => {
mock.clean(); mock.clean();
truffleConfig = mock.getDefaultTruffleConfig();
solcoverConfig = {}; solcoverConfig = {};
truffleConfig = mock.getDefaultTruffleConfig();
if (process.env.SILENT) if (process.env.SILENT)
solcoverConfig.silent = true; solcoverConfig.silent = true;
@ -145,6 +147,40 @@ describe('app', function() {
await plugin(truffleConfig); 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() { it('truffle run coverage --file test/<fileName>', async function() {
assertCleanInitialState(); assertCleanInitialState();

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

Loading…
Cancel
Save