-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackstop.js
More file actions
51 lines (42 loc) · 1.37 KB
/
backstop.js
File metadata and controls
51 lines (42 loc) · 1.37 KB
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
50
const fs = require('fs');
const backstop = require('backstopjs');
const args = require('yargs').argv;
const project = args.p;
const view = args.v;
const constants = require('./constants');
const projectConstants = require(`./projects/${project}/constants`);
const projectData = require(`./projects/${project}/scenarios.js`)({
baseUrl: constants.DEFAULT_HOST,
DEFAULT_DELAY: constants.DEFAULT_DELAY,
viewport: view,
projectConstants: projectConstants
});
const projectConfig = require("./backstop.config.js")({
project: project,
viewport: constants.VIEWPORTS[view],
scenarios: projectData.scenarios.map((scenario) => {
return Object.assign({}, constants.SCENARIO_DEFAULTS, scenario);
})
});
let commandToRun = "";
if (args.reference) {
commandToRun = "reference";
}
if (args.test) {
commandToRun = "test";
}
if (args.approve) {
commandToRun = "approve";
}
if (args.openReport) {
commandToRun = "openReport";
}
process.argv = []; // This is to avoid passing (y)args to the Backstop Client
const fileName = `backstop.json`
fs.writeFile(fileName, JSON.stringify(projectConfig, null, 4), 'utf8', () => {
console.log(`Successfully generated ${fileName} file.`);
if (commandToRun !== '') {
console.log(`Executing Command: ${commandToRun}`);
backstop(commandToRun, { docker: true, config: 'backstop.json' });
}
});