diff --git a/bin/exec.js b/bin/exec.js deleted file mode 100755 index 8c0dcfd..0000000 --- a/bin/exec.js +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env node -const App = require('./../lib/app.js'); -const reqCwd = require('req-cwd'); -const death = require('death'); - -const log = console.log; - -const config = reqCwd.silent('./.solcover.js') || {}; -const app = new App(config); - -death((signal, err) => app.cleanUp(err)); - -app.generateCoverageEnvironment(); -app.instrumentTarget(); -app.launchTestrpc() - .then(() => { - app.runTestCommand(); - app.generateReport(); - }) - .catch(err => log(err)); - - - diff --git a/dist/buidler.plugin.js b/dist/buidler.plugin.js new file mode 100644 index 0000000..e69de29 diff --git a/dist/truffle.plugin.js b/dist/truffle.plugin.js new file mode 100644 index 0000000..fdb36fe --- /dev/null +++ b/dist/truffle.plugin.js @@ -0,0 +1,88 @@ +/* + TruffleConfig Paths + =========================== + build_directory /users/myPath/to/someProject/build + contracts_directory. /users/myPath/to/someProject/contracts + working_directory /users/myPath/to/someProject + contracts_build_directory /users/myPath/to/someProject/build/contracts + + Compilation options override + ---------------------------- + build_directory /users/myPath/to/someProject/.coverageArtifacts + contracts_directory /users/myPath/to/someProject/.coverageContracts + + Test options override + --------------------- + contracts_directory, /users/myPath/to/someProject/.coverageContracts + contracts_build_directory, /users/myPath/to/someProject/.coverageArtifact/contracts + provider ganache.provider (w/ vm resolved) + logger add filter for unused variables... + + Truffle Lib API + =============== + load: const truffle = require("truffle") (or require("sc-truffle")) + compilation: await truffle.contracts.compile(config) + test: await truffle.test.run(config) +*/ + +const SolidityCoverage = require('./../lib/app.js'); + +module.exports = async (config) => + let truffle; + + try { + truffle = loadTruffleLibrary(); + + const coverageConfigPath = coveragePaths.config(config) + const coverageConfig = req.silent(coverageConfigPath) || {}; + + app.contractsDir = coveragePaths.contracts(config, coverageConfig); + + const app = new SolidityCoverage(coverageConfig); + app.generateEnvironment(); + app.instrument(config.contracts_directory); + + // Compile instrumented sources / optimization off + config.contracts_directory = app.contractsDir; + config.build_directory = coveragePaths.artifacts.root(config, coverageConfig); + config.contracts_build_directory = coveragePaths.artifacts.contracts(config, coverageConfig); + config.compilers.solc.settings.optimization.enabled = false; + await truffle.contracts.compile(config); + + // Test using compiled, instrumented sources + config.provider = await app.getCoverageProvider(); + try { + await truffle.test.run(config) + } catch (err) { + app.testsErrored = true; + } + + app.generateCoverage(); + + } catch(err){ + return app.cleanUp(err); + } + + return app.cleanUp(); +} + +// -------------------------------------- Helpers -------------------------------------------------- +function loadTruffleLibrary(){ + + try { return require("truffle") } catch(err) {}; + try { return require("sc-truffle")} catch(err) {}; + + throw new Error(utils.errors.NO_TRUFFLE_LIB) +} + +const coveragePaths = { + contracts: (t, c) => path.join(path.dirname(t.contracts_directory), c.contractsDirName)), + config: (t) => path.join(t.working_directory, '.solcover.js'), + + artifacts: { + root: (t, c) => path.join(path.dirname(t.build_directory), c.artifactsDirName), + contracts: (c, t) => path.join(c.build_directory, path.basename(t.contracts_build_directory)) + } +} + + diff --git a/truffle-plugin.json b/truffle-plugin.json new file mode 100644 index 0000000..2e545e1 --- /dev/null +++ b/truffle-plugin.json @@ -0,0 +1,5 @@ +{ + "commands": { + "coverage": "dist/truffle.plugin.js" + } +}