Skip to content

Commit

Permalink
ci: add e2e vercel test action
Browse files Browse the repository at this point in the history
This commit adds several end-to-end tests that can be used
to test whether the Vercel Preview deployment successfully
returns the cards.
  • Loading branch information
rickstaa committed Sep 25, 2022
1 parent fe1ca87 commit 80b4603
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Deployment Test
on:
deployment_status:

jobs:
e2e:
name: Test Preview Deployment
if:
github.event_name == 'deployment_status' &&
github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: npm ci
env:
CI: true
- name: Run end-to-end tests.
run: npm run test:e2e
env:
VERCEL_PREVIEW_URL: ${{ github.event.deployment_status.target_url }}
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ export default {
transform: {},
testEnvironment: "jsdom",
coverageProvider: "v8",
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/tests/e2e/"],
modulePathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/tests/e2e/"],
coveragePathIgnorePatterns: [
"<rootDir>/node_modules/",
"<rootDir>/tests/E2E/",
],
};
7 changes: 7 additions & 0 deletions jest.e2e.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
clearMocks: true,
transform: {},
testEnvironment: "jsdom",
coverageProvider: "v8",
testMatch: ["<rootDir>/tests/E2E/**/*.test.js"],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
"test:update:snapshot": "node --experimental-vm-modules node_modules/jest/bin/jest.js -u",
"test:e2e": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.e2e.config.js",
"theme-readme-gen": "node scripts/generate-theme-doc",
"preview-theme": "node scripts/preview-theme",
"generate-langs-json": "node scripts/generate-langs-json",
Expand Down
43 changes: 43 additions & 0 deletions tests/e2e/e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @file Contains end-to-end tests for the vercel preview instance.
*/
import { describe } from "@jest/globals";
import axios from "axios";

describe("Fetch Cards", () => {
let VERCEL_PREVIEW_URL;

beforeAll(() => {
VERCEL_PREVIEW_URL = process.env.VERCEL_URL;
});

test("retrieve stats card", async () => {
expect(VERCEL_PREVIEW_URL).toBeDefined();
await expect(
axios.get(`${VERCEL_PREVIEW_URL}/api?username=anuraghazra`),
).resolves.not.toThrow();
});

test("retrieve language card", async () => {
expect(VERCEL_PREVIEW_URL).toBeDefined();
await expect(
axios.get(`${VERCEL_PREVIEW_URL}/api/top-langs/?username=anuraghazra`),
).resolves.not.toThrow();
});

test("retrieve WakaTime card", async () => {
expect(VERCEL_PREVIEW_URL).toBeDefined();
await expect(
axios.get(`${VERCEL_PREVIEW_URL}/api/wakatime?username=willianrod`),
).resolves.not.toThrow();
});

test("retrieve repo card", async () => {
expect(VERCEL_PREVIEW_URL).toBeDefined();
await expect(
axios.get(
`${VERCEL_PREVIEW_URL}/api/pin/?username=anuraghazra&repo=github-readme-stats`,
),
).resolves.not.toThrow();
});
});

0 comments on commit 80b4603

Please sign in to comment.