Skip to content

Commit 1e45f9f

Browse files
committed
Progress on fixing sol cov
1 parent aac1ff2 commit 1e45f9f

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

bin/exec.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ const app = new App(config);
1010

1111
death((signal, err) => app.cleanUp(err));
1212

13-
app.generateCoverageEnvironment();
14-
app.instrumentTarget();
15-
app.launchTestrpc()
16-
.then(() => {
17-
app.runTestCommand();
18-
app.generateReport();
19-
})
20-
.catch(err => log(err));
13+
(async () => {
14+
15+
try {
16+
app.generateCoverageEnvironment();
17+
app.instrumentTarget();
18+
await app.launchTestrpc();
19+
await app.runTestCommand();
20+
await app.generateReport();
21+
}
22+
catch (err) {
23+
log(err);
24+
}
25+
26+
})();
2127

2228

2329

lib/app.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,18 @@ class App {
170170
* Changes here should be also be added to the before() block of test/run.js).
171171
* @return {Promise} Resolves when testrpc prints 'Listening' to std out / norpc is true.
172172
*/
173-
launchTestrpc() {
174-
return new Promise((resolve, reject) => {
175-
if (!this.norpc) {
176-
const defaultRpcOptions = `--accounts ${this.accounts} --port ${this.port}`;
177-
const options = (this.testrpcOptions || defaultRpcOptions) + ` --gasLimit ${gasLimitHex}`;
178-
const command = './node_modules/ganache-cli/build/cli.node.js ';
179-
180-
// Launch
181-
const execOpts = {maxBuffer: 1024 * 1024 * 10};
182-
this.testrpcProcess = childprocess.exec(command + options, execOpts, (err, stdout, stderr) => {
183-
if (err) {
184-
if (stdout) this.log(`testRpc stdout:\n${stdout}`);
185-
if (stderr) this.log(`testRpc stderr:\n${stderr}`);
186-
this.cleanUp('testRpc errored after launching as a childprocess.');
173+
async launchTestrpc() {
174+
if (this.norpc) {
175+
return Promise.resolve();
187176
}
188-
});
177+
let truffleConfig = reqCwd.silent(`${this.workingDir}/truffle.js`);
178+
let networkOpts = truffleConfig.networks.coverage;
189179

190-
// Resolve when testrpc logs that it's listening.
191-
this.testrpcProcess.stdout.on('data', data => {
192-
if (data.includes('Listening')) {
193-
this.log(`Launched testrpc on port ${this.port}`);
194-
return resolve();
195-
}
196-
});
197-
} else {
198-
return resolve();
199-
}
200-
});
180+
let ganache = require("ganache-cli");
181+
let server = ganache.server(networkOpts);
182+
183+
let { promisify } = require('util');
184+
await promisify(server.listen)(networkOpts.port);
201185
}
202186

203187
/**
@@ -206,7 +190,26 @@ class App {
206190
* as its own statement for command line options to work, apparently.
207191
* Also reads the 'allFiredEvents' log.
208192
*/
209-
runTestCommand() {
193+
async runTestCommand() {
194+
195+
let testCommand = require("truffle-core/lib/commands/test");
196+
let options = { logger: console, network: 'coverage', _: [] };
197+
198+
shell.cd(this.coverageDir);
199+
200+
await new Promise((resolve, reject) => {
201+
testCommand.run(options, (err, res) => {
202+
if (err) {
203+
reject(err);
204+
}
205+
resolve(res);
206+
});
207+
});
208+
209+
shell.cd('./..');
210+
211+
return;
212+
210213
try {
211214
const defaultCommand = `truffle test ${this.network} ${this.silence}`;
212215
const command = this.testCommand || defaultCommand;

0 commit comments

Comments
 (0)