-
Notifications
You must be signed in to change notification settings - Fork 611
Expand file tree
/
Copy pathextendConfig.js
More file actions
110 lines (95 loc) · 3.84 KB
/
extendConfig.js
File metadata and controls
110 lines (95 loc) · 3.84 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var path = require('path');
var temp = require('temp');
var fs = require('fs');
var hash = require('object-hash');
const tmpdir = require('os').tmpdir();
const version = require('../../package.json').version;
function extendConfig (config, userConfig) {
bitmapPaths(config, userConfig);
ci(config, userConfig);
htmlReport(config, userConfig);
jsonReport(config, userConfig);
comparePaths(config);
captureConfigPaths(config);
engine(config, userConfig);
config.id = userConfig.id;
config.engine = userConfig.engine || null;
config.report = userConfig.report || ['browser'];
config.defaultMisMatchThreshold = 0.1;
config.debug = userConfig.debug || false;
config.resembleOutputOptions = userConfig.resembleOutputOptions;
config.asyncCompareLimit = userConfig.asyncCompareLimit;
config.backstopVersion = version;
config.dockerCommandTemplate = userConfig.dockerCommandTemplate;
config.reloadOnError = userConfig.reloadOnError || {
"enabled": false,
"retryCount": 3,
"waitBeforeReload": 1500,
"onStatus": [504, 503, 500],
"outputFile": "retry_urls.json"
}
return config;
}
function bitmapPaths (config, userConfig) {
config.bitmaps_reference = path.join(config.projectPath, 'backstop_data', 'bitmaps_reference');
config.bitmaps_test = path.join(config.projectPath, 'backstop_data', 'bitmaps_test');
if (userConfig.paths) {
config.bitmaps_reference = userConfig.paths.bitmaps_reference || config.bitmaps_reference;
config.bitmaps_test = userConfig.paths.bitmaps_test || config.bitmaps_test;
}
}
function ci (config, userConfig) {
config.ci_report = path.join(config.projectPath, 'backstop_data', 'ci_report');
if (userConfig.paths) {
config.ci_report = userConfig.paths.ci_report || config.ci_report;
}
config.ciReport = {
format: 'junit',
testReportFileName: 'xunit',
testSuiteName: 'BackstopJS'
};
if (userConfig.ci) {
config.ciReport = {
format: userConfig.ci.format || config.ciReport.format,
testReportFileName: userConfig.ci.testReportFileName || config.ciReport.testReportFileName,
testSuiteName: userConfig.ci.testSuiteName || config.ciReport.testSuiteName
};
}
}
function htmlReport (config, userConfig) {
config.html_report = path.join(config.projectPath, 'backstop_data', 'html_report');
config.openReport = userConfig.openReport === undefined ? true : userConfig.openReport;
if (userConfig.paths) {
config.html_report = userConfig.paths.html_report || config.html_report;
}
config.compareConfigFileName = path.join(config.html_report, 'config.js');
config.compareReportURL = path.join(config.html_report, 'index.html');
}
function jsonReport (config, userConfig) {
config.json_report = path.join(config.projectPath, 'backstop_data', 'json_report');
if (userConfig.paths) {
config.json_report = userConfig.paths.json_report || config.json_report;
}
config.compareJsonFileName = path.join(config.json_report, 'jsonReport.json');
}
function comparePaths (config) {
config.comparePath = path.join(config.backstop, 'compare/output');
config.tempCompareConfigFileName = temp.path({ suffix: '.json' });
}
function captureConfigPaths (config) {
var captureDir = path.join(tmpdir, 'capture');
if (!fs.existsSync(captureDir)) {
fs.mkdirSync(captureDir);
}
var configHash = hash(config);
config.captureConfigFileName = path.join(tmpdir, 'capture', configHash + '.json');
config.captureConfigFileNameDefault = path.join(config.backstop, 'capture', 'config.default.json');
}
function engine (config, userConfig) {
config.engine_scripts = path.join(config.projectPath, 'backstop_data', 'engine_scripts');
config.engine_scripts_default = path.join(config.backstop, 'capture', 'engine_scripts');
if (userConfig.paths) {
config.engine_scripts = userConfig.paths.engine_scripts || config.engine_scripts;
}
}
module.exports = extendConfig;