Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locate .coverage_contracts correctly for subfolder paths #570

Merged
merged 2 commits into from
Nov 16, 2020
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
4 changes: 2 additions & 2 deletions plugins/resources/plugin.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const PluginUI = require('./truffle.ui');
const path = require('path');
const fs = require('fs-extra');
const shell = require('shelljs');
const util = require('util')

// ===
// UI
Expand Down Expand Up @@ -93,12 +92,13 @@ function toRelativePath(pathToFile, pathToParent){
* @return {Object} temp paths
*/
function getTempLocations(config){
const contractsRoot = path.parse(config.contractsDir).dir
const cwd = config.workingDir;
const contractsDirName = '.coverage_contracts';
const artifactsDirName = config.temp || '.coverage_artifacts';

return {
tempContractsDir: path.join(cwd, contractsDirName),
tempContractsDir: path.join(contractsRoot, contractsDirName),
tempArtifactsDir: path.join(cwd, artifactsDirName)
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/integration/projects/contract-subfolders/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Testing hooks
const fn = (msg, config) => config.logger.log(msg);

module.exports = {
skipFiles: ['Migrations.sol'],
silent: process.env.SILENT ? true : false,
istanbulReporter: ['json-summary', 'text'],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity ^0.5.0;

import "./../B/ContractB2.sol";

contract ContractA is ContractB {
uint x;
constructor() public {
}

function sendFn() public {
x = 5;
}

function callFn() public pure returns (uint){
uint y = 5;
return y;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.5.0;


contract ContractB {
uint x;
constructor() public {
}

function sendFnB() public {
x = 5;
}

function callFnB() public pure returns (uint){
uint y = 5;
return y;
}
}
17 changes: 17 additions & 0 deletions test/integration/projects/contract-subfolders/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../plugins/nomiclabs.plugin");

module.exports={
networks: {
hardhat: {
gasPrice: 2
}
},
solidity: {
version: "0.5.15"
},
paths: {
sources: './contracts/A'
},
logger: process.env.SILENT ? { log: () => {} } : console,
};
17 changes: 17 additions & 0 deletions test/integration/projects/contract-subfolders/test/contracta2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const ContractA = artifacts.require("ContractA");

contract("contracta", function(accounts) {
let instance;

before(async () => instance = await ContractA.new())

it('sends', async function(){
await instance.sendFn();
await instance.sendFnB();
});

it('calls', async function(){
await instance.callFn();
await instance.callFnB();
})
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
networks: {},
mocha: {},
compilers: {
solc: {}
}
}
15 changes: 15 additions & 0 deletions test/units/hardhat/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,19 @@ describe('Hardhat Plugin: standard use cases', function() {
verify.lineCoverage(expected);
})

it('locates .coverage_contracts correctly when dir is subfolder', async function(){
mock.installFullProject('contract-subfolders');
mock.hardhatSetupEnv(this);

await this.env.run("coverage");

const expected = [
{
file: 'contracts/A/ContractA2.sol',
pct: 100
}
];

verify.lineCoverage(expected);
})
})
15 changes: 15 additions & 0 deletions test/units/truffle/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,21 @@ describe('Truffle Plugin: standard use cases', function() {
verify.lineCoverage(expected);
});

it('locates .coverage_contracts correctly when dir is subfolder', async function(){
solcoverConfig = {
silent: process.env.SILENT ? true : false,
istanbulReporter: ['json-summary', 'text']
};

truffleConfig.contracts_directory = path.join(
process.cwd(),
mock.pathToTemp("contracts/A")
);

mock.installFullProject('contract-subfolders');
await plugin(truffleConfig);
})

// This test tightly coupled to the ganache version in production deps
// "test-files" project solcoverjs includes `client: require('ganache-cli')`
it('config: client', async function(){
Expand Down