forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
49 lines (39 loc) · 1.47 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
41
42
43
44
45
46
47
48
49
const execa = require('execa');
const program = require('commander');
const resolveBin = require('resolve-as-bin');
const { resolve, sep } = require('path');
const cypress = (commandName, { updateScreenshots }) => {
// Support running an unpublished dev build
const dirname = __dirname.split(sep).pop();
const projectPath = resolve(`${__dirname}${dirname === 'dist' ? '/..' : ''}`);
// For plugins/extendConfig
const CWD = `CWD=${process.cwd()}`;
// For plugins/compareSnapshots
const UPDATE_SCREENSHOTS = `UPDATE_SCREENSHOTS=${updateScreenshots ? 1 : 0}`;
const cypressOptions = [commandName, '--env', `${CWD},${UPDATE_SCREENSHOTS}`, `--project=${projectPath}`];
const execaOptions = {
cwd: __dirname,
stdio: 'inherit',
};
return execa(resolveBin('cypress'), cypressOptions, execaOptions)
.then(() => {}) // no return value
.catch((error) => {
console.error(error.message);
process.exitCode = 1;
});
};
module.exports = () => {
const updateOption = '-u, --update-screenshots';
const updateDescription = 'update expected screenshots';
program
.command('open')
.description('runs tests within the interactive GUI')
.option(updateOption, updateDescription)
.action((options) => cypress('open', options));
program
.command('run')
.description('runs tests from the CLI without the GUI')
.option(updateOption, updateDescription)
.action((options) => cypress('run', options));
program.parse(process.argv);
};