-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix/test): resolve reproducibility issues w/ execWithCache
- had removed some duplicate execs in the previous commit in order to speed up tests so that exec wouldn't need to be re-run - but this caused reproducibility issues, as if you change a test to `it.only` temporarily, it would fail hard as nothing would be exec'd if it weren't the first test - this uses an `execWithCache` function to instead naive "cache" the output and not re-run the same command twice-in-a-row - only works with sequential tests, but good enough for now - similar to a beforeAll() for a group of the same test, but no nesting or confusing variables in describe scope - N.B. no need for stageName in cache function or something more complex because each stage is parallelized as multi-process
- Loading branch information
Showing
4 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// this file contains helper utils for working with shell.js functions | ||
const shell = require('shelljs'); | ||
|
||
shell.config.silent = true; | ||
|
||
// simple shell.exec "cache" that doesn't re-run the same command twice in a row | ||
let prevCommand = ''; | ||
let prevCommandOutput = {}; | ||
function execWithCache(command, { noCache = false } = {}) { | ||
// return the old output | ||
if (!noCache && prevCommand === command) return prevCommandOutput; | ||
|
||
const output = shell.exec(command); | ||
|
||
// reset if command is not to be cached | ||
if (noCache) { | ||
prevCommand = ''; | ||
prevCommandOutput = {}; | ||
} else { | ||
prevCommand = command; | ||
prevCommandOutput = output; | ||
} | ||
|
||
return output; | ||
} | ||
|
||
module.exports = { | ||
execWithCache, | ||
}; |