Add two tests for scramjet, many more coming soon

This commit is contained in:
wearrrrr 2024-10-20 21:45:13 -05:00
parent 46e252b1c7
commit a105aa97ce
4 changed files with 53 additions and 21 deletions

View file

@ -4,6 +4,7 @@
"description": "An experimental web proxy that aims to be the successor to Ultraviolet", "description": "An experimental web proxy that aims to be the successor to Ultraviolet",
"main": "./lib/index.cjs", "main": "./lib/index.cjs",
"types": "./lib/index.d.js", "types": "./lib/index.d.js",
"type": "module",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/MercuryWorkshop/scramjet" "url": "https://github.com/MercuryWorkshop/scramjet"
@ -16,7 +17,8 @@
"pub": "npm publish --no-git-checks --access public", "pub": "npm publish --no-git-checks --access public",
"format": "prettier --config .prettierrc.js --write .", "format": "prettier --config .prettierrc.js --write .",
"lint": "eslint ./src/", "lint": "eslint ./src/",
"lint:fix": "eslint ./src/ --fix" "lint:fix": "eslint ./src/ --fix",
"test": "cd tests && npx playwright test"
}, },
"files": [ "files": [
"dist", "dist",
@ -50,7 +52,6 @@
"typescript": "^5.6.3", "typescript": "^5.6.3",
"wisp-server-node": "^1.1.7" "wisp-server-node": "^1.1.7"
}, },
"type": "module",
"dependencies": { "dependencies": {
"@mercuryworkshop/bare-mux": "^2.1.5", "@mercuryworkshop/bare-mux": "^2.1.5",
"dom-serializer": "^2.0.0", "dom-serializer": "^2.0.0",

View file

@ -13,23 +13,16 @@ import { defineConfig, devices } from "@playwright/test";
*/ */
export default defineConfig({ export default defineConfig({
testDir: "./tests", testDir: "./tests",
/* Run tests in files in parallel */
fullyParallel: true, fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI, forbidOnly: !!process.env.CI,
/* Retry on CI only */ retries: 0,
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html", reporter: "html",
timeout: 20000,
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: { use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry", trace: "on-first-retry",
actionTimeout: 5000,
}, },
/* Configure projects for major browsers */ /* Configure projects for major browsers */
@ -38,10 +31,9 @@ export default defineConfig({
name: "chromium", name: "chromium",
use: { ...devices["Desktop Chrome"] }, use: { ...devices["Desktop Chrome"] },
}, },
// { // {
// name: 'firefox', // name: "firefox",
// use: { ...devices['Desktop Firefox'] }, // use: { ...devices["Desktop Firefox"] },
// }, // },
], ],
@ -49,6 +41,6 @@ export default defineConfig({
webServer: { webServer: {
command: "cd .. && pnpm run dev", command: "cd .. && pnpm run dev",
url: "http://127.0.0.1:1337", url: "http://127.0.0.1:1337",
reuseExistingServer: !process.env.CI, reuseExistingServer: true,
}, },
}); });

View file

@ -1,12 +1,30 @@
import { test, expect } from "@playwright/test"; import { test, expect } from "@playwright/test";
import { setupPage } from "./setupPage";
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:1337"); await page.goto("http://localhost:1337/");
}); });
test.describe("Page loaded", () => { test.describe("YouTube", () => {
test("should display the title", async ({ page }) => { test("The front page can load.", async ({ page }) => {
const title = await page.locator("h1").textContent(); const frame = await setupPage(page, "https://www.youtube.com/");
expect(title).toBe("Percury Unblocker");
// Wait for the page inside the iframe to load
const logo = await frame.locator("#logo-icon > span > div").first().waitFor({ state: "visible" });
expect(logo).not.toBeNull();
});
test("The search page can load.", async ({ page }) => {
const frame = await setupPage(page, "https://www.youtube.com/results?search_query=bad+apple");
const title = await frame.locator("#video-title > yt-formatted-string").first().textContent({ timeout: 5000 });
const thumbnailSelector = "#contents > ytd-video-renderer:nth-child(1) > #dismissible > ytd-thumbnail > a > yt-image > img";
await frame.locator(thumbnailSelector).waitFor({ state: "visible" });
const thumbnailSrc = await frame.locator(thumbnailSelector).getAttribute("src", { timeout: 5000 });
expect(title).not.toBeNull();
expect(thumbnailSrc).not.toBeNull();
}); });
}) })

21
tests/tests/setupPage.ts Normal file
View file

@ -0,0 +1,21 @@
/* eslint-disable no-async-promise-executor */
import { expect, FrameLocator, Page } from "@playwright/test";
export function setupPage(page: Page, url: string): Promise<FrameLocator> {
return new Promise(async (resolve) => {
await page.waitForSelector(".version > b");
const bar = page.locator(".bar");
const title = await page.locator(".version > b").textContent();
const frame = page.frameLocator("iframe");
expect(title).toBe("scramjet");
expect(bar).not.toBeNull();
await bar.fill(url);
await page.waitForTimeout(1000);
await bar.press("Enter");
resolve(frame);
});
}