Skip to content

Commit f7603ac

Browse files
authored
Use recursive-readdir to resolve test files (#451)
1 parent 40c7ce3 commit f7603ac

File tree

15 files changed

+179
-14
lines changed

15 files changed

+179
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
"istanbul": "^0.4.5",
3636
"jsonschema": "^1.2.4",
3737
"lodash": "^4.17.15",
38-
"node-dir": "^0.1.17",
3938
"node-emoji": "^1.10.0",
4039
"pify": "^4.0.1",
40+
"recursive-readdir": "^2.2.2",
4141
"shelljs": "^0.8.3",
4242
"solidity-parser-antlr": "0.4.7",
4343
"web3": "1.2.1",

plugins/resources/truffle.utils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const PluginUI = require('./truffle.ui');
2-
32
const globalModules = require('global-modules');
43
const TruffleProvider = require('@truffle/provider');
5-
const dir = require('node-dir');
4+
const recursive = require('recursive-readdir');
65
const globby = require('globby');
76
const path = require('path');
87

@@ -15,15 +14,15 @@ const path = require('path');
1514
* @param {Object} config truffleConfig
1615
* @return {String[]} list of files to pass to mocha
1716
*/
18-
function getTestFilePaths(config){
17+
async function getTestFilePaths(config){
1918
let target;
2019
let ui = new PluginUI(config.logger.log);
2120

2221

2322
// Handle --file <path|glob> cli option (subset of tests)
2423
(typeof config.file === 'string')
2524
? target = globby.sync([config.file])
26-
: target = dir.files(config.testDir, { sync: true }) || [];
25+
: target = await recursive(config.testDir);
2726

2827
// Filter native solidity tests and warn that they're skipped
2928
const solregex = /.*\.(sol)$/;

plugins/truffle.plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async function plugin(config){
9696
);
9797

9898
config.all = true;
99-
config.test_files = truffleUtils.getTestFilePaths(config);
99+
config.test_files = await truffleUtils.getTestFilePaths(config);
100100
config.compilers.solc.settings.optimizer.enabled = false;
101101

102102
// Compile Instrumented Contracts
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
"silent": false,
3+
"istanbulReporter": [ "json-summary", "text"]
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { loadPluginFile } = require("@nomiclabs/buidler/plugins-testing");
2+
loadPluginFile(__dirname + "/../plugins/buidler.plugin");
3+
usePlugin("@nomiclabs/buidler-truffle5");
4+
5+
module.exports={
6+
defaultNetwork: "buidlerevm",
7+
logger: process.env.SILENT ? { log: () => {} } : console,
8+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.5.0;
2+
3+
4+
contract ContractA {
5+
uint x;
6+
constructor() public {
7+
}
8+
9+
function sendFn() public {
10+
x = 5;
11+
}
12+
13+
function callFn() public pure returns (uint){
14+
uint y = 5;
15+
return y;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.5.0;
2+
3+
4+
contract ContractB {
5+
uint x;
6+
constructor() public {
7+
}
8+
9+
function sendFn() public {
10+
x = 5;
11+
}
12+
13+
function callFn() public pure returns (uint){
14+
uint y = 5;
15+
return y;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.5.0;
2+
3+
4+
contract ContractC {
5+
uint x;
6+
constructor() public {
7+
}
8+
9+
function sendFn() public {
10+
x = 5;
11+
}
12+
13+
function callFn() public pure returns (uint){
14+
uint y = 5;
15+
return y;
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pragma solidity >=0.4.21 <0.6.0;
2+
3+
contract Migrations {
4+
address public owner;
5+
uint public last_completed_migration;
6+
7+
constructor() public {
8+
owner = msg.sender;
9+
}
10+
11+
modifier restricted() {
12+
if (msg.sender == owner) _;
13+
}
14+
15+
function setCompleted(uint completed) public restricted {
16+
last_completed_migration = completed;
17+
}
18+
19+
function upgrade(address new_address) public restricted {
20+
Migrations upgraded = Migrations(new_address);
21+
upgraded.setCompleted(last_completed_migration);
22+
}
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const ContractA = artifacts.require("ContractA");
2+
3+
contract("contracta", function(accounts) {
4+
let instance;
5+
6+
before(async () => instance = await ContractA.new())
7+
8+
it('sends [ @skipForCoverage ]', async function(){
9+
await instance.sendFn();
10+
});
11+
12+
it('calls [ @skipForCoverage ]', async function(){
13+
await instance.callFn();
14+
})
15+
});

0 commit comments

Comments
 (0)