Skip to content

Commit

Permalink
API e2e tests using Cypress. Github Action workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmwatson committed Jul 23, 2024
1 parent 3048184 commit 08519b4
Show file tree
Hide file tree
Showing 7 changed files with 965 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Cypress Tests

on: push

jobs:
cypress-run:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
# Install npm dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v6
with:
build: yarn build
start: yarn start
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Open Secrets PowerMapper

[![Tests](https://github.com/OpenUpSA/open-secrets-powermapper/actions/workflows/cypress.yml/badge.svg)](https://github.com/OpenUpSA/open-secrets-powermapper/actions/workflows/cypress.yml)

by [OpenUp](https://OpenUp.org.za).

## Development

```
cp env.example .env
```
```

Modify `.env` with real values.

Expand All @@ -17,8 +19,7 @@ yarn dev
## Deployment

Deployed on Netlify:

https://roaring-cactus-a582ea.netlify.app/

https://roaring-cactus-a582ea.netlify.app/

Automatic deployment of `main` and preview deployments of pull-requests.
Automatic deployment of `main` and preview deployments of pull-requests.
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
supportFile: false,
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
10 changes: 10 additions & 0 deletions cypress/e2e/api-entity-info.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe("Test Entity Info API endpoint", () => {
it("passes", () => {
cy.request("http://localhost:3000/api/entity-info?id=rec2SisdBnuMAZZJb").as(
"entityInfo"
);
cy.get("@entityInfo").should((response) => {
expect(response.body).to.have.property("name");
});
});
});
8 changes: 8 additions & 0 deletions cypress/e2e/api-power-stations.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe("Test Power Stations API endpoint", () => {
it("passes", () => {
cy.request("http://localhost:3000/api/power-stations").as("powerStations");
cy.get("@powerStations").should((response) => {
expect(response.body).to.have.property("powerStations");
});
});
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"test": "cypress run"
},
"dependencies": {
"@emotion/cache": "^11.11.0",
Expand All @@ -30,6 +31,7 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"cypress": "^13.13.1",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"typescript": "^5"
Expand Down
Loading

0 comments on commit 08519b4

Please sign in to comment.