Skip to content

Commit de8de1f

Browse files
committed
Added simple Cypress spce
1 parent f36aa01 commit de8de1f

File tree

6 files changed

+51
-49
lines changed

6 files changed

+51
-49
lines changed

.github/workflows/deploy.yml

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,46 @@ on:
77
branches: [ main ]
88
# Allows you to run this workflow manually from the Actions tab on GitHub.
99
workflow_dispatch:
10+
pull_request:
11+
branches: [ main ]
1012

11-
# Allow this job to clone the repo and create a page deployment
13+
# Allow this job to clone the repo and create a page deployment
1214
permissions:
1315
contents: read
1416
pages: write
1517
id-token: write
1618

1719
jobs:
18-
specs:
20+
test-and-deploy:
1921
runs-on: ubuntu-latest
20-
steps:
21-
- name: Check out your repository using git
22-
uses: actions/checkout@v3
23-
24-
- name: Use Node.js 16
25-
uses: actions/setup-node@v3
26-
with:
27-
node-version: '16'
28-
cache: 'npm'
29-
30-
- name: Install dependencies
31-
run: npm ci
32-
33-
- name: Run specs
34-
run: npm run test
35-
36-
build:
37-
runs-on: ubuntu-latest
38-
needs: specs
39-
env:
40-
NODE_ENV: production
4122

4223
steps:
43-
- name: Check out your repository using git
44-
uses: actions/checkout@v3
24+
- name: Checkout code
25+
uses: actions/checkout@v4
4526

46-
- name: Use Node.js 16
47-
uses: actions/setup-node@v3
48-
with:
49-
node-version: '16'
50-
cache: 'npm'
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '20'
31+
cache: 'npm'
5132

52-
- name: Install dependencies
53-
run: npm ci
33+
- name: Install dependencies
34+
run: npm ci
5435

55-
- name: Build React
56-
run: npm run build
36+
- name: Build project
37+
run: npm run build
5738

58-
- name: Upload artifact
59-
uses: actions/upload-pages-artifact@v1
60-
with:
61-
path: ./build
39+
- name: Run tests
40+
uses: cypress-io/github-action@v6
41+
with:
42+
start: npm run preview
43+
wait-on: 'http://localhost:5173'
44+
browser: chrome
45+
config: baseUrl=http://localhost:5173
6246

63-
deploy:
64-
environment:
65-
name: github-pages
66-
url: ${{ steps.deployment.outputs.page_url }}
67-
runs-on: ubuntu-latest
68-
needs: build
69-
steps:
7047
- name: Deploy to GitHub Pages
71-
id: deployment
72-
uses: actions/deploy-pages@v1
48+
if: github.ref == 'refs/heads/main'
49+
uses: peaceiris/actions-gh-pages@v3
50+
with:
51+
github_token: ${{ secrets.GITHUB_TOKEN }}
52+
publish_dir: ./dist

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.17.0

cypress.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { defineConfig } from 'cypress';
22

33
export default defineConfig({
44
e2e: {
5-
baseUrl: 'http://localhost:5173',
5+
baseUrl: process.env.CYPRESS_BASE_URL || 'http://localhost:5173',
66
supportFile: false,
7+
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}'
78
},
89
component: {
910
devServer: {

cypress/e2e/home.cy.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
describe('Home Page', () => {
2+
beforeEach(() => {
3+
cy.visit('/')
4+
})
5+
6+
it('displays the correct heading', () => {
7+
cy.get('h1')
8+
.should('exist')
9+
.and('contain.text', 'A/B Test Calculator')
10+
})
11+
})

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"preview": "vite preview",
1111
"test": "cypress run",
1212
"test:open": "cypress open",
13+
"test:e2e": "cypress run --e2e",
14+
"test:e2e:open": "cypress open --e2e",
1315
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
1416
"type-check": "tsc --noEmit"
1517
},

tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@
55
"lib": ["ES2020", "DOM", "DOM.Iterable"],
66
"module": "ESNext",
77
"skipLibCheck": true,
8+
9+
/* Bundler mode */
810
"moduleResolution": "bundler",
911
"allowImportingTsExtensions": true,
1012
"resolveJsonModule": true,
1113
"isolatedModules": true,
1214
"noEmit": true,
1315
"jsx": "react-jsx",
16+
17+
/* Linting */
1418
"strict": true,
1519
"noUnusedLocals": true,
1620
"noUnusedParameters": true,
17-
"noFallthrough": true,
21+
"noImplicitReturns": true,
22+
"noImplicitAny": true,
23+
"noImplicitThis": true,
24+
"strictNullChecks": true,
1825
"baseUrl": ".",
1926
"paths": {
2027
"@/*": ["src/*"]

0 commit comments

Comments
 (0)