From a03d5093eb5f6d76d8639d5a1052a701d54e6561 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Tue, 23 Jul 2024 17:55:46 -0700 Subject: [PATCH 1/5] First pass on snapshotting script --- client/package.json | 3 +- client/tests/e2e/scripts/takeSnapshots.js | 144 ++++++++++++++++++++++ package.json | 1 + 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 client/tests/e2e/scripts/takeSnapshots.js diff --git a/client/package.json b/client/package.json index 1e167c527..d219798f4 100644 --- a/client/package.json +++ b/client/package.json @@ -11,7 +11,8 @@ "lint": "eslint --ext js,jsx .", "storybook": "start-storybook -p 6006", "build-storybook": "build-storybook", - "lighthouse": "lhci autorun" + "lighthouse": "lhci autorun", + "record-routes": "DOTENV_CONFIG_PATH=../config/test.env node -r dotenv/config tests/e2e/scripts/takeSnapshots.js" }, "repository": { "type": "git", diff --git a/client/tests/e2e/scripts/takeSnapshots.js b/client/tests/e2e/scripts/takeSnapshots.js new file mode 100644 index 000000000..e51712477 --- /dev/null +++ b/client/tests/e2e/scripts/takeSnapshots.js @@ -0,0 +1,144 @@ +/* eslint-disable no-console */ +const puppeteer = require('puppeteer'); +const fs = require('fs').promises; +const path = require('path'); +const prettier = require('prettier'); + +const { + ApolloClient, + InMemoryCache, + gql, + HttpLink +} = require('@apollo/client'); +const getPage = require('../../util/getPage'); +const { setup, teardown } = require('../../util/getPage'); + +const BASE_URL = 'http://localhost:3000'; +const SNAPSHOTS_DIR = path.join(__dirname, 'snapshots'); + +const client = new ApolloClient({ + link: new HttpLink({ uri: `${BASE_URL}/api/graphql` }), + cache: new InMemoryCache() +}); + +async function getReportRoutesForTestPlanVersions() { + const maxValidTestPlanReportId = 19; + return Array.from( + { length: maxValidTestPlanReportId }, + (_, i) => `/test-plan-report/${i + 1}` + ); +} + +async function getBaseRoutes() { + return [ + '/', + '/signup-instructions', + '/account/settings', + '/test-queue', + '/reports', + '/candidate-review', + '/data-management', + '/invalid-request', + '/404' + // TODO + // '/run/:runId', + // '/test-plan-report/:testPlanReportId', + // '/test-review/:testPlanVersionId', + // '/candidate-test-plan/:testPlanVersionId/:atId', + ]; +} + +async function getDataManagementRoutes() { + const query = gql` + query GetTestPlanDirectories { + testPlans { + id + directory + } + } + `; + + const { data } = await client.query({ query }); + return data.testPlans.map( + ({ directory }) => `/data-management/${directory}/` + ); +} + +async function takeSnapshot(browser, role, route) { + const page = await browser.newPage(); + try { + await page.goto(`${BASE_URL}${route}`, { waitUntil: 'networkidle0' }); + + // Remove all