Skip to content

Commit

Permalink
feat(e2e): run e2e tests in parallel and support notggs repo (#1539)
Browse files Browse the repository at this point in the history
* feat(e2e): run e2e tests in parallel

* chore(e2e): use proper name for variable

* chore(e2e): remove extra closing brace
  • Loading branch information
dcshzj authored Oct 4, 2023
1 parent 18e27da commit bda1168
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ jobs:
needs: build
runs-on: ubuntu-latest
environment: staging
strategy:
fail-fast: false
matrix:
type: ["run-email", "run", "run-notggs"]
env:
CYPRESS_RECORD_KEY: ${{secrets.CYPRESS_RECORD_KEY}}
CYPRESS_BASEURL: ${{secrets.CYPRESS_BASEURL}}
Expand Down Expand Up @@ -137,5 +141,14 @@ jobs:
echo "COMMIT_INFO_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
- name: Install dependencies
run: npm ci
- name: Run test ci
- name: Run E2E tests (e2e test repo)
if: ${{ matrix.type == 'run' }}
run: npm run test:ci
- name: Run E2E tests (email test repo)
if: ${{ matrix.type == 'run-email' }}
run: npm run test:email-ci
- name: Run E2E tests (not GGS test repo)
if: ${{ matrix.type == 'run-notggs' }}
env:
CYPRESS_TEST_REPO_NAME: ${{secrets.CYPRESS_NOTGGS_TEST_REPO_NAME}}
run: npm run test:ci
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"release": "npm version $npm_config_isomer_update && git push --tags",
"test": "craco test",
"test:ci": "node scripts/run-e2e.js run",
"test:email-ci": "node scripts/run-e2e.js run-email",
"test-e2e": "source .env && node scripts/run-e2e.js run",
"reset-e2e": "source .env && node scripts/reset-e2e.js",
"lint": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ignore-path .gitignore .",
Expand Down
48 changes: 38 additions & 10 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
CYPRESS_COOKIE_NAME,
CYPRESS_COOKIE_VALUE,
CYPRESS_BACKEND_URL,
CYPRESS_TEST_REPO_NAME,
} = process.env
if (!CYPRESS_COOKIE_NAME || !CYPRESS_COOKIE_VALUE) {
throw new Error(
Expand All @@ -24,21 +25,37 @@ const githubHeaders = {
}

// 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
const runCypressCommand =
cypressCommand === "run"
? `${baseCypressCommand} --record`
: baseCypressCommand

const emailE2ETests = [
"collaborators",
"comments",
"dashboard",
"notifications",
"reviewRequests",
]
// E2E test repositories
const e2eTestRepositoriesWithHashes = {
"e2e-test-repo": "bcfe46da1288b3302c5bb5f72c5c58b50574f26c",
"e2e-email-test-repo": "93593ceb8ee8af690267e49ea787701fc73baed8",
"e2e-notggs-test-repo": "1ccc5253dd06e06a088d1e6ec86a38c870c0a3d6",
}

const cypressCommand = process.argv[2] // either `run`, `run-email` or `open`
const baseCypressCommand = `npx cypress`
let runCypressCommand = baseCypressCommand

// if we are running tests, record them on the dashboard so that github will show the corresponding status
if (cypressCommand === "open") {
runCypressCommand = `${baseCypressCommand} open`
} else if (cypressCommand === "run-email") {
runCypressCommand = `${baseCypressCommand} run --spec "${emailE2ETests
.map((x) => `cypress/e2e/${x}.spec.ts`)
.join(",")}" --record --tag "e2e-email-test-repo"`
} else {
runCypressCommand = `${baseCypressCommand} run --spec "**/!(${emailE2ETests.join(
"|"
)}).spec.ts" --record --tag "${CYPRESS_TEST_REPO_NAME}"`
}

// Reset test repositories
const resetRepository = async (repository, branchName, userType) => {
const endpoint = `${CYPRESS_BACKEND_URL}/sites/${repository}/admin/resetRepo`
Expand All @@ -53,7 +70,7 @@ const resetRepository = async (repository, branchName, userType) => {
{ withCredentials: true }
)
console.log(
`Successfully reset ${repository} (${branchName}) to ${e2eTestRepositoriesWithHashes[repository]}}`
`Successfully reset ${repository} (${branchName}) to ${e2eTestRepositoriesWithHashes[repository]}`
)
}

Expand All @@ -64,8 +81,19 @@ const resetE2ETestRepositories = async () => {
resetRepository("e2e-email-test-repo", "master", "email")
}

const resetRequiredE2ETestRepo = async () => {
if (cypressCommand === "run-email") {
resetRepository("e2e-email-test-repo", "staging", "email")
resetRepository("e2e-email-test-repo", "master", "email")
} else if (cypressCommand === "run") {
resetRepository(CYPRESS_TEST_REPO_NAME, "staging", "github")
} else {
resetE2ETestRepositories()
}
}

const runE2ETests = async () => {
resetE2ETestRepositories()
resetRequiredE2ETestRepo()
.then(() => {
const child = spawn(runCypressCommand, { shell: true })
child.stderr.on("data", (data) => {
Expand Down

0 comments on commit bda1168

Please sign in to comment.