test : changed test format + added playwright support
Check Deno code / Check Deno code (pull_request) Has been cancelled
Tests / Unit tests (pull_request) Has been cancelled
Tests / Integration tests (pull_request) Has been cancelled
Check Deno code / Check Deno code (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Check Deno code / Check Deno code (pull_request) Has been cancelled
Tests / Unit tests (pull_request) Has been cancelled
Tests / Integration tests (pull_request) Has been cancelled
Check Deno code / Check Deno code (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
This commit was merged in pull request #153.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { chromium, Browser, Page } from "npm:playwright";
|
||||
import { assertEquals } from "@std/assert";
|
||||
|
||||
const BASE_URL = Deno.env.get("BASE_URL") || "http://localhost:8000";
|
||||
|
||||
Deno.test({
|
||||
name: "E2E: Guest navigation flow",
|
||||
async fn() {
|
||||
const browser: Browser = await chromium.launch({
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
||||
});
|
||||
const context = await browser.newContext();
|
||||
const page: Page = await context.newPage();
|
||||
|
||||
try {
|
||||
// 1. Home page
|
||||
console.log(`Navigating to ${BASE_URL}...`);
|
||||
await page.goto(BASE_URL);
|
||||
|
||||
const title = await page.innerText("h2");
|
||||
assertEquals(title, "PolyMPR");
|
||||
|
||||
const loginLink = await page.getAttribute("a[href='/login']", "href");
|
||||
assertEquals(loginLink, "/login");
|
||||
|
||||
// 2. Click login
|
||||
await page.click("text=Se connecter");
|
||||
await page.waitForURL("**/login**");
|
||||
console.log("Reached login page.");
|
||||
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
},
|
||||
// On ignore si le serveur n'est pas joignable (hors CI)
|
||||
ignore: Deno.env.get("CI") === undefined && !(await isServerUp()),
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "E2E: App Dashboard accessibility (requires login)",
|
||||
async fn() {
|
||||
const browser: Browser = await chromium.launch({
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
||||
});
|
||||
const page: Page = await browser.newPage();
|
||||
|
||||
try {
|
||||
// Tenter d'accéder à /apps sans être connecté
|
||||
await page.goto(`${BASE_URL}/apps`);
|
||||
|
||||
// On devrait être redirigé vers /login ou voir un message d'erreur
|
||||
const url = page.url();
|
||||
if (url.includes("/login")) {
|
||||
console.log("Correctly redirected to login.");
|
||||
} else {
|
||||
// Si ton middleware ne redirige pas mais affiche une erreur
|
||||
const body = await page.innerText("body");
|
||||
console.log("Landing page url:", url);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
},
|
||||
ignore: Deno.env.get("CI") === undefined && !(await isServerUp()),
|
||||
});
|
||||
|
||||
async function isServerUp() {
|
||||
try {
|
||||
const res = await fetch(BASE_URL);
|
||||
await res.body?.cancel();
|
||||
return res.ok;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user