Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ $ npm install --save-dev solidity-coverage@beta
### Usage notes:
+ Coverage runs tests a little more slowly.
+ Coverage distorts gas consumption. Tests that check exact gas consumption should be skipped.
+ Coverage launches its own in-process ganache server.
+ You can set [ganache options](https://github.com/trufflesuite/ganache-core#options) using the `providerOptions` key in your `.solcover.js` config.
+ Coverage launches its own in-process ganache server.
+ You can set [ganache options](https://github.com/trufflesuite/ganache-core#options) using the `providerOptions` key in your `.solcover.js` config.

### Truffle V5

Expand All @@ -45,6 +45,7 @@ truffle run coverage [options]
|--------------|------------------------------------|--------------------------------|
| file | `--file="test/registry/*.js"` | Filename or glob describing a subset of JS tests to run. (Globs must be enclosed by quotes.)|
| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
| network | `--network development` | Use network settings defined in the Truffle config |
| version | | Version info |
| help | | Usage notes |

Expand All @@ -71,6 +72,7 @@ module.exports = {
| mocha | *Object* | `{ }` | [Mocha options](https://mochajs.org/api/mocha) to merge into existing mocha config. `grep` and `invert` are useful for skipping certain tests under coverage using tags in the test descriptions.|
| onServerReady | *Function* | | Hook run *after* server is launched, *before* the tests execute. Useful if you need to use the Oraclize bridge or have setup scripts which rely on the server's availability |
| onTestsComplete | *Function* | | Hook run *after* the tests complete, *before* Istanbul reports are generated. |
| onCompileComplete | *Function* | | Hook run *after* compilation completes, *before* tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. |
| onIstanbulComplete | *Function* | | Hook run *after* the Istanbul reports are generated, *before* the ganache server is shut down. Useful if you need to clean resources up. |


Expand Down
7 changes: 5 additions & 2 deletions dist/plugin-assets/truffle.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class PluginUI extends UI {


'versions': `${ct} ${c.bold('truffle')}: v${args[0]}\n` +
`${ct} ${c.bold('ganache-core')}: ${args[0]}\n` +
`${ct} ${c.bold('solidity-coverage')}: v${args[0]}`,
`${ct} ${c.bold('ganache-core')}: ${args[1]}\n` +
`${ct} ${c.bold('solidity-coverage')}: v${args[2]}`,

'network': `\n${c.bold('Network Info')}` +
`\n${c.bold('============')}\n` +
Expand All @@ -78,6 +78,7 @@ class PluginUI extends UI {
*/
generate(kind, args=[]){
const c = this.chalk;
const x = ":x:";

const kinds = {

Expand All @@ -91,6 +92,8 @@ class PluginUI extends UI {
`${c.red('This can happen if it has a syntax error or ')}` +
`${c.red('the path you specified for it is wrong.')}`,

'tests-fail': `${x} ${c.bold(args[0])} ${c.red('test(s) failed under coverage.')}`,

'no-network': `${c.red('Network: ')} ${args[0]} ` +
`${c.red(' is not defined in your truffle-config networks. ')}`,

Expand Down
6 changes: 4 additions & 2 deletions dist/truffle.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ async function plugin(config){

// Compile Instrumented Contracts
await truffle.contracts.compile(config);
await api.onCompileComplete(config);

// Run tests
try {
failures = await truffle.test.run(config)
} catch (e) {
error = e.stack;
}

await api.onTestsComplete(config);

// Run Istanbul
await api.report();
await api.onIstanbulComplete(config);

Expand All @@ -113,7 +115,7 @@ async function plugin(config){
await utils.finish(config, api);

if (error !== undefined) throw error;
if (failures > 0) throw new Error(`${failures} test(s) failed under coverage.`)
if (failures > 0) throw new Error(ui.generate('tests-fail', [failures]));
}

module.exports = plugin;
1 change: 1 addition & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class API {
this.defaultHook = () => {};
this.onServerReady = config.onServerReady || this.defaultHook;
this.onTestsComplete = config.onTestsComplete || this.defaultHook;
this.onCompileComplete = config.onCompileComplete || this.defaultHook;
this.onIstanbulComplete = config.onIstanbulComplete || this.defaultHook;

this.server = null;
Expand Down
1 change: 1 addition & 0 deletions test/integration/projects/test-files/.solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
istanbulReporter: ['json-summary', 'text'],
onServerReady: fn.bind(null, 'running onServerReady'),
onTestsComplete: fn.bind(null, 'running onTestsComplete'),
onCompileComplete: fn.bind(null, 'running onCompileComplete'),
onIstanbulComplete: fn.bind(null, 'running onIstanbulComplete')
}
1 change: 1 addition & 0 deletions test/units/truffle/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ describe('Truffle Plugin: standard use cases', function() {
assert(
mock.loggerOutput.val.includes('running onServerReady') &&
mock.loggerOutput.val.includes('running onTestsComplete') &&
mock.loggerOutput.val.includes('running onCompileComplete') &&
mock.loggerOutput.val.includes('running onIstanbulComplete'),

`Should run "on" hooks : ${mock.loggerOutput.val}`
Expand Down