Skip to content

Commit 0ba3297

Browse files
chore: move playwright tests from main repo (#1341)
* chore: move playwright tests from main repo * fix: update import paths
1 parent 186f015 commit 0ba3297

File tree

6 files changed

+237
-1
lines changed

6 files changed

+237
-1
lines changed

.github/workflows/mobile-curriculum-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
run: npm install -g serve
7777

7878
- name: Run playwright tests
79-
run: npx playwright test --config=playwright-mobile.config.ts
79+
run: npx playwright test --config=mobile/e2e/playwright.config.js
8080

8181
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
8282
if: ${{ !cancelled() }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ play-store-credentials.json
6666

6767
generated-tests/
6868
curriculum.json
69+
70+
# e2e tests
71+
72+
/e2e/playwright

e2e/learn.spec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
// These are all in the freeCodeCamp repo. That repo is installed at the root
4+
// in CI.
5+
import currData from "../../shared/config/curriculum.json";
6+
import { orderedSuperBlockInfo } from "../../tools/scripts/build/build-external-curricula-data";
7+
import { SuperBlocks } from "../../shared/config/curriculum";
8+
9+
// non editor superblocks should be skipped because they are not
10+
// checked if they are compatible with the mobile app.
11+
12+
const nonEditorSB = [
13+
SuperBlocks.PythonForEverybody,
14+
SuperBlocks.DataAnalysisPy,
15+
SuperBlocks.MachineLearningPy,
16+
SuperBlocks.CollegeAlgebraPy,
17+
SuperBlocks.A2English,
18+
SuperBlocks.B1English,
19+
];
20+
21+
const publicSB = orderedSuperBlockInfo
22+
.filter((sb) => sb.public === true && !nonEditorSB.includes(sb.dashedName))
23+
.map((sb) => sb.dashedName);
24+
25+
const removeCertSuperBlock = (currData) => {
26+
const copy = currData;
27+
delete copy["certifications"];
28+
return copy;
29+
};
30+
31+
const typedCurriculum = removeCertSuperBlock(currData);
32+
33+
test.describe("Test challenges in mobile", () => {
34+
for (const superBlock of publicSB) {
35+
for (const currBlock of Object.values(
36+
typedCurriculum[superBlock]["blocks"]
37+
)) {
38+
test.describe(`SuperBlock: ${superBlock} - Block: ${currBlock["meta"]["name"]}`, () => {
39+
for (const currChallenge of currBlock["challenges"]) {
40+
// Skip non-editor challenges
41+
if (![0, 1, 5, 6, 14].includes(currChallenge["challengeType"])) {
42+
continue;
43+
}
44+
45+
test(`Challenge: ${currChallenge["title"]}(${currChallenge["id"]})`, async ({
46+
page,
47+
}) => {
48+
const logMsges = [];
49+
page.on("console", (msg) => {
50+
logMsges.push(msg.text());
51+
});
52+
await page.goto(
53+
`/${superBlock}/${currChallenge["block"]}/${currChallenge["id"]}`
54+
);
55+
expect(logMsges).toContain("completed");
56+
});
57+
}
58+
});
59+
}
60+
}
61+
});

e2e/playwright.config.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import path from 'path';
2+
import { config as dotenvConfig } from 'dotenv';
3+
import { defineConfig, devices } from '@playwright/test';
4+
5+
/**
6+
* Read environment variables from file.
7+
* https://github.com/motdotla/dotenv
8+
*/
9+
const envPath = path.resolve(__dirname, '.env');
10+
dotenvConfig({ path: envPath });
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: '.',
16+
testMatch: '*.spec.js',
17+
/* Run tests in files in parallel */
18+
fullyParallel: true,
19+
/* Fail the build on CI if you accidentally left test.only in the source code. */
20+
forbidOnly: !!process.env.CI,
21+
/* Retry on CI only */
22+
retries: process.env.CI ? 2 : 0,
23+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
24+
reporter: [['html', { outputFolder: 'playwright/reporter' }]],
25+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
26+
timeout: 15 * 1000,
27+
outputDir: 'playwright/test-results',
28+
29+
use: {
30+
/* Base URL to use in actions like `await page.goto('/')`. */
31+
baseURL: 'http://127.0.0.1:3000/',
32+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
33+
trace: 'on-first-retry',
34+
35+
/* Use custom test attribute */
36+
testIdAttribute: 'data-playwright-test-label'
37+
},
38+
39+
/* Configure projects for major browsers */
40+
projects: [
41+
{
42+
name: 'Mobile Chrome',
43+
use: { ...devices['Pixel 5'] }
44+
}
45+
],
46+
47+
/* Run your local dev server before starting the tests */
48+
webServer: {
49+
command: 'cd ../mobile-app && npx serve generated-tests',
50+
url: 'http://127.0.0.1:3000',
51+
reuseExistingServer: !process.env.CI
52+
}
53+
});

package-lock.json

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"prepare": "husky"
3030
},
3131
"devDependencies": {
32+
"@playwright/test": "1.50.1",
33+
"dotenv": "16.4.7",
3234
"husky": "9.0.11",
3335
"lint-staged": "15.2.7",
3436
"npm-run-all2": "6.2.0",

0 commit comments

Comments
 (0)