(
testName,
callback,
{ focus = false, skip = false, timeout } = {}
)
| 378 | * key `focus` to true to only run this test, or its `skip` key to skip it. |
| 379 | */ |
| 380 | export function visualTest( |
| 381 | testName, |
| 382 | callback, |
| 383 | { focus = false, skip = false, timeout } = {} |
| 384 | ) { |
| 385 | let suiteFn = describe; |
| 386 | if (focus) { |
| 387 | suiteFn = suiteFn.only; |
| 388 | } |
| 389 | if (skip) { |
| 390 | suiteFn = suiteFn.skip; |
| 391 | } |
| 392 | |
| 393 | suiteFn(testName, function() { |
| 394 | let name; |
| 395 | let myp5; |
| 396 | let lastDeviceRatio = window.devicePixelRatio; |
| 397 | |
| 398 | beforeAll(function() { |
| 399 | name = namePrefix + escapeName(testName); |
| 400 | // Force everything to be 1x |
| 401 | window.devicePixelRatio = 1; |
| 402 | return new Promise(res => { |
| 403 | myp5 = new p5(function(p) { |
| 404 | p.setup = function() { |
| 405 | res(); |
| 406 | }; |
| 407 | }); |
| 408 | }); |
| 409 | }); |
| 410 | |
| 411 | afterAll(function() { |
| 412 | window.devicePixelRatio = lastDeviceRatio; |
| 413 | myp5.remove(); |
| 414 | }); |
| 415 | |
| 416 | test('matches expected screenshots', async function() { |
| 417 | let expectedScreenshots; |
| 418 | try { |
| 419 | const metadata = JSON.parse(await readFile( |
| 420 | `./test/unit/visual/screenshots/${name}/metadata.json` |
| 421 | )); |
| 422 | expectedScreenshots = metadata.numScreenshots; |
| 423 | } catch (e) { |
| 424 | console.log(e); |
| 425 | expectedScreenshots = 0; |
| 426 | } |
| 427 | |
| 428 | const actual = []; |
| 429 | |
| 430 | // Generate screenshots |
| 431 | await callback(myp5, async () => { |
| 432 | const img = await myp5.get(); |
| 433 | img.pixelDensity(1); |
| 434 | actual.push(img); |
| 435 | }); |
| 436 | |
| 437 |
no test coverage detected