Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playwright #37

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: script/setup
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,7 @@ towtruck.private-key.pem

# Sensitive repo data
/data
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
"recommendations": ["esbenp.prettier-vscode", "ms-playwright.playwright"]
}
14 changes: 14 additions & 0 deletions e2es/seedTestData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { copyFile, mkdir } from "fs/promises";

export const createDestinationDirectory = async () => {
console.info("Creating destination directory...");
await mkdir("./data");
};

export const seedTestData = async () => {
console.info("Seeding test data...");
await copyFile("./e2es/testData/repos.json", "./data/repos.json");
};

await createDestinationDirectory();
await seedTestData();
47 changes: 47 additions & 0 deletions e2es/testData/repos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"org": "dxw",
"repos": [
{
"name": "optionparser",
"description": "Command-line option parser for PHP (forked with a `v1.0.0`)",
"htmlUrl": "https://github.com/dxw/optionparser",
"apiUrl": "https://api.github.com/repos/dxw/optionparser",
"pullsUrl": "https://api.github.com/repos/dxw/optionparser/pulls{/number}",
"issuesUrl": "https://api.github.com/repos/dxw/optionparser/issues{/number}",
"updatedAt": "2024-07-08T12:39:14Z",
"language": "PHP",
"topics": ["composer", "govpress", "packagist", "php"],
"openIssues": 0,
"dependencies": [],
"openPrsCount": 0
},
{
"name": "govuk-blogs",
"description": "This is the theme in use for the blogs hosted at blog.gov.uk.",
"htmlUrl": "https://github.com/dxw/govuk-blogs",
"apiUrl": "https://api.github.com/repos/dxw/govuk-blogs",
"pullsUrl": "https://api.github.com/repos/dxw/govuk-blogs/pulls{/number}",
"issuesUrl": "https://api.github.com/repos/dxw/govuk-blogs/issues{/number}",
"updatedAt": "2024-09-04T09:02:48Z",
"language": "PHP",
"topics": ["govpress", "wordpress-theme"],
"openIssues": 1,
"dependencies": [],
"openPrsCount": 0
},
{
"name": "php-missing",
"description": "Some functions missing from PHP's stdlib",
"htmlUrl": "https://github.com/dxw/php-missing",
"apiUrl": "https://api.github.com/repos/dxw/php-missing",
"pullsUrl": "https://api.github.com/repos/dxw/php-missing/pulls{/number}",
"issuesUrl": "https://api.github.com/repos/dxw/php-missing/issues{/number}",
"updatedAt": "2024-07-18T18:12:43Z",
"language": "PHP",
"topics": ["composer", "govpress", "packagist", "php"],
"openIssues": 7,
"dependencies": [],
"openPrsCount": 2
}
]
}
22 changes: 22 additions & 0 deletions e2es/towtruck.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, expect } from "@playwright/test";

test("has dependency info", async ({ page, baseURL }) => {
await page.goto(baseURL);

await expect(page).toHaveTitle(/Towtruck/);

page.getByText("There are 3 repositories that Towtruck is tracking for dxw.");

const tableHeadings = [
"Name",
"Description",
"Language",
"Last Updated",
"Open issues count",
"Open PRs count",
"Dependencies",
];
tableHeadings.forEach((heading) => {
page.getByRole("columnheader", { name: heading });
});
});
3 changes: 0 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { createServer } from "http";
import nunjucks from "nunjucks";
import { getReposFromJson, mapRepoFromStorageToUi } from "./utils/index.js";
import { OctokitApp } from "./octokitApp.js";

nunjucks.configure({
autoescape: true,
watch: true,
});

const httpServer = createServer(async (request, response) => {
if (await OctokitApp.middleware(request, response)) return;

const pathToRepos = "./data/repos.json";
const persistedData = await getReposFromJson(pathToRepos);

Expand Down
3 changes: 1 addition & 2 deletions octokitApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const app = new App({
},
});

// eslint-disable-next-line no-unused-vars
app.webhooks.onAny(({ id, name, payload }) => {
app.webhooks.onAny(({ name }) => {
console.log(name, "event received");
});

Expand Down
82 changes: 82 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
},
"devDependencies": {
"@eslint/js": "^9.9.1",
"@playwright/test": "^1.47.0",
"@types/node": "^22.5.4",
"chokidar": "^3.6.0",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
Expand Down
52 changes: 52 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });

/**
* @see https://playwright.dev/docs/test-configuration
*/
export default defineConfig({
testDir: "./e2es",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
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",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
baseURL: "http://127.0.0.1:3000",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

projects: [
{
name: "setup data",
testMatch: /seed\.test\.data\.js/,
},
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
dependencies: ["setup data"],
},
],

/* Run your local dev server before starting the tests */
webServer: {
command: "node ./e2es/seedTestData.js && script/server",
url: "http://127.0.0.1:3000",
reuseExistingServer: !process.env.CI,
},
});
Loading