MCPcopy
hub / github.com/ampproject/amphtml / runVisualTests

Function runVisualTests

build-system/tasks/visual-diff/index.js:253–338  ·  view source on GitHub ↗

* Sets the AMP config, launches a server, and generates Percy snapshots for a * set of given webpages. * * @param {!puppeteer.Browser} browser a Puppeteer controlled browser. * @param {!Array<!WebpageDef>} webpages details about the pages to snapshot. * @return {Promise }

(browser, webpages)

Source from the content-addressed store, hash-verified

251 * @return {Promise<void>}
252 */
253async function runVisualTests(browser, webpages) {
254 const numUnfilteredPages = webpages.length;
255 webpages = webpages.filter((webpage) => !webpage.flaky);
256 if (numUnfilteredPages != webpages.length) {
257 log(
258 'info',
259 'Skipping',
260 cyan(numUnfilteredPages - webpages.length),
261 'flaky pages'
262 );
263 }
264 if (argv.grep) {
265 webpages = webpages.filter((webpage) => argv.grep.test(webpage.name));
266 log(
267 'info',
268 cyan(`--grep ${argv.grep}`),
269 'matched',
270 cyan(webpages.length),
271 'pages'
272 );
273 }
274
275 // Expand all the interactive tests. Every test should have a base test with
276 // no interactions, and each test that has in interactive tests file should
277 // load those tests here.
278 for (const webpage of webpages) {
279 webpage.tests_ = {};
280 if (!webpage.no_base_test) {
281 webpage.tests_[''] = BASE_TEST_FUNCTION;
282 }
283 if (webpage.interactive_tests) {
284 try {
285 Object.assign(
286 webpage.tests_,
287 require(path.resolve(ROOT_DIR, webpage.interactive_tests))
288 );
289 } catch (error) {
290 log(
291 'fatal',
292 'Failed to load interactive test',
293 cyan(webpage.interactive_tests),
294 'for test',
295 cyan(webpage.name),
296 '\nError:',
297 error
298 );
299 }
300 }
301 }
302
303 const totalTests = webpages.reduce(
304 (numTests, webpage) => numTests + Object.keys(webpage.tests_).length,
305 0
306 );
307 if (!totalTests) {
308 log('fatal', 'No pages left to test!');
309 } else {
310 log(

Callers 1

performVisualTestsFunction · 0.85

Calls 9

cyanFunction · 0.85
newPageFunction · 0.85
devModeFunction · 0.85
snapshotWebpagesFunction · 0.85
assignMethod · 0.80
resolveMethod · 0.80
logFunction · 0.70
filterMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected