Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8e32f9

Browse files
authored
ci: add e2e vercel test action (anuraghazra#2054)
* ci: add e2e vercel test actionThis commit adds several end-to-end tests that can be usedto test whether the Vercel Preview deployment successfullyreturns the cards.* test: add additional e2e card tests* test: improve e2e card testsThis commit makes sure that the tests also check whether a valid cardsare returned from the preview deployment.
1 parentfe1ca87 commitf8e32f9

File tree

6 files changed

+209
-2
lines changed

6 files changed

+209
-2
lines changed

‎.github/workflows/e2e-test.yml

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

‎jest.config.js

Lines changed: 6 additions & 0 deletions
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

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

‎package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 2 additions & 1 deletion
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",
@@ -17,7 +18,7 @@
1718
"author":"Anurag Hazra",
1819
"license":"MIT",
1920
"devDependencies": {
20-
"@actions/core":"^1.2.4",
21+
"@actions/core":"^1.9.1",
2122
"@actions/github":"^4.0.0",
2223
"@testing-library/dom":"^8.17.1",
2324
"@testing-library/jest-dom":"^5.16.5",

‎tests/e2e/e2e.test.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/**
2+
*@file Contains end-to-end tests for the Vercel preview instance.
3+
*/
4+
importdotenvfrom"dotenv";
5+
dotenv.config();
6+
7+
import{describe}from"@jest/globals";
8+
importaxiosfrom"axios";
9+
import{renderRepoCard}from"../../src/cards/repo-card.js";
10+
import{renderStatsCard}from"../../src/cards/stats-card.js";
11+
import{renderTopLanguages}from"../../src/cards/top-languages-card.js";
12+
import{renderWakatimeCard}from"../../src/cards/wakatime-card.js";
13+
14+
// Script variables
15+
constREPO="dummy-cra";
16+
constUSER="grsdummy";
17+
constSTATS_DATA={
18+
name:"grsdummy",
19+
totalPRs:1,
20+
totalCommits:2,
21+
totalIssues:1,
22+
totalStars:1,
23+
contributedTo:1,
24+
rank:{
25+
level:"A+",
26+
score:51.01622937949586,
27+
},
28+
};
29+
constLANGS_DATA={
30+
TypeScript:{
31+
color:"#3178c6",
32+
name:"TypeScript",
33+
size:2049,
34+
},
35+
HTML:{
36+
color:"#e34c26",
37+
name:"HTML",
38+
size:1721,
39+
},
40+
CSS:{
41+
color:"#563d7c",
42+
name:"CSS",
43+
size:930,
44+
},
45+
Python:{
46+
color:"#3572A5",
47+
name:"Python",
48+
size:671,
49+
},
50+
};
51+
constWAKATIME_DATA={
52+
human_readable_range:"last week",
53+
is_already_updating:false,
54+
is_coding_activity_visible:false,
55+
is_including_today:false,
56+
is_other_usage_visible:false,
57+
is_stuck:false,
58+
is_up_to_date:false,
59+
is_up_to_date_pending_future:false,
60+
percent_calculated:0,
61+
range:"last_7_days",
62+
status:"pending_update",
63+
timeout:15,
64+
username:"grsdummy",
65+
writes_only:false,
66+
};
67+
constREPOSITORY_DATA={
68+
name:"dummy-cra",
69+
nameWithOwner:"grsdummy/dummy-cra",
70+
isPrivate:false,
71+
isArchived:false,
72+
isTemplate:false,
73+
stargazers:{
74+
totalCount:1,
75+
},
76+
description:"Dummy create react app.",
77+
primaryLanguage:{
78+
color:"#3178c6",
79+
id:"MDg6TGFuZ3VhZ2UyODc=",
80+
name:"TypeScript",
81+
},
82+
forkCount:0,
83+
starCount:1,
84+
};
85+
86+
describe("Fetch Cards",()=>{
87+
letVERCEL_PREVIEW_URL;
88+
89+
beforeAll(()=>{
90+
process.env.NODE_ENV="development";
91+
VERCEL_PREVIEW_URL=process.env.VERCEL_PREVIEW_URL;
92+
});
93+
94+
test("retrieve stats card",async()=>{
95+
expect(VERCEL_PREVIEW_URL).toBeDefined();
96+
97+
// Check if the Vercel preview instance stats card function is up and running.
98+
awaitexpect(
99+
axios.get(`${VERCEL_PREVIEW_URL}/api?username=${USER}`),
100+
).resolves.not.toThrow();
101+
102+
// Get local stats card.
103+
constlocalStatsCardSVG=renderStatsCard(STATS_DATA);
104+
105+
// Get the Vercel preview stats card response.
106+
constserverStatsSvg=awaitaxios.get(
107+
`${VERCEL_PREVIEW_URL}/api?username=${USER}`,
108+
);
109+
110+
// Check if stats card from deployment matches the stats card from local.
111+
expect(serverStatsSvg.data).toEqual(localStatsCardSVG);
112+
});
113+
114+
test("retrieve language card",async()=>{
115+
expect(VERCEL_PREVIEW_URL).toBeDefined();
116+
117+
// Check if the Vercel preview instance language card function is up and running.
118+
awaitexpect(
119+
axios.get(`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}`),
120+
).resolves.not.toThrow();
121+
122+
// Get local language card.
123+
constlocalLanguageCardSVG=renderTopLanguages(LANGS_DATA);
124+
125+
// Get the Vercel preview language card response.
126+
constseverLanguageSVG=awaitaxios.get(
127+
`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}`,
128+
);
129+
130+
// Check if language card from deployment matches the local language card.
131+
expect(severLanguageSVG.data).toEqual(localLanguageCardSVG);
132+
});
133+
134+
test("retrieve WakaTime card",async()=>{
135+
expect(VERCEL_PREVIEW_URL).toBeDefined();
136+
137+
// Check if the Vercel preview instance WakaTime function is up and running.
138+
awaitexpect(
139+
axios.get(`${VERCEL_PREVIEW_URL}/api/wakatime?username=${USER}`),
140+
).resolves.not.toThrow();
141+
142+
// Get local WakaTime card.
143+
constlocalWakaCardSVG=renderWakatimeCard(WAKATIME_DATA);
144+
145+
// Get the Vercel preview WakaTime card response.
146+
constserverWakaTimeSvg=awaitaxios.get(
147+
`${VERCEL_PREVIEW_URL}/api/wakatime?username=${USER}`,
148+
);
149+
150+
// Check if WakaTime card from deployment matches the local WakaTime card.
151+
expect(serverWakaTimeSvg.data).toEqual(localWakaCardSVG);
152+
});
153+
154+
test("retrieve repo card",async()=>{
155+
expect(VERCEL_PREVIEW_URL).toBeDefined();
156+
157+
// Check if the Vercel preview instance Repo function is up and running.
158+
awaitexpect(
159+
axios.get(`${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}`),
160+
).resolves.not.toThrow();
161+
162+
// Get local repo card.
163+
constlocalRepoCardSVG=renderRepoCard(REPOSITORY_DATA);
164+
165+
// Get the Vercel preview repo card response.
166+
constserverRepoSvg=awaitaxios.get(
167+
`${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}`,
168+
);
169+
170+
// Check if Repo card from deployment matches the local Repo card.
171+
expect(serverRepoSvg.data).toEqual(localRepoCardSVG);
172+
});
173+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp