MCPcopy Create free account
hub / github.com/garris/BackstopJS / decorateConfigForCapture

Function decorateConfigForCapture

core/util/createBitmaps.js:29–81  ·  view source on GitHub ↗
(config, isReference)

Source from the content-addressed store, hash-verified

27}
28
29function decorateConfigForCapture (config, isReference) {
30 let configJSON;
31
32 if (typeof config.args.config === 'object') {
33 configJSON = config.args.config;
34 } else {
35 configJSON = Object.assign({}, require(config.backstopConfigFileName));
36 }
37 configJSON.scenarios = configJSON.scenarios || [];
38 ensureViewportLabel(configJSON);
39
40 const totalScenarioCount = configJSON.scenarios.length;
41
42 function pad (number) {
43 let r = String(number);
44 if (r.length === 1) {
45 r = '0' + r;
46 }
47 return r;
48 }
49
50 const screenshotNow = new Date();
51 let screenshotDateTime = screenshotNow.getFullYear() + pad(screenshotNow.getMonth() + 1) + pad(screenshotNow.getDate()) + '-' + pad(screenshotNow.getHours()) + pad(screenshotNow.getMinutes()) + pad(screenshotNow.getSeconds());
52 screenshotDateTime = configJSON.dynamicTestId ? configJSON.dynamicTestId : screenshotDateTime;
53 configJSON.screenshotDateTime = screenshotDateTime;
54 config.screenshotDateTime = screenshotDateTime;
55
56 if (configJSON.dynamicTestId) {
57 console.log(`dynamicTestId '${configJSON.dynamicTestId}' found. BackstopJS will run in dynamic-test mode.`);
58 }
59
60 configJSON.env = cloneDeep(config);
61 configJSON.isReference = isReference;
62 configJSON.paths.tempCompareConfigFileName = config.tempCompareConfigFileName;
63 configJSON.defaultMisMatchThreshold = config.defaultMisMatchThreshold;
64 configJSON.backstopConfigFileName = config.backstopConfigFileName;
65 configJSON.defaultRequireSameDimensions = config.defaultRequireSameDimensions;
66
67 if (config.args.filter) {
68 const scenarios = [];
69 config.args.filter.split(',').forEach(function (filteredTest) {
70 configJSON.scenarios.forEach(function (scenario) {
71 if (regexTest(scenario.label, filteredTest)) {
72 scenarios.push(scenario);
73 }
74 });
75 });
76 configJSON.scenarios = scenarios;
77 }
78
79 logger.log('Selected ' + configJSON.scenarios.length + ' of ' + totalScenarioCount + ' scenarios.');
80 return configJSON;
81}
82
83function saveViewportIndexes (viewport, index) {
84 return Object.assign({}, viewport, { vIndex: index });

Callers 1

createBitmaps.jsFile · 0.85

Calls 3

ensureViewportLabelFunction · 0.85
padFunction · 0.85
regexTestFunction · 0.85

Tested by

no test coverage detected