Skip to content

Commit

Permalink
Allow Playwright tests to be authenticated
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danlivings-dxw committed Nov 28, 2024
1 parent 39e03b1 commit 91d2391
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Binary file modified e2es/testData/towtruck.db
Binary file not shown.
15 changes: 13 additions & 2 deletions e2es/towtruck.spec.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 91d2391

Please sign in to comment.