From 4f91f9830b9c8cfb113b05a048890e1b003717a2 Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 4 Feb 2024 13:20:41 +0300 Subject: [PATCH] basic-routes-e2e --- .gitea/workflows/main.yml | 2 +- test/basic-routes.test.js | 33 +++++++++++++++++++++++++++++++++ test/discoursio-webapp.check.js | 21 --------------------- 3 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 test/basic-routes.test.js delete mode 100644 test/discoursio-webapp.check.js diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index f13ab5fd..35df461b 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -47,7 +47,7 @@ jobs: - name: Install playwright browsers run: npx playwright install --with-deps - name: Run Playwright Test - run: npx playwright test test/discoursio-webapp.check.js + run: npx playwright test push: needs: test_with_playwright diff --git a/test/basic-routes.test.js b/test/basic-routes.test.js new file mode 100644 index 00000000..0b3f042e --- /dev/null +++ b/test/basic-routes.test.js @@ -0,0 +1,33 @@ +// test/discoursio-webapp.check.js + +const { chromium } = require('playwright') + +;(async () => { + const browser = await chromium.launch() + const context = await browser.newContext() + + // Define the URLs to visit + const pagesToVisit = [ + 'http://localhost:3000/', + 'http://localhost:3000/feed', + 'http://localhost:3000/create', + 'http://localhost:3000/about/donate', + 'http://localhost:3000/authors', + 'http://localhost:3000/topics', + 'http://localhost:3000/inbox', + ] + + // Loop through the pages and visit each one + for (const pageUrl of pagesToVisit) { + const page = await context.newPage() + await page.goto(pageUrl) + + // Add your test assertions here if needed + + // Close the page before moving to the next one + await page.close() + } + + // Close the browser + await browser.close() +})() diff --git a/test/discoursio-webapp.check.js b/test/discoursio-webapp.check.js deleted file mode 100644 index b9550de3..00000000 --- a/test/discoursio-webapp.check.js +++ /dev/null @@ -1,21 +0,0 @@ -const { chromium } = require('playwright') - -const checkUrl = async (page, targetUrl, pageName) => { - const response = await page.goto(targetUrl) - if (response.status() > 399) { - throw new Error(`Failed with response code ${response.status()}`) - } - - await page.screenshot({ path: `${pageName}.jpg` }) -} - -const browser = await chromium.launch() -const page = await browser.newPage() - -const targetUrl = process.env.ENVIRONMENT_URL || 'https://testing.discours.io' - -await checkUrl(page, targetUrl, 'main') -await checkUrl(page, `${targetUrl}/authors`, 'authors') -await checkUrl(page, `${targetUrl}/topics`, 'topics') -await page.close() -await browser.close()