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

Function processScenarioView

core/util/runPuppet.js:52–304  ·  view source on GitHub ↗
(scenario, variantOrScenarioLabelSafe, scenarioLabelSafe, viewport, config, logger)

Source from the content-addressed store, hash-verified

50}
51
52async function processScenarioView (scenario, variantOrScenarioLabelSafe, scenarioLabelSafe, viewport, config, logger) {
53 const { scenarioDefaults = {} } = config;
54
55 /**
56 * @type {Object}
57 * @description Spread `scenarioDefaults` into the scenario.
58 * @default `scenario`
59 */
60 scenario = {
61 ...scenarioDefaults,
62 ...scenario
63 };
64
65 if (!config.paths) {
66 config.paths = {};
67 }
68
69 if (typeof viewport.label !== 'string') {
70 viewport.label = viewport.name || '';
71 }
72
73 const engineScriptsPath = config.env.engine_scripts || config.env.engine_scripts_default;
74 const isReference = config.isReference;
75
76 const VP_W = viewport.width || viewport.viewport.width;
77 const VP_H = viewport.height || viewport.viewport.height;
78
79 const puppeteerArgs = Object.assign(
80 {},
81 {
82 ignoreHTTPSErrors: true,
83 headless: config.debugWindow ? false : config?.engineOptions?.headless || 'new'
84 },
85 config.engineOptions
86 );
87
88 const browser = await puppeteer.launch(puppeteerArgs);
89 const page = await browser.newPage();
90
91 await page.setViewport({ width: VP_W, height: VP_H });
92 page.setDefaultNavigationTimeout(engineTools.getEngineOption(config, 'waitTimeout', TEST_TIMEOUT));
93
94 if (isReference) {
95 logger.log('blue', 'CREATING NEW REFERENCE FILE');
96 }
97
98 // --- set up console output and ready event ---
99 const readyEvent = scenario.readyEvent || config.readyEvent;
100 const readyTimeout = scenario.readyTimeout || config.readyTimeout || 30000;
101 let readyResolve, readyPromise, readyTimeoutTimer;
102 if (readyEvent) {
103 readyPromise = new Promise(resolve => {
104 readyResolve = resolve;
105 // fire the ready event after the readyTimeout
106 readyTimeoutTimer = setTimeout(() => {
107 logger.error('red', `ReadyEvent not detected within readyTimeout limit. (${readyTimeout} ms)`, scenario.url);
108 resolve();
109 }, readyTimeout);

Callers 1

runPuppet.jsFile · 0.70

Calls 3

puppetCommandsFunction · 0.85
writeScenarioLogsFunction · 0.85
delegateSelectorsFunction · 0.70

Tested by

no test coverage detected