* Cleans up the artifacts folder * * Generally called in after()
(tmpPath, preserve)
| 48 | * Generally called in after() |
| 49 | */ |
| 50 | function clean (tmpPath, preserve) { |
| 51 | |
| 52 | /** |
| 53 | * If preserve is a normal integer over 0 thats how many results to keep. |
| 54 | * If string 'all' then keep all |
| 55 | * Else: don't preserve anything |
| 56 | */ |
| 57 | if (preserve === 'all') { |
| 58 | |
| 59 | /** |
| 60 | * Preserve all artifacts |
| 61 | * Don't purge any artifacts |
| 62 | * |
| 63 | * BEWARE: this can fill the disk up over time |
| 64 | */ |
| 65 | return; |
| 66 | |
| 67 | } else if (isNormalNonZeroInteger(preserve)) { |
| 68 | |
| 69 | /** |
| 70 | * Preserve a specific number of artifacts |
| 71 | * |
| 72 | * 1 = keep only th last run |
| 73 | * 2 = keep the last run and the one before it, purging any that happened beforehand |
| 74 | */ |
| 75 | |
| 76 | // Set the path |
| 77 | let artifactsBasePath = path.resolve(tmpPath + '/../artifacts'); |
| 78 | |
| 79 | // The the files in this path |
| 80 | let artifactFolders = fs.readdirSync(artifactsBasePath); |
| 81 | |
| 82 | // Reverse chronologially sort the files |
| 83 | artifactFolders.sort(function (a, b) { |
| 84 | return fs.statSync(path.resolve(artifactsBasePath, b)).mtime.getTime() - fs.statSync(path.resolve(artifactsBasePath, a)).mtime.getTime(); |
| 85 | }); |
| 86 | |
| 87 | // Keep only the number of files defined in the config setting 'preserve'. |
| 88 | keep(artifactsBasePath, artifactFolders, preserve); |
| 89 | } |
| 90 | |
| 91 | // Always purge tmp, it needs to be empty for next run |
| 92 | cleanPath(tmpPath); |
| 93 | } |
| 94 | |
| 95 | function isNormalNonZeroInteger (str) { |
| 96 |
no test coverage detected