Skip to content

Commit

Permalink
👷 cypress end-to-end testing (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax authored Jan 25, 2025
1 parent 4ad8907 commit 0e5d09b
Show file tree
Hide file tree
Showing 7 changed files with 1,663 additions and 242 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ jobs:
PR_TITLE: ${{ github.event.pull_request.title }}
run: echo "$PR_TITLE" | npx commitlint

docker:
name: Docker build
e2e:
name: End-to-end tests
runs-on: ubuntu-latest
steps:
- uses: haliphax/narf/.github@main
- name: Checkout
uses: actions/checkout@v4

- name: Docker build
run: docker build -t narf .
run: docker build -t narf:latest .

- name: Cypress
run: |
mkdir db
docker run -d -p 3000:3000 -v $(pwd)/db:/app/db narf:latest
npm i cypress
npm run e2e
eslint:
runs-on: ubuntu-latest
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
build-essential=12.9 pkg-config=1.8.1-1 python-is-python3=3.11.2-1+deb12u1
COPY package-lock.json package.json ./
RUN npm ci --ignore-scripts --include=dev
RUN npm ci --include=dev
COPY . .
RUN npm run build && npm prune --omit=dev

FROM base
COPY --from=build /app /app
RUN mkdir -p /data
VOLUME /data
RUN mkdir -p /app/db
VOLUME /app/db
EXPOSE 3000
ENV DATABASE_URL="file:///data/sqlite.db"
ENV host="0.0.0.0"
CMD [ "npm", "run", "start" ]
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
supportFile: false,
},
});
33 changes: 33 additions & 0 deletions cypress/e2e/story.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe("story spec", () => {
it("passes", () => {
cy.visit("http://localhost:3000", {})
.get("#title")
.should("be.visible")
.type("Test{enter}")
.location()
.should("match", /\/[%a-zA-Z0-9]+/)
.get('button[title="Vote 1"]')
.click()
.location()
.then((l) => {
localStorage.clear();
cy.visit(l.href)
.get('button[title="Vote 2"]')
.should("be.visible")
.click()
.get("span.y")
.should("be.visible")
.get("button")
.filter((_, e) => e.textContent.includes("Reveal"))
.first()
.click()
.get('dialog[open] button[value="OK"]')
.should("be.visible")
.click()
.get(".🥧")
.should("be.visible")
.find("> div")
.should("have.length", 2);
});
});
});
8 changes: 8 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}
Loading

0 comments on commit 0e5d09b

Please sign in to comment.