From 947b8171683da54ffa53acb0ca11ef470780ea02 Mon Sep 17 00:00:00 2001 From: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:27:10 +0800 Subject: [PATCH 1/3] fix(e2e): utlise new backend endpoint to reset e2e repos (#1536) * fix(e2e): utlise new backend endpoint to reset e2e repos * fix(e2e): avoid printing actual content of env var --- package-lock.json | 12 ------ package.json | 1 - scripts/build.js | 90 ++++++++++++++++++++++---------------------- scripts/reset-e2e.js | 4 +- scripts/run-e2e.js | 4 +- 5 files changed, 48 insertions(+), 63 deletions(-) diff --git a/package-lock.json b/package-lock.json index 71f29d2d0..a51896d57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -113,7 +113,6 @@ "@typescript-eslint/parser": "^5.55.0", "auto-changelog": "^2.4.0", "babel-jest": "^29.5.0", - "btoa": "^1.2.1", "chromatic": "^6.5.6", "cypress": "^12.8.0", "cypress-pipe": "^2.0.0", @@ -13550,17 +13549,6 @@ "node-int64": "^0.4.0" } }, - "node_modules/btoa": { - "version": "1.2.1", - "dev": true, - "license": "(MIT OR Apache-2.0)", - "bin": { - "btoa": "bin/btoa.js" - }, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/buffer": { "version": "5.2.1", "dev": true, diff --git a/package.json b/package.json index 1d8591296..ae1642f72 100644 --- a/package.json +++ b/package.json @@ -159,7 +159,6 @@ "@typescript-eslint/parser": "^5.55.0", "auto-changelog": "^2.4.0", "babel-jest": "^29.5.0", - "btoa": "^1.2.1", "chromatic": "^6.5.6", "cypress": "^12.8.0", "cypress-pipe": "^2.0.0", diff --git a/scripts/build.js b/scripts/build.js index a47ee3010..ab11fe00d 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -2,23 +2,28 @@ const { spawn } = require("child_process") const axios = require("axios") -const btoa = require("btoa") -// login credentials -const { PERSONAL_ACCESS_TOKEN, USERNAME } = process.env -if (!PERSONAL_ACCESS_TOKEN || !USERNAME) { +// Login credentials +const { + CYPRESS_COOKIE_NAME, + CYPRESS_COOKIE_VALUE, + CYPRESS_BACKEND_URL, +} = process.env +if (!CYPRESS_COOKIE_NAME || !CYPRESS_COOKIE_VALUE) { throw new Error( - `E2E tests require env vars PERSONAL_ACCESS_TOKEN (${PERSONAL_ACCESS_TOKEN}) and USERNAME (${USERNAME}) to be set.` + `E2E tests require env vars CYPRESS_COOKIE_NAME and CYPRESS_COOKIE_VALUE to be set.` ) } -const CREDENTIALS = `${USERNAME}:${PERSONAL_ACCESS_TOKEN}` -const headers = { - authorization: `basic ${btoa(CREDENTIALS)}`, - accept: "application/json", +const emailHeaders = { + Cookie: `${CYPRESS_COOKIE_NAME}=${CYPRESS_COOKIE_VALUE}; e2eUserType=Email admin; site=e2e email test site; email=admin@e2e.gov.sg`, } -// cypress commands +const githubHeaders = { + Cookie: `${CYPRESS_COOKIE_NAME}=${CYPRESS_COOKIE_VALUE}; e2eUserType=Github user`, +} + +// Cypress test runner const cypressCommand = process.argv[2] // either `run` or `open` const baseCypressCommand = `npx cypress ${cypressCommand}` // if we are running tests, record them on the dashboard so that github will show the corresponding status @@ -27,49 +32,40 @@ const runCypressCommand = ? `${baseCypressCommand} --record` : baseCypressCommand -// reset e2e-test-repo -const { E2E_COMMIT_HASH } = process.env -if (!E2E_COMMIT_HASH) { - throw new Error( - `E2E tests require env var E2E_COMMIT_HASH (${E2E_COMMIT_HASH}) to be set.` - ) +// E2E test repositories +const e2eTestRepositoriesWithHashes = { + "e2e-test-repo": "bcfe46da1288b3302c5bb5f72c5c58b50574f26c", + "e2e-email-test-repo": "93593ceb8ee8af690267e49ea787701fc73baed8", + "e2e-notggs-test-repo": "1ccc5253dd06e06a088d1e6ec86a38c870c0a3d6", } -const GITHUB_ORG_NAME = "isomerpages" -const E2E_GITHUB_REPO_NAME = "e2e-test-repo" -const E2E_EMAIL_REPO_NAME = "e2e-email-test-repo" -const E2E_EMAIL_COMMIT_HASH = "93593ceb8ee8af690267e49ea787701fc73baed8" -const resetRepo = async (repo, hash, branch) => { - const endpoint = `https://api.github.com/repos/${GITHUB_ORG_NAME}/${repo}/git/refs/heads/${branch}` - await axios.patch( +// Reset test repositories +const resetRepository = async (repository, branchName, userType) => { + const endpoint = `${CYPRESS_BACKEND_URL}/sites/${repository}/admin/resetRepo` + const headers = userType === "github" ? githubHeaders : emailHeaders + await axios.post( endpoint, { - sha: hash, - force: true, + commitSha: e2eTestRepositoriesWithHashes[repository], + branchName, }, - { - headers, - } + { headers }, + { withCredentials: true } + ) + console.log( + `Successfully reset ${repository} (${branchName}) to ${e2eTestRepositoriesWithHashes[repository]}}` ) - console.log(`Successfully reset ${repo} to ${hash}`) -} - -const resetGithubE2eTestRepo = () => - resetRepo(E2E_GITHUB_REPO_NAME, E2E_COMMIT_HASH, "staging") - -const resetEmailE2eTestRepo = () => { - resetRepo(E2E_EMAIL_REPO_NAME, E2E_EMAIL_COMMIT_HASH, "staging") - resetRepo(E2E_EMAIL_REPO_NAME, E2E_EMAIL_COMMIT_HASH, "master") } -const resetE2eTestRepo = async () => { - await resetGithubE2eTestRepo() - await resetEmailE2eTestRepo() +const resetE2ETestRepositories = async () => { + resetRepository("e2e-test-repo", "staging", "github") + resetRepository("e2e-notggs-test-repo", "staging", "github") + resetRepository("e2e-email-test-repo", "staging", "email") + resetRepository("e2e-email-test-repo", "master", "email") } -// resets the e2e repo then runs the corresponding cypress command -const runE2eTests = async () => - resetE2eTestRepo() +const runE2ETests = async () => { + resetE2ETestRepositories() .then(() => { const child = spawn(runCypressCommand, { shell: true }) child.stderr.on("data", (data) => { @@ -83,7 +79,8 @@ const runE2eTests = async () => // NOTE: Cypress uses the exit code to show the number of failed tests. // If we do not exit here, the child process (that's running the test) will not be able to feedback // to Github Actions if the tests pass. - process.exit(exitCode) + // If exitCode is null, means that the child process was killed by a signal. + process.exit(exitCode || 1) }) }) .catch((err) => { @@ -92,8 +89,9 @@ const runE2eTests = async () => // This also prevents CI from recording this as a successful step. process.exit(1) }) +} module.exports = { - runE2eTests, - resetE2eTestRepo, + runE2ETests, + resetE2ETestRepositories, } diff --git a/scripts/reset-e2e.js b/scripts/reset-e2e.js index 1d5df1d20..e2ec4b6f2 100644 --- a/scripts/reset-e2e.js +++ b/scripts/reset-e2e.js @@ -1,3 +1,3 @@ -const { resetE2eTestRepo } = require("./build") +const { resetE2ETestRepositories } = require("./build") -resetE2eTestRepo() +resetE2ETestRepositories() diff --git a/scripts/run-e2e.js b/scripts/run-e2e.js index 3aee7d219..090ce50b5 100644 --- a/scripts/run-e2e.js +++ b/scripts/run-e2e.js @@ -1,3 +1,3 @@ -const { runE2eTests } = require("./build") +const { runE2ETests } = require("./build") -runE2eTests() +runE2ETests() From 4ad3c38a6e36ce6af89b60be331c529e93cb0a28 Mon Sep 17 00:00:00 2001 From: seaerchin <44049504+seaerchin@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:47:27 +0800 Subject: [PATCH 2/3] Fix/styles (#1560) * fix(annnouncementobdy): remove extra sentenee * fix(hero): fix minor ints * fix(textcardsbody): remove form control from whole group * fix(hero): update styles * fix(hero): update styles --- .../components/Homepage/AnnouncementBody.tsx | 3 +- src/layouts/components/Homepage/HeroBody.tsx | 8 +- .../Homepage/HeroHighlightSection.tsx | 2 +- .../components/Homepage/TextCardsBody.tsx | 223 +++++++++--------- .../components/homepage/_hero.scss | 17 +- .../isomer-template/theme/_breakpoints.scss | 1 + 6 files changed, 131 insertions(+), 123 deletions(-) diff --git a/src/layouts/components/Homepage/AnnouncementBody.tsx b/src/layouts/components/Homepage/AnnouncementBody.tsx index 37487ae3d..64125224e 100644 --- a/src/layouts/components/Homepage/AnnouncementBody.tsx +++ b/src/layouts/components/Homepage/AnnouncementBody.tsx @@ -74,8 +74,7 @@ export const AnnouncementBody = ({ Announcements - {`You can display up to ${MAX_ANNOUNCEMENTS} announcements at a time. Newly added - announcements are shown on the top of the list`} + {`You can display up to ${MAX_ANNOUNCEMENTS} announcements at a time.`} - + Hero Interactions - + Content type - Button Text + Button text {errors.description} - - - Cards - - - Cards are displayed side by side on a desktop screen. You can add up - to 4 cards - - - - - - - {cards.map((card, cardIndex) => ( - - - + Cards + + + Cards are displayed side by side on a desktop screen. You can add up to + 4 cards + + + + + + + {cards.map((card, cardIndex) => ( + + + + Title + + + {cardErrors[cardIndex].title} + + + + Description +