Skip to content

Commit 3f59e8a

Browse files
authored
Add --file command option (for js test subsets) (#387)
1 parent d53a44f commit 3f59e8a

File tree

17 files changed

+442
-7
lines changed

17 files changed

+442
-7
lines changed

dist/truffle.plugin.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const dir = require('node-dir');
3333
const Web3 = require('web3');
3434
const util = require('util');
3535
const ganache = require('ganache-core-sc');
36+
const globby = require('globby');
3637

3738
async function plugin(truffleConfig){
3839
let app;
@@ -116,16 +117,21 @@ async function plugin(truffleConfig){
116117
// Finish
117118
await app.cleanUp();
118119

119-
if (error !== undefined) throw new Error(error)
120+
if (error !== undefined) throw error;
120121
if (failures > 0) throw new Error(`${failures} test(s) failed under coverage.`)
121122
}
122123

123124
// -------------------------------------- Helpers --------------------------------------------------
124125

125126
function tests(truffle){
127+
let target;
128+
129+
(typeof truffle.file === 'string')
130+
? target = globby.sync([truffle.file])
131+
: target = dir.files(truffle.test_directory, { sync: true }) || [];
132+
126133
const regex = /.*\.(js|ts|es|es6|jsx|sol)$/;
127-
const files = dir.files(truffle.test_directory, { sync: true }) || [];
128-
return files.filter(f => f.match(regex) != null);
134+
return target.filter(f => f.match(regex) != null);
129135
}
130136

131137

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"death": "^1.1.0",
2525
"ganache-core-sc": "2.7.0-sc.0",
26+
"globby": "^10.0.1",
2627
"istanbul": "^0.4.5",
2728
"node-dir": "^0.1.17",
2829
"req-cwd": "^1.0.1",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
silent: process.env.SILENT ? true : false,
3+
}
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Migrations = artifacts.require("Migrations");
2+
3+
module.exports = function(deployer) {
4+
deployer.deploy(Migrations);
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const ContractA = artifacts.require("ContractA");
2+
3+
module.exports = function(deployer) {
4+
deployer.deploy(ContractA);
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const ContractB = artifacts.require("ContractB");
2+
3+
module.exports = function(deployer) {
4+
deployer.deploy(ContractB);
5+
};

0 commit comments

Comments
 (0)