Skip to content

Commit

Permalink
fix(tests): remove hard-coding + wait for responses (freeCodeCamp#56728)
Browse files Browse the repository at this point in the history
Co-authored-by: Shaun Hamilton <[email protected]>
  • Loading branch information
ojeytonwilliams and ShaunSHamilton authored Oct 21, 2024
1 parent 07c3067 commit 4f2d879
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ports:
tasks:
- before: |
echo '
export COOKIE_DOMAIN=gitpod.io
export COOKIE_DOMAIN=.gitpod.io
export HOME_LOCATION=$(gp url 8000)
export API_LOCATION=$(gp url 3000)
export CHALLENGE_EDITOR_API_LOCATION=$(gp url 3200)
Expand All @@ -45,7 +45,7 @@ tasks:
docker compose up -d
- name: server
before: export COOKIE_DOMAIN=gitpod.io && export HOME_LOCATION=$(gp url 8000) && export API_LOCATION=$(gp url 3000)
before: export COOKIE_DOMAIN=.gitpod.io && export HOME_LOCATION=$(gp url 8000) && export API_LOCATION=$(gp url 3000)
# init is not executed for prebuilt workspaces and restarts,
# so we should put all the heavy initialization here
init: >
Expand Down
19 changes: 15 additions & 4 deletions e2e/failed-updates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test.describe('failed update flushing', () => {
}) => {
// Initially, the user has no completed challenges.
const userRes = await request.get(
'http://localhost:3000/user/get-session-user'
new URL('/user/get-session-user', process.env.API_LOCATION).toString()
);
const completedChallenges = (await userRes.json()).user.developmentuser
.completedChallenges;
Expand All @@ -55,16 +55,27 @@ test.describe('failed update flushing', () => {

// The update epic sends two requests and this lets us wait for both.
const submitRes = page
.waitForResponse('http://localhost:3000/modern-challenge-completed')
.waitForResponse(
new URL(
'/modern-challenge-completed',
process.env.API_LOCATION
).toString()
)

.then(() =>
page.waitForResponse('http://localhost:3000/modern-challenge-completed')
page.waitForResponse(
new URL(
'/modern-challenge-completed',
process.env.API_LOCATION
).toString()
)
);

await page.reload();
await submitRes;

const updatedUserRes = await request.get(
'http://localhost:3000/user/get-session-user'
new URL('/user/get-session-user', process.env.API_LOCATION).toString()
);

// Now the user should have both completed challenges.
Expand Down
13 changes: 11 additions & 2 deletions e2e/projects.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { execSync } from 'child_process';
import { test, expect, Page } from '@playwright/test';
import { SuperBlocks } from '../shared/config/curriculum';
import translations from '../client/i18n/locales/english/translations.json';
import tributePageHtml from './fixtures/tribute-page-html.json';
import tributePageCss from './fixtures/tribute-page-css.json';
import curriculum from './fixtures/js-ads-projects.json';
import { authedRequest } from './utils/request';

import { focusEditor, getEditors, clearEditor } from './utils/editor';
import { isMacOS } from './utils/user-agent';
import { alertToBeVisible } from './utils/alerts';

interface Meta {
challengeOrder: { id: string; title: string }[];
Expand Down Expand Up @@ -201,7 +203,7 @@ test.describe('JavaScript projects can be submitted and then viewed in /settings
});
await expect(solutionModal).toBeVisible();
await solutionModal
.getByRole('button', { name: 'Close' })
.getByRole('button', { name: translations.buttons['close'] })
.first()
.click();
// Wait for the modal to disappear before continue
Expand All @@ -210,16 +212,23 @@ test.describe('JavaScript projects can be submitted and then viewed in /settings

await page
.getByRole('button', {
name: "I agree to freeCodeCamp's Academic Honesty Policy."
name: translations.buttons['agree-honesty']
})
.click();

await alertToBeVisible(page, translations.buttons['accepted-honesty']);

await page
.getByRole('button', {
name: 'Claim Certification Legacy JavaScript Algorithms and Data Structures'
})
.click();

await alertToBeVisible(
page,
'@developmentuser, you have successfully claimed the Legacy JavaScript Algorithms and Data Structures Certification! Congratulations on behalf of the freeCodeCamp.org team!'
);

const showCertLink = page.getByRole('link', {
name: 'Show Certification Legacy JavaScript Algorithms and Data Structures'
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/third-party-donation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test.describe('third-party donation tests', () => {
);

await page.route(
'http://localhost:3000/donate/charge-stripe-card',
new URL('donate/charge-stripe-card', process.env.API_LOCATION).toString(),
async route => {
await route.fulfill({ json: { isDonating: true } });
}
Expand Down
4 changes: 3 additions & 1 deletion e2e/utils/add-growthbook-cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export async function addGrowthbookCookie({
{
name: 'gbuuid',
value: variation,
domain: 'localhost',
// Weirdly, it seems necessary to prefix the domain with a dot. This seems
// to be a peculiarity of Playwright.
domain: process.env.COOKIE_DOMAIN || 'localhost',
path: '/',
expires: Math.floor(Date.now() / 1000) + 400 * 24 * 60 * 60 // 400 days from now
}
Expand Down

0 comments on commit 4f2d879

Please sign in to comment.