This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
cleanScreenshots.js
48 lines (39 loc) · 1.68 KB
/
cleanScreenshots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const fs = require('fs-extra');
const glob = require('glob');
const path = require('path');
const { Logger } = require('@cerner/terra-cli');
const logger = new Logger({ prefix: '[terra-functional-testing:cleanScreenshots]' });
// eslint-disable-next-line global-require, import/no-dynamic-require
const isDirectory = filePath => (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory());
async function cleanScreenshots() {
const monoRepoPath = path.resolve(process.cwd(), 'packages');
const isMonoRepo = fs.existsSync(monoRepoPath);
let patterns = [];
// Check whether or not it a monorepo and then get the paths to the snapshot directories.
if (isMonoRepo) {
const packageNames = fs.readdirSync(monoRepoPath);
packageNames.forEach((packageName) => {
patterns.push(path.resolve(monoRepoPath, packageName, 'tests', 'wdio', '__snapshots__', 'diff'));
patterns.push(path.resolve(monoRepoPath, packageName, 'tests', 'wdio', '__snapshots__', 'error'));
patterns.push(path.resolve(monoRepoPath, packageName, 'tests', 'wdio', '__snapshots__', 'latest'));
});
} else {
patterns = [
`${process.cwd()}/tests/wdio/__snapshots__/diff`,
`${process.cwd()}/tests/wdio/__snapshots__/error`,
`${process.cwd()}/tests/wdio/__snapshots__/latest`,
];
}
// Determine the existing snapshot directories.
const screenshotDirectories = patterns.filter((pattern) => (
glob.sync(pattern).length > 0
));
// Delete the existing snapshot directories.
screenshotDirectories.forEach((dir) => {
if (isDirectory(dir)) {
fs.removeSync(dir);
}
});
logger.info('Cleaned wdio snapshots directories.');
}
module.exports = cleanScreenshots;