-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Avoid compilation when doing tests #469
Comments
I see there's the
|
I have the same problem:
|
Not the solution for you, but maybe the following command can be helpful: $ truffle test test/TestScrooge.sol Only TestScrooge.sol and its imported contracts will be compiled by Truffle, and only the tests in TestScrooge.sol will be executed. |
i resolved this for my case: apparently, the problem was due to outdated |
You could also try running |
Had the same problem, fixed by compiling in advance for the same network that is used for the tests: first: |
Running Everytime I ran I'm expecting only the contracts related in my test will get compiled and deployed. Not everything. Update I found a workaround for this. I create an empty folder in my Truffle project called Next, I ran the test with
|
@gnidan any fix for this issue? beyond the workaround? for version |
There should be an option to disable compiling also. I needed to debug a flaky test situation so I wanted to run a test a hundred times to be sure. But compiling a hundred times is totally unnecessary and a waste of time. |
I have exactly same problem. Would be nice if one can avoid compilation every time test is executed. |
We will look into this. Thanks! |
Adding to this, with v4 I was able to work around this with these steps: truffle compile --network test --all With v5 if you compile first as above, the test runs/hangs indefinitely with no output. I have to wipe the build folder to get back into a working state and then have truffle test do the compilation every time. |
Hmm, so I don't believe this is a problem any more on the latest truffle ( If anyone has a repo they could share to reproduce, I'll get right to debugging. 😎 |
I also have this problem on truffle On line 42, it finds all contracts and creates an empty array using the path as a key. On line 83, it should look at the artifacts json files and pushes the json in the empty array created before, using So, for the rest of the function, truffle was believing that some contracts didn't have artifacts json files, and the result of that is the recompilation of these contracts. I don't know why they were different since it seems to work for some people and they were only different for some contracts. I'm on Windows, but the same thing happened inside a Docker container (node:8 image). Maybe some path normalization can fix this issue? |
Thanks for that info @rogerioyuuki , looking into this. Hopefully there's a quick fix. |
@rogerioyuuki , I'm on macOS and when using Can you verify what the behavior is on your end when doing the above? |
@CruzMolina I think my problem might be Windows related. Instead of running a single script similar of that updated function, I added a few What I found is similar to what I described, with one further addition. I also found another type of path mismatch, but instead of absolute-relative mismatch, there is a mix of paths with inverted slash and forward slash and it causes the same problem. It happens even on files that I didn't create (from openzeppelin dependency, installed via npm). I don't understand why the slashes are getting mixed up. My guess is that contracts that are found via
Reproduction On a new project ( created with pragma solidity >=0.4.22 <0.6.0;
contract Mortal {
/* Define variable owner of the type address */
address owner;
/* This constructor is executed at initialization and sets the owner of the contract */
constructor() public { owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() public { if (msg.sender == owner) selfdestruct(msg.sender); }
}
contract Greeter is Mortal {
/* Define variable greeting of the type string */
string greeting;
/* This runs when the contract is executed */
constructor(string memory _greeting) public {
greeting = _greeting;
}
/* Main function */
function greet() public view returns (string memory) {
return greeting;
}
} contracts/Test.sol pragma solidity >=0.4.22 <0.6.0;
import "./HelloWorld.sol";
contract Test is Mortal {
function greet() public view returns (uint) {
return 1;
}
} When you first run
And when running
And looking at the artifacts json files, both contracts Greeter and Mortal have the I guessed that it had to do with imports because you can change this project to have the absolute and relative path mismatch I mentioned earlier. Change the import to
updated function:
Obs: I'm on
PS: To add more context why this matters, it's not only an optimization issue. I was trying to generate coverage reports to my tests, but some tools rely on intermediate steps between the compilation and the tests that gets overridden if truffle recompiles during |
Hey @rogerioyuuki , thanks again for looking into this. Can you go into this section of the code locally https://github.com/trufflesuite/truffle/blob/develop/packages/truffle-compile/index.js#L58-L79 and replace it with:
Hoping this might help. Unfortunately I don't have access to Windows to debug this locally. |
An alternative suspect is in Here https://github.com/trufflesuite/truffle/blob/develop/packages/truffle-resolver/fs.js#L13-L15 |
Still an issue with this setup (using windows): Truffle v5.0.20 (core: 5.0.20) Seems to be possibly unrelated to tests as I get the same recompile if I just run "truffle compile" one after the other after wiping the build folder. |
Still an significant nice to have in big projects where there is a lot of source code to compile. If I run The motivation is that often I have my Solidity source but don't actually alter it that at all, just the javascript test files, many times, as I re-run the tests. |
Just an update - still happens on |
Because we are working around another issue we are redoing truffle test once per test file. Not having this feature means that we recompile the contracts for each test file, which almost doubles test time. |
Truffle no longer compiles your contracts if they are up-to-date with your built artifacts during testing. It is mandatory, however, that Truffle compile any Solidity tests that you have as it does not store those as artifact files. If you want to ensure that none of your non-test artifacts are compiled you can also use the |
This is absolutely still happening in Truffle 5.1.40... @eggplantzzz Which version is this supposed to be fixed? |
I have All Issues described by @rogerioyuuki in Truffle v5.1.49
|
@eggplantzzz please reopen this issue |
I am writing tests (leaving the contract code intact) but truffle will recompile every time I run
truffle test
. Ideallytruffle test
would be smart about recompiling only files that have changed. As a quick fix, a flag to skip compilation would do for me 👍The text was updated successfully, but these errors were encountered: