forked from haim-io/cypress-image-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
40 lines (36 loc) · 1 KB
/
cli.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
import arg from 'arg'
import colors from 'colors/safe'
import fs from 'fs-extra'
import path from './config'
import { readDir } from './utils'
const parseArgumentsIntoOptions = rawArgs => {
const args = arg(
{
'--update': Boolean,
'-u': '--update',
},
{
argv: rawArgs.slice(2),
}
)
return {
updateBaseline: args['--update'] || false,
}
}
// eslint-disable-next-line import/prefer-default-export
export function cli(args) {
const options = parseArgumentsIntoOptions(args)
if (options.updateBaseline) {
// Only update image if it failed the comparison
const filesToUpdate = readDir(path.dir.diff)
if (filesToUpdate) {
filesToUpdate.forEach(file => {
fs.copySync(`${path.dir.comparison}/${file}`, `${path.dir.baseline}/${file}`)
console.log(colors.green(`Updated baseline image ${file}`))
})
} else {
const output = 'No baselines to be updated. Make sure to run the visual tests before running update.'
console.log(colors.yellow(output))
}
}
}