LimeChain / matchstick

🔥 Unit testing framework for Subgraph development on The Graph protocol. ⚙️
MIT License
210 stars 18 forks source link

Skip compile for unchanged suites #238

Closed dimitrovmaksim closed 2 years ago

dimitrovmaksim commented 2 years ago

Issues: closes https://github.com/LimeChain/matchstick/issues/223

What it does:

  1. Adds a check if a wasm binary already exists for each suite.
  2. Adds a check (is_source_modified function) if any of the .test.ts files in each suite has been changed since the last time the wasm binary was compiled. The function first checks if the whole suite folder has been modified, e.g. files have been removed/added, if not - loops through each suite's files and compares modified time with the binary modified time. If any test file has been changed since the last time the suite has been compiled, the loop breaks, the function returns true and the suite is recompiled. - UPDATED
  3. Adds #skip_compile method to impl Compiler, that returns a CompileOutput struct with a mocked ExitStatus using the ExitStatusExt* trait.
  4. Extracts let (in_files, out_file) = Compiler::get_paths_for(name.clone(), entry); from #compile to main.rs, because in_files and out_file are used to check if any files were changed.
  5. Had to change the arguments which #compile accepts. It is usually not a good thing and goes against the design principles, but on the other hand imo #compile should not be bothered with the logic if it should compile the suite or not and this logic should be outside the method.
  6. Prints to the logs which test are being compiled and which have been skipped.

* ExitStatusExt has a unix and windows versions. I have included it like this, but I don't know if this is the correct way:

#[cfg(unix)]
use std::os::unix::process::ExitStatusExt;

#[cfg(windows)]
use std::os::winows::process::ExitStatusExt;

The alternative is using Command::new() with some dummy command like echo and using the status from the output (hacky)

Screenshots:

Screenshot 2021-12-06 at 14 32 47 Screenshot 2021-12-06 at 14 32 57