mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
Add Chromium end-to-end test and fix level list styling
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+4
-4
@@ -34,10 +34,10 @@ Le brief original est [`prompt-pyquest.md`](prompt-pyquest.md) (résumé fidèle
|
|||||||
|
|
||||||
## Reste à faire
|
## Reste à faire
|
||||||
|
|
||||||
1. **Tester dans un vrai navigateur** (`make dev`) : aucun test n'a encore tourné dans Chrome/Firefox/
|
1. **Navigateurs** : parcours validé dans Chromium 155 (`make test-e2e` : niveaux 00 et 01, erreurs
|
||||||
Safari. Le worker, le client et Pyodide sont validés ensemble sous Node
|
traduites, interruption de boucle infinie en ~50 ms, persistance IndexedDB, hors-ligne via
|
||||||
(`tests/js/pyodide-worker.integration.test.mjs`), mais pas l'UI réelle, le service worker, ni
|
service worker, thèmes clair/sombre, mobile 375 px sans débordement). **Reste** : Firefox,
|
||||||
IndexedDB. Prévoir un test sur iOS Safari (mémoire WASM, autoplay audio).
|
Safari desktop et surtout iOS Safari (mémoire WASM, autoplay audio, `SharedArrayBuffer`).
|
||||||
2. Icônes PNG (iOS) en plus de `app/icons/icon.svg`.
|
2. Icônes PNG (iOS) en plus de `app/icons/icon.svg`.
|
||||||
3. Branchement du client de synchronisation (jeton Bearer + `ProgressStore.export/import`) :
|
3. Branchement du client de synchronisation (jeton Bearer + `ProgressStore.export/import`) :
|
||||||
le backend (`backend/sync`) existe, pas encore le côté client ni l'UI.
|
le backend (`backend/sync`) existe, pas encore le côté client ni l'UI.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ VENV := .venv
|
|||||||
VENV_PY := $(VENV)/bin/python
|
VENV_PY := $(VENV)/bin/python
|
||||||
PORT ?= 8000
|
PORT ?= 8000
|
||||||
|
|
||||||
.PHONY: help install vendor-pyodide dev validate-levels build test test-js test-python test-backend typecheck clean
|
.PHONY: help install vendor-pyodide dev validate-levels build test test-js test-python test-backend test-e2e typecheck clean
|
||||||
|
|
||||||
help: ## Affiche cette aide
|
help: ## Affiche cette aide
|
||||||
@grep -E '^[a-z-]+:.*##' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf " %-16s %s\n", $$1, $$2}'
|
@grep -E '^[a-z-]+:.*##' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf " %-16s %s\n", $$1, $$2}'
|
||||||
@@ -41,6 +41,10 @@ test-backend: $(VENV)/.installed ## Tests du backend Django (nécessite Django d
|
|||||||
$(VENV)/bin/pip install --quiet -r backend/requirements.txt
|
$(VENV)/bin/pip install --quiet -r backend/requirements.txt
|
||||||
cd backend && ../$(VENV_PY) manage.py test
|
cd backend && ../$(VENV_PY) manage.py test
|
||||||
|
|
||||||
|
test-e2e: ## Tests bout en bout dans Chromium (CHROMIUM=/chemin/navigateur)
|
||||||
|
npm --prefix tests/e2e install --silent
|
||||||
|
node --test tests/e2e/e2e.test.mjs
|
||||||
|
|
||||||
typecheck: $(VENV)/.installed ## Vérifie les types Python avec pyright
|
typecheck: $(VENV)/.installed ## Vérifie les types Python avec pyright
|
||||||
$(VENV)/bin/pyright
|
$(VENV)/bin/pyright
|
||||||
|
|
||||||
|
|||||||
@@ -256,3 +256,22 @@ body {
|
|||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.explain > :first-child,
|
||||||
|
.cell > :first-child {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.level-button {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.25rem 0.75rem;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.level-title {
|
||||||
|
flex: 1 1 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.level-state {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
// Parcours de bout en bout dans Chromium : niveaux 00 et 01, erreurs, interruption, persistance.
|
||||||
|
// Prérequis : make vendor-pyodide ; un Chromium installé (variable CHROMIUM, défaut /usr/bin/chromium).
|
||||||
|
import { spawn } from 'node:child_process';
|
||||||
|
import { existsSync } from 'node:fs';
|
||||||
|
import { after, before, test } from 'node:test';
|
||||||
|
import assert from 'node:assert';
|
||||||
|
import { chromium } from 'playwright-core';
|
||||||
|
|
||||||
|
const root = new URL('../../', import.meta.url).pathname;
|
||||||
|
const executablePath = process.env.CHROMIUM ?? '/usr/bin/chromium';
|
||||||
|
const port = 8125;
|
||||||
|
const base = `http://127.0.0.1:${port}/`;
|
||||||
|
const skip = !existsSync(`${root}vendor/pyodide/pyodide.mjs`) ? 'vendor/pyodide absent' : !existsSync(executablePath) ? `navigateur absent (${executablePath})` : false;
|
||||||
|
|
||||||
|
let server;
|
||||||
|
let browser;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
if (skip) return;
|
||||||
|
server = spawn('python3', [`${root}scripts/dev_server.py`, '--port', String(port)], { env: { ...process.env, PYQUEST_QUIET: '1' }, stdio: 'ignore' });
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
browser = await chromium.launch({ executablePath, args: ['--no-sandbox'] });
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await browser?.close();
|
||||||
|
server?.kill();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parcours complet des niveaux 00 et 01', { skip, timeout: 180000 }, async () => {
|
||||||
|
const page = await (await browser.newContext()).newPage();
|
||||||
|
const errors = [];
|
||||||
|
page.on('pageerror', (error) => errors.push(error.message));
|
||||||
|
|
||||||
|
await page.goto(base);
|
||||||
|
assert.equal(await page.evaluate(() => crossOriginIsolated), true, 'page isolée (COOP/COEP)');
|
||||||
|
await page.waitForSelector('.explain', { timeout: 60000 });
|
||||||
|
|
||||||
|
const next = () => page.locator('.notebook-action button').last().click();
|
||||||
|
const run = async (code) => {
|
||||||
|
const cell = page.locator('.cell').last();
|
||||||
|
await cell.locator('textarea').fill(code);
|
||||||
|
await cell.locator('.btn-primary').click();
|
||||||
|
await page.waitForFunction(() => document.querySelector('.cell:last-of-type')?.getAttribute('aria-busy') !== 'true');
|
||||||
|
await page.waitForTimeout(150);
|
||||||
|
return (await cell.locator('.cell-feedback').textContent()).trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Niveau 00 : 4 explications puis « Je comprends ».
|
||||||
|
for (let i = 0; i < 4; i++) await next();
|
||||||
|
await next();
|
||||||
|
await page.waitForSelector('.toast');
|
||||||
|
assert.match(await page.textContent('.progress-summary'), /10 XP/);
|
||||||
|
|
||||||
|
// Niveau 01.
|
||||||
|
await page.locator('.level-button', { hasText: 'Ton premier programme' }).click();
|
||||||
|
await page.waitForSelector('.explain');
|
||||||
|
await next();
|
||||||
|
assert.match(await run('print("Bonjour")'), /correct/);
|
||||||
|
await next();
|
||||||
|
assert.match(await run('print("bonjour le monde")'), /majuscules/);
|
||||||
|
assert.match(await run('print(Bonjour)'), /Python ne connaît pas « Bonjour »/);
|
||||||
|
assert.match(await run('print("Bonjour le monde")'), /correct/);
|
||||||
|
|
||||||
|
// Boucle infinie interrompue, puis cellule réutilisable.
|
||||||
|
const cell = page.locator('.cell').last();
|
||||||
|
await cell.locator('textarea').fill('while True:\n pass');
|
||||||
|
await cell.locator('.btn-primary').click();
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
await cell.locator('.btn', { hasText: 'Arrêter' }).click();
|
||||||
|
await page.waitForFunction(() => document.querySelector('.cell:last-of-type')?.getAttribute('aria-busy') !== 'true', null, { timeout: 15000 });
|
||||||
|
assert.match(await cell.locator('.cell-feedback').textContent(), /Exécution arrêtée/);
|
||||||
|
assert.match(await run('print("Bonjour le monde")'), /correct/);
|
||||||
|
|
||||||
|
// La progression survit au rechargement (IndexedDB).
|
||||||
|
await page.reload();
|
||||||
|
await page.waitForSelector('.progress-map .level-button', { timeout: 60000 });
|
||||||
|
assert.match(await page.textContent('.progress-map'), /10 XP/);
|
||||||
|
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
});
|
||||||
Generated
+25
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "pyquest-e2e",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "pyquest-e2e",
|
||||||
|
"dependencies": {
|
||||||
|
"playwright-core": "1.49.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright-core": {
|
||||||
|
"version": "1.49.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.1.tgz",
|
||||||
|
"integrity": "sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"playwright-core": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "pyquest-e2e",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"description": "Tests de bout en bout dans un vrai navigateur (hors dépendances de l'application).",
|
||||||
|
"dependencies": {
|
||||||
|
"playwright-core": "1.49.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user