diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml new file mode 100644 index 00000000000000..f78d0f96ab0c86 --- /dev/null +++ b/.github/workflows/e2e-test.yml @@ -0,0 +1,21 @@ +name: Vercel Preview Tests +on: + deployment_status: + +jobs: + e2e: + name: Test Vercel 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 }} diff --git a/jest.config.js b/jest.config.js index 312d88ad8e023a..b4578cf5aaad5a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,4 +3,10 @@ export default { transform: {}, testEnvironment: "jsdom", coverageProvider: "v8", + testPathIgnorePatterns: ["/node_modules/", "/tests/e2e/"], + modulePathIgnorePatterns: ["/node_modules/", "/tests/e2e/"], + coveragePathIgnorePatterns: [ + "/node_modules/", + "/tests/E2E/", + ], }; diff --git a/jest.e2e.config.js b/jest.e2e.config.js new file mode 100644 index 00000000000000..0ad75d0209c9c8 --- /dev/null +++ b/jest.e2e.config.js @@ -0,0 +1,7 @@ +export default { + clearMocks: true, + transform: {}, + testEnvironment: "jsdom", + coverageProvider: "v8", + testMatch: ["/tests/E2E/**/*.test.js"], +}; diff --git a/package.json b/package.json index c2562293401453..3ec19e8a4e1861 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/e2e/e2e.test.js b/tests/e2e/e2e.test.js new file mode 100644 index 00000000000000..6606d6e9f3fd3e --- /dev/null +++ b/tests/e2e/e2e.test.js @@ -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(); + }); +});