Skip to content

Commit 362183f

Browse files
authored
Add --version, option.client, and update README (#393)
* Initial README simplification * Add --version cli flag
2 parents 0ef36c9 + eeff9a8 commit 362183f

File tree

5 files changed

+52
-68
lines changed

5 files changed

+52
-68
lines changed

README.md

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,96 +19,66 @@ find discrepancies between the coverage report and your suite's behavior, please
1919
```
2020
$ npm install --save-dev solidity-coverage
2121
```
22-
23-
### Run
24-
Set a `coverage` network in truffle-config.js (see [Network Configuration](#network-configuration)) and then run:
25-
```
26-
$ npx solidity-coverage
27-
```
28-
2922
### Usage notes:
30-
+ For pragma solidity >=0.4.22 <0.6.0 / Petersburg / Truffle v4 and v5
31-
+ Tests run more slowly while coverage is being generated.
32-
+ Your contracts will be double-compiled and a (long) delay between compilation and
33-
the beginning of test execution is possible if your contracts are large.
34-
+ Truffle should be globallly installed in your environment.. If you prefer running truffle as
35-
a local dependency, please see [this section](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency) of the FAQ.
36-
+ If your suite uses native Solidity testing or accesses contracts via mocks stored in `tests/` (a la Zeppelin), coverage will trigger test errors because it can't control the way truffle compiles that folder. Mocks should be relocated to the root `contracts` directory. More on why this is necessary at issue [146](https://github.com/sc-forks/solidity-coverage/issues/146)
37-
38-
### Network Configuration
39-
40-
By default, this tool connects to a coverage-enabled fork of ganache-cli
41-
called **testrpc-sc** on port 8555.
42-
+ it's a dependency - there's nothing extra to download.
43-
+ the solidity-coverage command launches it automatically in the background. (See [this section of the FAQ](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-testrpc-sc-on-its-own) if you need to launch it separately yourself)
23+
+ For pragma solidity >=0.4.22 <0.6.0 / Petersburg
24+
+ Coverage runs tests a little more slowly.
25+
+ Coverage distorts gas consumption.
26+
+ Coverage launches its own in-process ganache instance. You can
27+
set [ganache options](https://github.com/trufflesuite/ganache-core#options) via
28+
the `providerOptions` key in your `.solcover.js` config file.
4429

45-
In `truffle-config.js`, add a coverage network following the example below.
30+
### Truffle V5
4631

47-
**Example**
32+
Add "solidity-coverage" to your plugins array in `truffle-config.js`
4833
```javascript
4934
module.exports = {
50-
networks: {
51-
development: {
52-
host: "localhost",
53-
port: 8545,
54-
network_id: "*"
55-
},
56-
coverage: {
57-
host: "localhost",
58-
network_id: "*",
59-
port: 8555, // <-- If you change this, also set the port option in .solcover.js.
60-
gas: 0xfffffffffff, // <-- Use this high gas value
61-
gasPrice: 0x01 // <-- Use this low gas price
62-
},
63-
...etc...
64-
}
65-
};
35+
networks: {...},
36+
plugins: ["solidity-coverage"]
37+
}
38+
```
39+
Run
40+
```
41+
truffle run coverage [options]
6642
```
67-
### Options
43+
44+
45+
### Command Options
46+
| Option | Example | Description |
47+
|--------------|--------------------------------|-------------|
48+
| --file | --file="test/registry/*.js" | Filename or glob describing a subset of JS tests to run. (Globs must be enclosed by quotes.)|
49+
| --solcoverjs | --solcoverjs ./../.solcover.js | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
50+
| --version | | Version info |
51+
| --help | | Usage notes |
52+
|<img width=250/>|<img width=500/> |<img width=100/>|
53+
54+
### Config Options
6855

6956
Additional options can be specified in a `.solcover.js` config file located in
7057
the root directory of your project.
7158

7259
**Example:**
7360
```javascript
7461
module.exports = {
75-
port: 6545,
76-
testrpcOptions: '-p 6545 -u 0x54fd80d6ae7584d8e9a19fe1df43f04e5282cc43',
77-
testCommand: 'mocha --timeout 5000',
78-
norpc: true,
79-
dir: './secretDirectory',
80-
copyPackages: ['openzeppelin-solidity'],
81-
skipFiles: ['Routers/EtherRouter.sol']
62+
skipFiles: ['Routers/EtherRouter.sol']
8263
};
8364
```
8465

8566

8667
| Option | Type | Default | Description |
8768
| ------ | ---- | ------- | ----------- |
88-
| accounts | *Number* | 35 | Number of accounts to launch testrpc with. |
89-
| port | *Number* | 8555 | Port to run testrpc on / have truffle connect to |
90-
| norpc | *Boolean* | false | Prevent solidity-coverage from launching its own testrpc. Useful if you are managing a complex test suite with a [shell script](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/ed872ca0a11c4926f8bb91dd103bea1378a3384c/scripts/coverage.sh) |
91-
| testCommand | *String* | `truffle test` | Run an arbitrary test command. ex: `mocha --timeout 5000`. NB: Also set the `port` option to whatever your tests require (probably 8545). |
92-
| testrpcOptions | *String* | `--port 8555` | options to append to a command line invocation of testrpc. NB: Using this overwrites the defaults so always specify a port in this string *and* in the `port` option |
93-
| copyNodeModules | *Boolean* | false | :warning: **DEPRECATED** use `copyPackages` instead :warning: Copies `node_modules` into the coverage environment. May significantly increase the time for coverage to complete if enabled. Useful if your contracts import solidity files from an npm installed package (and your node_modules is small). |
94-
| copyPackages | *Array* | `[]` | Copies specific `node_modules` packages into the coverage environment. May significantly reduce the time for coverage to complete compared to `copyNodeModules`. Useful if your contracts import solidity files from an npm installed package. |
69+
| client | *Object* | require("truffle").ganache | Useful if you need a specific ganache version. (usage: `client: require("ganache-core")`)|
70+
| providerOptions | *Object* | {} | ganache-core options (ex: `network_id: 55`). Complete list of options [here](https://github.com/trufflesuite/ganache-core#options). |
9571
| skipFiles | *Array* | `['Migrations.sol']` | Array of contracts or folders (with paths expressed relative to the `contracts` directory) that should be skipped when doing instrumentation. `Migrations.sol` is skipped by default, and does not need to be added to this configuration option if it is used. |
96-
| deepSkip | boolean | false | Use this if instrumentation hangs on large, skipped files (like Oraclize). It's faster. |
97-
| dir | *String* | `.` | Solidity-coverage copies all the assets in your root directory (except `node_modules`) to a special folder where it instruments the contracts and executes the tests. `dir` allows you to define a relative path from the root directory to those assets. Useful if your contracts & tests are within their own folder as part of a larger project.|
98-
| buildDirPath | *String* | `/build/contracts` | Build directory path for compiled smart contracts |
9972
| istanbulReporter | *Array* | ['html', 'lcov', 'text'] | Coverage reporters for Istanbul. Optional reporter replaces the default reporters. |
10073

10174
### FAQ
10275

103-
Solutions to common problems people run into:
76+
Common problems & questions:
10477

10578
+ [Running out of gas](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-gas)
10679
+ [Running out of memory (locally and in CI)](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-memory-locally-and-in-ci)
10780
+ [Running out of time (in mocha)](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-time-in-mocha)
108-
+ [Running on windows](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-on-windows)
109-
+ [Running testrpc-sc on its own](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-testrpc-sc-on-its-own)
110-
+ [Running truffle as a local dependency](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-truffle-as-a-local-dependency)
111-
+ [Integrating into CI](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#continuous-integration-installing-metacoin-on-travisci-with-coveralls)
81+
+ [Running in CI](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#continuous-integration-installing-metacoin-on-travisci-with-coveralls)
11282
+ [Why are asserts and requires highlighted as branch points?](https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#why-has-my-branch-coverage-decreased-why-is-assert-being-shown-as-a-branch-point)
11383

11484

dist/truffle.plugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
const App = require('./../lib/app');
29+
const pkg = require('./../package.json');
2930
const req = require('req-cwd');
3031
const death = require('death');
3132
const path = require('path');
@@ -66,7 +67,7 @@ async function plugin(truffleConfig){
6667

6768
// Instrument and test..
6869
try {
69-
death(app.cleanUp);
70+
death(app.cleanUp); // This doesn't work...
7071

7172
// Launch in-process provider
7273
const provider = await app.provider(truffle.ganache);
@@ -77,6 +78,10 @@ async function plugin(truffleConfig){
7778

7879
app.ui.report('truffle-version', [truffle.version]);
7980
app.ui.report('ganache-version', [ganacheVersion]);
81+
app.ui.report('coverage-version',[pkg.version]);
82+
83+
// Bail early if user ran: --version
84+
if (truffleConfig.version) return;
8085

8186
// Write instrumented sources to temp folder
8287
app.instrument();

lib/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class App {
3232

3333
this.originalContractsDir = config.originalContractsDir
3434

35-
this.client = config.provider;
35+
this.client = config.client;
3636
this.providerOptions = config.providerOptions || {};
3737

3838
this.skippedFolders = [];

lib/ui.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ class UI {
2828

2929
'truffle-help': `Usage: truffle run coverage [options]\n\n` +
3030
`Options:\n` +
31-
` --file: path (or glob) to run subset of JS test files\n` +
32-
` --solcoverjs: relative path to .solcover.js (ex: ./../.solcover.js)\n`,
31+
` --file: path (or glob) to subset of JS test files. (Quote your globs)\n` +
32+
` --solcoverjs: relative path to .solcover.js (ex: ./../.solcover.js)\n` +
33+
` --version: version info\n`,
3334

34-
'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`,
35-
'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`,
35+
'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`,
36+
'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`,
37+
'coverage-version': `${ct} ${c.bold('solidity-coverage')}: v${args[0]}`,
3638

3739
'instr-start': `\n${c.bold('Instrumenting for coverage...')}` +
3840
`\n${c.bold('=============================')}\n`,

test/units/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ describe('app', function() {
183183
await plugin(truffleConfig);
184184
})
185185

186+
it('truffle run coverage --version', async function(){
187+
assertCleanInitialState();
188+
truffleConfig.version = "true";
189+
mock.install('Simple', 'simple.js', solcoverConfig);
190+
await plugin(truffleConfig);
191+
})
192+
186193
it('truffle run coverage --file test/<fileName>', async function() {
187194
assertCleanInitialState();
188195

0 commit comments

Comments
 (0)