Expand testfiles arg globs (#523)

pull/526/head
cgewecke 4 years ago committed by GitHub
parent 5ad384dd55
commit daf4b02e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      plugins/buidler.plugin.js
  2. 16
      plugins/resources/buidler.utils.js
  3. 31
      test/units/buidler/flags.js

@ -119,7 +119,9 @@ function plugin() {
// ======
// Tests
// ======
const testfiles = args.testfiles ? [args.testfiles] : [];
const testfiles = args.testfiles
? buidlerUtils.getTestFilePaths(args.testfiles)
: [];
try {
await env.run(TASK_TEST, {testFiles: testfiles})

@ -10,6 +10,19 @@ const { createProvider } = require("@nomiclabs/buidler/internal/core/providers/c
// Buidler Plugin Utils
// =============================
/**
* Returns a list of test files to pass to mocha.
* @param {String} files file or glob
* @return {String[]} list of files to pass to mocha
*/
function getTestFilePaths(files){
const target = globby.sync([files])
// Buidler supports js & ts
const testregex = /.*\.(js|ts)$/;
return target.filter(f => f.match(testregex) != null);
}
/**
* Normalizes buidler paths / logging for use by the plugin utilities and
* attaches them to the config
@ -104,6 +117,7 @@ module.exports = {
normalizeConfig: normalizeConfig,
finish: finish,
tempCacheDir: tempCacheDir,
setupNetwork: setupNetwork
setupNetwork: setupNetwork,
getTestFilePaths: getTestFilePaths
}

@ -116,6 +116,37 @@ describe('Buidler Plugin: command line options', function() {
verify.lineCoverage(expected);
});
it('--file test/<glob*>', async function() {
const taskArgs = {
testfiles: path.join(
buidlerConfig.paths.root,
'test/**/globby*'
)
};
mock.installFullProject('test-files');
mock.buidlerSetupEnv(this);
await this.env.run("coverage", taskArgs);
const expected = [
{
file: mock.pathToContract(buidlerConfig, 'ContractA.sol'),
pct: 0,
},
{
file: mock.pathToContract(buidlerConfig, 'ContractB.sol'),
pct: 100,
},
{
file: mock.pathToContract(buidlerConfig, 'ContractC.sol'),
pct: 100,
},
];
verify.lineCoverage(expected);
});
it('--config ../.solcover.js', async function() {
// Write solcoverjs to parent dir of sc_temp (where the test project is installed)
fs.writeFileSync(

Loading…
Cancel
Save