Skip to content

Commit 4f2d879

Browse files
fix(tests): remove hard-coding + wait for responses (freeCodeCamp#56728)
Co-authored-by: Shaun Hamilton <[email protected]>
1 parent 07c3067 commit 4f2d879

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

.gitpod.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ports:
3030
tasks:
3131
- before: |
3232
echo '
33-
export COOKIE_DOMAIN=gitpod.io
33+
export COOKIE_DOMAIN=.gitpod.io
3434
export HOME_LOCATION=$(gp url 8000)
3535
export API_LOCATION=$(gp url 3000)
3636
export CHALLENGE_EDITOR_API_LOCATION=$(gp url 3200)
@@ -45,7 +45,7 @@ tasks:
4545
docker compose up -d
4646
4747
- name: server
48-
before: export COOKIE_DOMAIN=gitpod.io && export HOME_LOCATION=$(gp url 8000) && export API_LOCATION=$(gp url 3000)
48+
before: export COOKIE_DOMAIN=.gitpod.io && export HOME_LOCATION=$(gp url 8000) && export API_LOCATION=$(gp url 3000)
4949
# init is not executed for prebuilt workspaces and restarts,
5050
# so we should put all the heavy initialization here
5151
init: >

e2e/failed-updates.spec.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test.describe('failed update flushing', () => {
3636
}) => {
3737
// Initially, the user has no completed challenges.
3838
const userRes = await request.get(
39-
'http://localhost:3000/user/get-session-user'
39+
new URL('/user/get-session-user', process.env.API_LOCATION).toString()
4040
);
4141
const completedChallenges = (await userRes.json()).user.developmentuser
4242
.completedChallenges;
@@ -55,16 +55,27 @@ test.describe('failed update flushing', () => {
5555

5656
// The update epic sends two requests and this lets us wait for both.
5757
const submitRes = page
58-
.waitForResponse('http://localhost:3000/modern-challenge-completed')
58+
.waitForResponse(
59+
new URL(
60+
'/modern-challenge-completed',
61+
process.env.API_LOCATION
62+
).toString()
63+
)
64+
5965
.then(() =>
60-
page.waitForResponse('http://localhost:3000/modern-challenge-completed')
66+
page.waitForResponse(
67+
new URL(
68+
'/modern-challenge-completed',
69+
process.env.API_LOCATION
70+
).toString()
71+
)
6172
);
6273

6374
await page.reload();
6475
await submitRes;
6576

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

7081
// Now the user should have both completed challenges.

e2e/projects.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { execSync } from 'child_process';
22
import { test, expect, Page } from '@playwright/test';
33
import { SuperBlocks } from '../shared/config/curriculum';
4+
import translations from '../client/i18n/locales/english/translations.json';
45
import tributePageHtml from './fixtures/tribute-page-html.json';
56
import tributePageCss from './fixtures/tribute-page-css.json';
67
import curriculum from './fixtures/js-ads-projects.json';
78
import { authedRequest } from './utils/request';
89

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

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

211213
await page
212214
.getByRole('button', {
213-
name: "I agree to freeCodeCamp's Academic Honesty Policy."
215+
name: translations.buttons['agree-honesty']
214216
})
215217
.click();
216218

219+
await alertToBeVisible(page, translations.buttons['accepted-honesty']);
220+
217221
await page
218222
.getByRole('button', {
219223
name: 'Claim Certification Legacy JavaScript Algorithms and Data Structures'
220224
})
221225
.click();
222226

227+
await alertToBeVisible(
228+
page,
229+
'@developmentuser, you have successfully claimed the Legacy JavaScript Algorithms and Data Structures Certification! Congratulations on behalf of the freeCodeCamp.org team!'
230+
);
231+
223232
const showCertLink = page.getByRole('link', {
224233
name: 'Show Certification Legacy JavaScript Algorithms and Data Structures'
225234
});

e2e/third-party-donation.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test.describe('third-party donation tests', () => {
5959
);
6060

6161
await page.route(
62-
'http://localhost:3000/donate/charge-stripe-card',
62+
new URL('donate/charge-stripe-card', process.env.API_LOCATION).toString(),
6363
async route => {
6464
await route.fulfill({ json: { isDonating: true } });
6565
}

e2e/utils/add-growthbook-cookie.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export async function addGrowthbookCookie({
1111
{
1212
name: 'gbuuid',
1313
value: variation,
14-
domain: 'localhost',
14+
// Weirdly, it seems necessary to prefix the domain with a dot. This seems
15+
// to be a peculiarity of Playwright.
16+
domain: process.env.COOKIE_DOMAIN || 'localhost',
1517
path: '/',
1618
expires: Math.floor(Date.now() / 1000) + 400 * 24 * 60 * 60 // 400 days from now
1719
}

0 commit comments

Comments
 (0)