From 6a6a58e2ea8d8d2d967962e128e054f7b4f0994a Mon Sep 17 00:00:00 2001 From: rich Date: Fri, 13 Sep 2024 15:06:58 +0100 Subject: [PATCH] Add seeding This adds a seeding job. Using live data is hard to assert against and means we have to run the seeding job which takes time and uses rate-limit tokens. Instead we copy across some test data we can use. This means the data will always be consistent and we can test against it more easily. We can't do this in a setup job [as Playwright recommends](https://playwright.dev/docs/test-global-setup-teardown) because the app depends on the JSON existing before it can start. Instead we have to copy and paste the seed data across before we start the app. --- e2es/seedTestData.js | 14 ++++++++++++ e2es/testData/repos.json | 47 ++++++++++++++++++++++++++++++++++++++++ playwright.config.js | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 e2es/seedTestData.js create mode 100644 e2es/testData/repos.json diff --git a/e2es/seedTestData.js b/e2es/seedTestData.js new file mode 100644 index 0000000..2d02705 --- /dev/null +++ b/e2es/seedTestData.js @@ -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(); diff --git a/e2es/testData/repos.json b/e2es/testData/repos.json new file mode 100644 index 0000000..40e3595 --- /dev/null +++ b/e2es/testData/repos.json @@ -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 + } + ] +} diff --git a/playwright.config.js b/playwright.config.js index c92accb..b6ce368 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -45,7 +45,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: "script/server", + command: "node ./e2es/seedTestData.js && script/server", url: "http://127.0.0.1:3000", reuseExistingServer: !process.env.CI, },