From 54483d52ea560dc5cc645eb4c8716429758fcb93 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 9 Sep 2019 00:56:23 -0700 Subject: [PATCH] Add coverage expectations to plugin integration tests --- .../projects/import-paths/.solcover.js | 3 +- .../projects/multiple-migrations/.solcover.js | 1 + .../projects/skipping/.solcover.js | 3 +- .../projects/test-files/.solcover.js | 1 + test/units/app.js | 94 +++++++++++++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) diff --git a/test/integration/projects/import-paths/.solcover.js b/test/integration/projects/import-paths/.solcover.js index f328e37..4278185 100644 --- a/test/integration/projects/import-paths/.solcover.js +++ b/test/integration/projects/import-paths/.solcover.js @@ -1,3 +1,4 @@ module.exports = { silent: process.env.SILENT ? true : false, -}; + istanbulReporter: ['json-summary', 'text'] +} diff --git a/test/integration/projects/multiple-migrations/.solcover.js b/test/integration/projects/multiple-migrations/.solcover.js index f328e37..7a54eb3 100644 --- a/test/integration/projects/multiple-migrations/.solcover.js +++ b/test/integration/projects/multiple-migrations/.solcover.js @@ -1,3 +1,4 @@ module.exports = { silent: process.env.SILENT ? true : false, + istanbulReporter: ['json-summary', 'text'] }; diff --git a/test/integration/projects/skipping/.solcover.js b/test/integration/projects/skipping/.solcover.js index 681cd56..4be0bbd 100644 --- a/test/integration/projects/skipping/.solcover.js +++ b/test/integration/projects/skipping/.solcover.js @@ -1,4 +1,5 @@ module.exports = { silent: process.env.SILENT ? true : false, - skipFiles: ['skipped-folder'] + skipFiles: ['skipped-folder'], + istanbulReporter: ['json-summary', 'text'] } diff --git a/test/integration/projects/test-files/.solcover.js b/test/integration/projects/test-files/.solcover.js index 8eb203c..4278185 100644 --- a/test/integration/projects/test-files/.solcover.js +++ b/test/integration/projects/test-files/.solcover.js @@ -1,3 +1,4 @@ module.exports = { silent: process.env.SILENT ? true : false, + istanbulReporter: ['json-summary', 'text'] } diff --git a/test/units/app.js b/test/units/app.js index f707771..9970999 100644 --- a/test/units/app.js +++ b/test/units/app.js @@ -12,6 +12,20 @@ const opts = { compact: false, depth: 5, breakLength: 80 }; // ======= function pathExists(path) { return shell.test('-e', path); } +function pathToContract(config, file) { + return path.join('contracts', file); +} + +function assertLineCoverage(expected=[]){ + let summary = JSON.parse(fs.readFileSync('coverage/coverage-summary.json')); + expected.forEach(item => assert(summary[item.file].lines.pct === item.pct)) +} + +function assertCoverageMissing(expected=[]){ + let summary = JSON.parse(fs.readFileSync('coverage/coverage-summary.json')); + expected.forEach(item => assert(summary[item.file] === undefined)) +} + function assertCleanInitialState(){ assert(pathExists('./coverage') === false, 'should start without: coverage'); assert(pathExists('./coverage.json') === false, 'should start without: coverage.json'); @@ -88,12 +102,41 @@ describe('app', function() { assertCleanInitialState(); mock.installFullProject('multiple-migrations'); await plugin(truffleConfig); + + const expected = [ + { + file: pathToContract(truffleConfig, 'ContractA.sol'), + pct: 100 + }, + { + file: pathToContract(truffleConfig, 'ContractB.sol'), + pct: 100, + }, + { + file: pathToContract(truffleConfig, 'ContractC.sol'), + pct: 100, + }, + ]; + + assertLineCoverage(expected); }); it('project skips a folder', async function() { assertCleanInitialState(); mock.installFullProject('skipping'); await plugin(truffleConfig); + + const expected = [{ + file: pathToContract(truffleConfig, 'ContractA.sol'), + pct: 100 + }]; + + const missing = [{ + file: pathToContract(truffleConfig, 'ContractB.sol'), + }]; + + assertLineCoverage(expected); + assertCoverageMissing(missing); }); it('project with relative path solidity imports', async function() { @@ -109,6 +152,23 @@ describe('app', function() { truffleConfig.file = testPath; mock.installFullProject('test-files'); await plugin(truffleConfig); + + const expected = [ + { + file: pathToContract(truffleConfig, 'ContractA.sol'), + pct: 100 + }, + { + file: pathToContract(truffleConfig, 'ContractB.sol'), + pct: 0, + }, + { + file: pathToContract(truffleConfig, 'ContractC.sol'), + pct: 0, + }, + ]; + + assertLineCoverage(expected); }); it('truffle run coverage --file test/', async function() { @@ -118,6 +178,23 @@ describe('app', function() { truffleConfig.file = testPath; mock.installFullProject('test-files'); await plugin(truffleConfig); + + const expected = [ + { + file: pathToContract(truffleConfig, 'ContractA.sol'), + pct: 0, + }, + { + file: pathToContract(truffleConfig, 'ContractB.sol'), + pct: 100, + }, + { + file: pathToContract(truffleConfig, 'ContractC.sol'), + pct: 100, + }, + ]; + + assertLineCoverage(expected); }); it('truffle run coverage --file test/gl{o,b}*.js', async function() { @@ -127,6 +204,23 @@ describe('app', function() { truffleConfig.file = testPath; mock.installFullProject('test-files'); await plugin(truffleConfig); + + const expected = [ + { + file: pathToContract(truffleConfig, 'ContractA.sol'), + pct: 0, + }, + { + file: pathToContract(truffleConfig, 'ContractB.sol'), + pct: 100, + }, + { + file: pathToContract(truffleConfig, 'ContractC.sol'), + pct: 100, + }, + ]; + + assertLineCoverage(expected); }); it('contract only uses ".call"', async function(){