From 48f80e8979a1d9108eac7b84d27ee7547c6096ad Mon Sep 17 00:00:00 2001 From: Dan Livings Date: Thu, 14 Nov 2024 17:20:10 +0000 Subject: [PATCH] Allow Playwright tests to be authenticated The `GH_TOKEN` environment variable can be used both locally and in CI to avoid testing the GitHub OAuth flow (which is provided by the Octokit library and can therefore be assumed to be well tested). In local development the token can be retrieved by logging into Towtruck and then copying the value of the `Token` cookie. In CI, the correct value is automatically populated by GitHub Actions into a secret. --- .github/workflows/playwright.yml | 1 + e2es/testData/towtruck.db | Bin 16384 -> 16384 bytes e2es/towtruck.spec.js | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 739fb0d..eede2fe 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -30,6 +30,7 @@ jobs: CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }} REDIRECT_URL_BASE: ${{ secrets.REDIRECT_URL_BASE }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: actions/upload-artifact@v4 if: always() with: diff --git a/e2es/testData/towtruck.db b/e2es/testData/towtruck.db index 7c112129059dba5c3cfd147bcebe87942f45d10b..80f2c5e42d8a17e96ed940618a288ec875cfd049 100644 GIT binary patch delta 1345 zcmZ{k&u`LT7{^ zag4*e-XITD6(K-Ad!~6ThCXhmQ z?YOojp0b|v*N*!8SRf(GY%c1DoXk2bb`>#xW7UjD+!NOLO|TrWHMw)%QTm&IM+O(L z(}|S)GA3AG1o{{}o`FZUs&FtZJC?R5!~}(Pl@5hCSPr@;r9ltGNqbJ&EI7J20FPQ} zuWbpysHES~m2%NAij{)asHoK>ypLqs9wL((bubn zTK&tC&=S#B;%dtZoh{RBI++=T6@_9hUXOGA~am>-HP4S+Y z5KQ1G&PNN>GkS|DGoR@n^hN3e#W63ad1jK@r*6^><`VOs{J R1MrSf5JKVxkmuE0^bZ%*x$yu1 delta 1191 zcmZva%WD%+6vk(g%;eF|^Uf>A(k5wIQw@o3sv_A$7osb-)?&pW4SCF%Nvwh~nNr%~ z(z`1NR`3AYy&-l`O*5GvNPYM0LEuLd`V;x znUcH;%&Re=O-~Bj>NY5Za6PqIAb3vuXoMP+f*WqpYoukCf(P27oR*MBa>QdlqieVC zxP|bfTuJW(Er{nIQG>ax0dE-9G(}OLk(|0)_N?sn^6|#RYH&|E51$(VepN-W)~r+_ zt*r!$4b@!4Ud1Xp9=1RuEJdnWcB5p~?6taM z);%tQB9OUNYM%FV+x$~uMfk)Y@>%XZ|5A7&{1yQBom=Hsge$@e{-Ebx;Mhe53K0sa#Cp->9PSd5(#P+#tv^|SP zS5F?jx>l;O<9%Xq+-K&{*yMY1Yzzbtkkn5$K)1eT*8SrIVR7^~_^^i__RdCn91*W_ F;(xO}c|HID diff --git a/e2es/towtruck.spec.js b/e2es/towtruck.spec.js index 0f469fb..3004545 100644 --- a/e2es/towtruck.spec.js +++ b/e2es/towtruck.spec.js @@ -1,11 +1,22 @@ import { test, expect } from "@playwright/test"; -test("has dependency info", async ({ page, baseURL }) => { +test("has dependency info", async ({ page, context, baseURL }) => { + await context.addCookies([{ + name: "Token", + domain: "127.0.0.1", + path: "/", + value: process.env.GH_TOKEN, + }]); + await page.goto(baseURL); await expect(page).toHaveTitle(/Towtruck/); - page.getByText("There are 3 repositories that Towtruck is tracking for dxw."); + expect(await page.getByText("There is 1 organisation using Towtruck that you are a member of.").count()).toBe(1); + + await page.getByRole("link", { name: "dxw", exact: true }).click(); + + expect(await page.getByText("There are 3 repositories that Towtruck is tracking for dxw.").count()).toBe(1); const tableHeadings = [ "Name",