Skip to content

Commit ae4d27e

Browse files
authored
pythongh-124621: Emscripten: Add smoke test for using pyrepl in Chrome (python#137004)
Adds a mechanism to test browser-based initialisation of the Python interpreter, via a Playwright headless browser instance.
1 parent ecb3f23 commit ae4d27e

File tree

8 files changed

+753
-0
lines changed

8 files changed

+753
-0
lines changed

Tools/wasm/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ make a node application that "embeds" the interpreter instead of acting like the
8484
CLI you will need to write your own alternative to `node_entry.mjs`.
8585

8686

87+
### Running tests
88+
89+
After building, you can run the full test suite with:
90+
```shell
91+
./cross-build/wasm32-emscripten/build/python/python.sh -m test -uall
92+
```
93+
You can run the browser smoke test with:
94+
```shell
95+
./Tools/wasm/emscripten/browser_test/run_test.sh
96+
```
97+
8798
### The Web Example
8899

89100
When building for Emscripten, the web example will be built automatically. It
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
test-results
3+
playwright-report
4+
test_log.txt
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('/');
5+
6+
await expect(page).toHaveTitle("Emscripten PyRepl Example");
7+
const xterm = await page.locator('css=#terminal');
8+
await expect(xterm).toHaveText(/Python.*on emscripten.*Type.*for more information/);
9+
const xtermInput = await page.getByRole('textbox');
10+
await xtermInput.pressSequentially(`def f():\nprint("hello", "emscripten repl!")\n\n`);
11+
await xtermInput.pressSequentially(`f()\n`);
12+
await expect(xterm).toHaveText(/hello emscripten repl!/);
13+
14+
});
15+

0 commit comments

Comments
 (0)