Skip to content

Commit daf4b02

Browse files
authored
Expand testfiles arg globs (sc-forks#523)
1 parent 5ad384d commit daf4b02

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

plugins/buidler.plugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ function plugin() {
119119
// ======
120120
// Tests
121121
// ======
122-
const testfiles = args.testfiles ? [args.testfiles] : [];
122+
const testfiles = args.testfiles
123+
? buidlerUtils.getTestFilePaths(args.testfiles)
124+
: [];
123125

124126
try {
125127
await env.run(TASK_TEST, {testFiles: testfiles})

plugins/resources/buidler.utils.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ const { createProvider } = require("@nomiclabs/buidler/internal/core/providers/c
1010
// Buidler Plugin Utils
1111
// =============================
1212

13+
/**
14+
* Returns a list of test files to pass to mocha.
15+
* @param {String} files file or glob
16+
* @return {String[]} list of files to pass to mocha
17+
*/
18+
function getTestFilePaths(files){
19+
const target = globby.sync([files])
20+
21+
// Buidler supports js & ts
22+
const testregex = /.*\.(js|ts)$/;
23+
return target.filter(f => f.match(testregex) != null);
24+
}
25+
1326
/**
1427
* Normalizes buidler paths / logging for use by the plugin utilities and
1528
* attaches them to the config
@@ -104,6 +117,7 @@ module.exports = {
104117
normalizeConfig: normalizeConfig,
105118
finish: finish,
106119
tempCacheDir: tempCacheDir,
107-
setupNetwork: setupNetwork
120+
setupNetwork: setupNetwork,
121+
getTestFilePaths: getTestFilePaths
108122
}
109123

test/units/buidler/flags.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,37 @@ describe('Buidler Plugin: command line options', function() {
116116
verify.lineCoverage(expected);
117117
});
118118

119+
it('--file test/<glob*>', async function() {
120+
const taskArgs = {
121+
testfiles: path.join(
122+
buidlerConfig.paths.root,
123+
'test/**/globby*'
124+
)
125+
};
126+
127+
mock.installFullProject('test-files');
128+
mock.buidlerSetupEnv(this);
129+
130+
await this.env.run("coverage", taskArgs);
131+
132+
const expected = [
133+
{
134+
file: mock.pathToContract(buidlerConfig, 'ContractA.sol'),
135+
pct: 0,
136+
},
137+
{
138+
file: mock.pathToContract(buidlerConfig, 'ContractB.sol'),
139+
pct: 100,
140+
},
141+
{
142+
file: mock.pathToContract(buidlerConfig, 'ContractC.sol'),
143+
pct: 100,
144+
},
145+
];
146+
147+
verify.lineCoverage(expected);
148+
});
149+
119150
it('--config ../.solcover.js', async function() {
120151
// Write solcoverjs to parent dir of sc_temp (where the test project is installed)
121152
fs.writeFileSync(

0 commit comments

Comments
 (0)