|
| 1 | +[][18] |
| 2 | + |
| 3 | +[][20] |
| 4 | +[][21] |
| 5 | +[][26] |
| 6 | + |
| 7 | +# solidity-coverage |
| 8 | + |
| 9 | +Solidity code coverage plugin for [buidler](http://getbuidler.com). |
| 10 | + |
| 11 | +## What |
| 12 | + |
| 13 | +![coverage example][22] |
| 14 | + |
| 15 | ++ For more details about how it works and potential limitations, see [the accompanying article][16]. |
| 16 | ++ `solidity-coverage` is also [JoinColony/solcover][17] |
| 17 | + |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +```bash |
| 22 | +$ npm install --save-dev solidity-coverage@beta |
| 23 | +``` |
| 24 | + |
| 25 | +And add the following to your `buidler.config.js`: |
| 26 | + |
| 27 | +```js |
| 28 | +usePlugin("solidity-coverage"); |
| 29 | +``` |
| 30 | + |
| 31 | +## Tasks |
| 32 | + |
| 33 | +This plugin implements a `coverage` task |
| 34 | + |
| 35 | +```bash |
| 36 | +npx buidler coverage [options] |
| 37 | +``` |
| 38 | + |
| 39 | +| Option <img width=200/> | Example <img width=750/>| Description <img width=1000/> | |
| 40 | +|--------------|------------------------------------|--------------------------------| |
| 41 | +| testfiles | `--testfiles test/file.js` | JS test file(s) to run.| |
| 42 | +| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) | |
| 43 | +| network | `--network development` | Use network settings defined in the Buidler config | |
| 44 | + |
| 45 | + |
| 46 | +## Configuration |
| 47 | + |
| 48 | +Options can be specified in a `.solcover.js` config file located in the root directory of your project. |
| 49 | + |
| 50 | +**Project Examples:** |
| 51 | + |
| 52 | ++ Simple: [buidler-metacoin][29] |
| 53 | ++ More complex: [MolochDao/moloch][30] |
| 54 | + |
| 55 | +**Config Example:** |
| 56 | +```javascript |
| 57 | +module.exports = { |
| 58 | + skipFiles: ['Routers/EtherRouter.sol'] |
| 59 | +}; |
| 60 | +``` |
| 61 | + |
| 62 | +| Option <img width=200/>| Type <img width=200/> | Default <img width=1300/> | Description <img width=800/> | |
| 63 | +| ------ | ---- | ------- | ----------- | |
| 64 | +| silent | *Boolean* | false | Suppress logging output | |
| 65 | +| client | *Object* | `require("ganache-core")` | Useful if you need a specific ganache version. | |
| 66 | +| providerOptions | *Object* | `{ }` | [ganache-core options][1] | |
| 67 | +| skipFiles | *Array* | `['Migrations.sol']` | Array of contracts or folders (with paths expressed relative to the `contracts` directory) that should be skipped when doing instrumentation. | |
| 68 | +| istanbulFolder | *String* | `./coverage` | Folder location for Istanbul coverage reports. | |
| 69 | +| istanbulReporter | *Array* | `['html', 'lcov', 'text', 'json']` | [Istanbul coverage reporters][2] | |
| 70 | +| mocha | *Object* | `{ }` | [Mocha options][3] to merge into existing mocha config. `grep` and `invert` are useful for skipping certain tests under coverage using tags in the test descriptions.| |
| 71 | +| onServerReady[<sup>*</sup>][14] | *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. [More...][23] | |
| 72 | +| onCompileComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* compilation completes, *before* tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. [More...][23]| |
| 73 | +| onTestsComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the tests complete, *before* Istanbul reports are generated. [More...][23]| |
| 74 | +| onIstanbulComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the Istanbul reports are generated, *before* the ganache server is shut down. Useful if you need to clean resources up. [More...][23]| |
| 75 | + |
| 76 | +[<sup>*</sup> Advanced use][14] |
| 77 | + |
| 78 | +## Usage |
| 79 | + |
| 80 | ++ Coverage runs tests a little more slowly. |
| 81 | ++ Coverage launches its own in-process ganache server. |
| 82 | ++ You can set [ganache options][1] using the `providerOptions` key in your `.solcover.js` [config][15]. |
| 83 | ++ Coverage [distorts gas consumption][13]. Tests that check exact gas consumption should be [skipped][24]. |
| 84 | ++ :warning: Contracts are compiled **without optimization**. Please report unexpected compilation faults to [issue 417][25] |
| 85 | + |
| 86 | +## Documentation |
| 87 | + |
| 88 | +More documentation, including FAQ and information about solidity-coverage's API [is available here][28]. |
| 89 | + |
| 90 | + |
| 91 | +[1]: https://github.com/trufflesuite/ganache-core#options |
| 92 | +[2]: https://istanbul.js.org/docs/advanced/alternative-reporters/ |
| 93 | +[3]: https://mochajs.org/api/mocha |
| 94 | +[4]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#running-out-of-gas |
| 95 | +[5]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#running-out-of-memory |
| 96 | +[6]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#running-out-of-time |
| 97 | +[7]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#continuous-integration |
| 98 | +[8]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#notes-on-branch-coverage |
| 99 | +[9]: https://sc-forks.github.io/metacoin/ |
| 100 | +[10]: https://coveralls.io/github/OpenZeppelin/openzeppelin-solidity?branch=master |
| 101 | +[11]: https://github.com/sc-forks/solidity-coverage/tree/beta/test/units |
| 102 | +[12]: https://github.com/sc-forks/solidity-coverage/issues |
| 103 | +[13]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/faq.md#notes-on-gas-distortion |
| 104 | +[14]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/advanced.md |
| 105 | +[15]: #config-options |
| 106 | +[16]: https://blog.colony.io/code-coverage-for-solidity-eecfa88668c2 |
| 107 | +[17]: https://github.com/JoinColony/solcover |
| 108 | +[18]: https://gitter.im/sc-forks/solidity-coverage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge |
| 109 | +[19]: https://badge.fury.io/js/solidity-coverage |
| 110 | +[20]: https://circleci.com/gh/sc-forks/solidity-coverage |
| 111 | +[21]: https://codecov.io/gh/sc-forks/solidity-coverage |
| 112 | +[22]: https://cdn-images-1.medium.com/max/800/1*uum8t-31bUaa6dTRVVhj6w.png |
| 113 | +[23]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/advanced.md#workflow-hooks |
| 114 | +[24]: https://github.com/sc-forks/solidity-coverage/blob/beta/docs/advanced.md#skipping-tests |
| 115 | +[25]: https://github.com/sc-forks/solidity-coverage/issues/417 |
| 116 | +[26]: https://buidler.dev/ |
| 117 | +[27]: https://www.trufflesuite.com/docs |
| 118 | +[28]: https://github.com/sc-forks/solidity-coverage/blob/beta/README.md |
| 119 | +[29]: https://github.com/sc-forks/buidler-e2e/tree/coverage |
| 120 | +[30]: https://github.com/sc-forks/moloch |
| 121 | + |
0 commit comments