# Objective - Run examples in WASM in CI - Fix #4817 ## Solution - on feature `bevy_ci_testing` - add an extra log message before exiting - when building for wasm, read CI config file at compile time - add a simple [playwright](https://playwright.dev) test script that opens the browser then waits for the success log, and takes a screenshot - add a CI job that runs the playwright test for Chromium and Firefox on one example (lighting) and save the screenshots - Firefox screenshot is good (with some clusters visible) - Chromium screenshot is gray, I don't know why but it's logging `GPU stall due to ReadPixels` - Webkit is not enabled for now, to revisit once https://bugs.webkit.org/show_bug.cgi?id=234926 is fixed or worked around - the CI job only runs on bors validation example run: https://github.com/mockersf/bevy/actions/runs/2361673465. The screenshots can be downloaded
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { test, expect, Page } from '@playwright/test';
 | 
						|
 | 
						|
test.beforeEach(async ({ page }) => {
 | 
						|
  await page.goto('http://localhost:8000/');
 | 
						|
});
 | 
						|
 | 
						|
const MAX_TIMEOUT_FOR_TEST = 300_000;
 | 
						|
 | 
						|
test.describe('WASM example', () => {
 | 
						|
  test('Wait for success', async ({ page }, test_info) => {
 | 
						|
    let start = new Date().getTime();
 | 
						|
 | 
						|
    let found = false;
 | 
						|
    while (new Date().getTime() - start < MAX_TIMEOUT_FOR_TEST) {
 | 
						|
      let msg = await promise_with_timeout(100, on_console(page), "no log found");
 | 
						|
      if (msg.includes("no log found")) {
 | 
						|
        continue;
 | 
						|
      }
 | 
						|
      console.log(msg);
 | 
						|
      if (msg.includes("Test successful")) {
 | 
						|
        let prefix = process.env.SCREENSHOT_PREFIX === undefined ? "screenshot" : process.env.SCREENSHOT_PREFIX;
 | 
						|
        await page.screenshot({ path: `${prefix}-${test_info.project.name}.png`, fullPage: true });
 | 
						|
        found = true;
 | 
						|
        break;
 | 
						|
      }
 | 
						|
    }
 | 
						|
 | 
						|
    expect(found).toBe(true);
 | 
						|
  });
 | 
						|
 | 
						|
});
 | 
						|
 | 
						|
function on_console(page) {
 | 
						|
  return new Promise(resolve => {
 | 
						|
    page.on('console', msg => resolve(msg.text()));
 | 
						|
  });
 | 
						|
}
 | 
						|
 | 
						|
async function promise_with_timeout(time_limit, task, failure_value) {
 | 
						|
  let timeout;
 | 
						|
  const timeout_promise = new Promise((resolve, reject) => {
 | 
						|
    timeout = setTimeout(() => {
 | 
						|
      resolve(failure_value);
 | 
						|
    }, time_limit);
 | 
						|
  });
 | 
						|
  const response = await Promise.race([task, timeout_promise]);
 | 
						|
  if (timeout) {
 | 
						|
    clearTimeout(timeout);
 | 
						|
  }
 | 
						|
  return response;
 | 
						|
} |