-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
322 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "start-wasm-example", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@playwright/test": "^1.22.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import type { PlaywrightTestConfig } from '@playwright/test'; | ||
import { devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
const config: PlaywrightTestConfig = { | ||
testDir: './tests', | ||
/* Maximum time one test can run for. */ | ||
timeout: 600 * 1000, | ||
expect: { | ||
/** | ||
* Maximum time expect() should wait for the condition to be met. | ||
* For example in `await expect(locator).toHaveText();` | ||
*/ | ||
timeout: 5000 | ||
}, | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: 1, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'list', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ | ||
actionTimeout: 0, | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://localhost:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { | ||
...devices['Desktop Firefox'], | ||
}, | ||
}, | ||
|
||
// Webkit doesn't work | ||
// { | ||
// name: 'webkit', | ||
// use: { | ||
// ...devices['Desktop Safari'], | ||
// }, | ||
// }, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { | ||
// ...devices['Pixel 5'], | ||
// }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { | ||
// ...devices['iPhone 12'], | ||
// }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { | ||
// channel: 'msedge', | ||
// }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { | ||
// channel: 'chrome', | ||
// }, | ||
// }, | ||
], | ||
|
||
/* Folder for test artifacts such as screenshots, videos, traces, etc. */ | ||
// outputDir: 'test-results/', | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// port: 3000, | ||
// }, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test, expect, Page } from '@playwright/test'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('http://localhost:8000/'); | ||
}); | ||
|
||
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 < 600000) { | ||
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")) { | ||
await page.screenshot({ path: `screenshot-${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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: validation jobs | ||
|
||
on: | ||
push: | ||
branches: | ||
- staging | ||
- trying | ||
- main | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
run-examples-on-wasm: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
target: wasm32-unknown-unknown | ||
override: true | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-wasm-run-examples-${{ hashFiles('**/Cargo.toml') }} | ||
|
||
- name: install xvfb, llvmpipe and lavapipe | ||
run: | | ||
sudo apt-get update -y -qq | ||
sudo add-apt-repository ppa:oibaf/graphics-drivers -y | ||
sudo apt-get update | ||
sudo apt install -y xvfb libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers | ||
- name: Install wasm-bindgen | ||
run: cargo install --force wasm-bindgen-cli | ||
|
||
- name: Run examples | ||
shell: bash | ||
run: | | ||
# start a webserver | ||
python3 -m http.server --directory examples/wasm & | ||
# build the example in wasm | ||
example=.github/example-run/scene.ron | ||
# example_name=`basename $example .ron` | ||
example_name=lighting | ||
echo "running $example_name - "`date` | ||
cp $example ci_testing_config.ron | ||
cargo build --example $example_name --features "bevy_ci_testing" --target wasm32-unknown-unknown | ||
wasm-bindgen --out-dir examples/wasm/target --out-name wasm_example --target web target/wasm32-unknown-unknown/debug/examples/$example_name.wasm | ||
cd .github/start-wasm-example | ||
npm install | ||
npx playwright install --with-deps | ||
xvfb-run npx playwright test --headed | ||
- name: Save screenshots | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: screenshots | ||
path: .github/start-wasm-example/screenshot-*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters