diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 739fb0d..282cb61 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -30,6 +30,8 @@ jobs: CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }} REDIRECT_URL_BASE: ${{ secrets.REDIRECT_URL_BASE }} + PLAYWRIGHT_GITHUB_USERNAME: ${{ secrets.PLAYWRIGHT_GITHUB_USERNAME }} + PLAYWRIGHT_GITHUB_PASSWORD: ${{ secrets.PLAYWRIGHT_GITHUB_PASSWORD }} - uses: actions/upload-artifact@v4 if: always() with: diff --git a/e2es/auth.setup.js b/e2es/auth.setup.js new file mode 100644 index 0000000..ffe974e --- /dev/null +++ b/e2es/auth.setup.js @@ -0,0 +1,20 @@ +import { test as setup } from '@playwright/test'; + +const USERNAME = process.env.PLAYWRIGHT_GITHUB_USERNAME; +const PASSWORD = process.env.PLAYWRIGHT_GITHUB_PASSWORD; + +setup('authenticate', async ({ page, baseURL }, testInfo) => { + await page.goto(baseURL); + await page.getByRole('button', { name: 'Login with GitHub' }).click(); + + await page.waitForURL(/https:\/\/github.com\/login/); + + await page.getByLabel('Username or email address').fill(USERNAME); + await page.getByLabel('Password').fill(PASSWORD); + + await page.locator('[type=submit]').click(); + + await page.waitForURL(baseURL); + + await page.context().storageState({ path: testInfo.outputPath('user.json') }); +}); diff --git a/e2es/seedTestData.js b/e2es/seed.setup.js similarity index 100% rename from e2es/seedTestData.js rename to e2es/seed.setup.js diff --git a/e2es/testData/towtruck.db b/e2es/testData/towtruck.db index 7c11212..80f2c5e 100644 Binary files a/e2es/testData/towtruck.db and b/e2es/testData/towtruck.db differ diff --git a/e2es/towtruck.spec.js b/e2es/towtruck.spec.js index 0f469fb..166bd5d 100644 --- a/e2es/towtruck.spec.js +++ b/e2es/towtruck.spec.js @@ -5,7 +5,11 @@ test("has dependency info", async ({ page, 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", diff --git a/playwright.config.js b/playwright.config.js index b6ce368..14254a2 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -33,19 +33,19 @@ export default defineConfig({ projects: [ { - name: "setup data", - testMatch: /seed\.test\.data\.js/, + name: "setup", + testMatch: /.*\.setup\.js/, }, { name: "chromium", use: { ...devices["Desktop Chrome"] }, - dependencies: ["setup data"], + dependencies: ["setup"], }, ], /* Run your local dev server before starting the tests */ webServer: { - command: "node ./e2es/seedTestData.js && script/server", + command: "script/server", url: "http://127.0.0.1:3000", reuseExistingServer: !process.env.CI, },