Skip to content

Commit 11a581b

Browse files
committed
ci: add e2e vercel test action
This commit adds several end-to-end tests that can be used to test whether the Vercel Preview deployment successfully returns the cards.
1 parent fe1ca87 commit 11a581b

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

.github/workflows/e2e-test.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deployment Test
2+
on:
3+
deployment_status:
4+
5+
jobs:
6+
e2e:
7+
name: Test Preview Deployment
8+
if:
9+
github.event_name == 'deployment_status' &&
10+
github.event.deployment_status.state == 'success'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Install dependencies
15+
run: npm ci
16+
env:
17+
CI: true
18+
- name: Run end-to-end tests.
19+
run: npm run test:e2e
20+
env:
21+
VERCEL_PREVIEW_URL: ${{ github.event.deployment_status.target_url }}

jest.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ export default {
33
transform: {},
44
testEnvironment: "jsdom",
55
coverageProvider: "v8",
6+
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/tests/e2e/"],
7+
modulePathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/tests/e2e/"],
8+
coveragePathIgnorePatterns: [
9+
"<rootDir>/node_modules/",
10+
"<rootDir>/tests/E2E/",
11+
],
612
};

jest.e2e.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
clearMocks: true,
3+
transform: {},
4+
testEnvironment: "jsdom",
5+
coverageProvider: "v8",
6+
testMatch: ["<rootDir>/tests/e2e/**/*.test.js"],
7+
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
99
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
1010
"test:update:snapshot": "node --experimental-vm-modules node_modules/jest/bin/jest.js -u",
11+
"test:e2e": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.e2e.config.js",
1112
"theme-readme-gen": "node scripts/generate-theme-doc",
1213
"preview-theme": "node scripts/preview-theme",
1314
"generate-langs-json": "node scripts/generate-langs-json",

tests/e2e/e2e.test.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file Contains end-to-end tests for the vercel preview instance.
3+
*/
4+
import { describe } from "@jest/globals";
5+
import axios from "axios";
6+
7+
describe("Fetch Cards", () => {
8+
let VERCEL_PREVIEW_URL;
9+
10+
beforeAll(() => {
11+
VERCEL_PREVIEW_URL = process.env.VERCEL_URL;
12+
});
13+
14+
test("retrieve stats card", async () => {
15+
expect(VERCEL_PREVIEW_URL).toBeDefined();
16+
await expect(
17+
axios.get(`${VERCEL_PREVIEW_URL}/api?username=anuraghazra`),
18+
).resolves.not.toThrow();
19+
});
20+
21+
test("retrieve language card", async () => {
22+
expect(VERCEL_PREVIEW_URL).toBeDefined();
23+
await expect(
24+
axios.get(`${VERCEL_PREVIEW_URL}/api/top-langs/?username=anuraghazra`),
25+
).resolves.not.toThrow();
26+
});
27+
28+
test("retrieve WakaTime card", async () => {
29+
expect(VERCEL_PREVIEW_URL).toBeDefined();
30+
await expect(
31+
axios.get(`${VERCEL_PREVIEW_URL}/api/wakatime?username=willianrod`),
32+
).resolves.not.toThrow();
33+
});
34+
35+
test("retrieve repo card", async () => {
36+
expect(VERCEL_PREVIEW_URL).toBeDefined();
37+
await expect(
38+
axios.get(
39+
`${VERCEL_PREVIEW_URL}/api/pin/?username=anuraghazra&repo=github-readme-stats`,
40+
),
41+
).resolves.not.toThrow();
42+
});
43+
});

0 commit comments

Comments
 (0)