Skip to content

Commit

Permalink
Merge pull request #124 from Windesheim-AI-App/task/update-tests-in-cicd
Browse files Browse the repository at this point in the history
chore: 🚧 Optimize E2E tests in CI/CD
  • Loading branch information
KoenvanMeijeren authored Nov 27, 2023
2 parents 8e715e3 + 6047d8b commit 3661637
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ instrument/
*.md
package-lock.json

./fonts.js
fonts.js
9 changes: 9 additions & 0 deletions .github/cleanup-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: cleanup-action
description: test action
runs:
using: 'composite'
steps:
- name: 'Remove env file'
shell: bash
run: |
rm .env
37 changes: 37 additions & 0 deletions .github/prepare-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: prepare-action
description: Prepare build

inputs:
openai-api-key:
description: 'The OpenAI API key'
required: true
app-debug:
description: 'If the debug mode is enabled'
required: true
wp-username:
description: 'The WordPress username'
required: true
wp-password:
description: 'The WordPress password'
required: true

runs:
using: 'composite'
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: 'Create & configure env file'
shell: bash
run: |
touch .env
echo OPENAI_API_KEY=${{ inputs.openai-api-key }} >> .env
echo APP_DEBUG=${{ inputs.app-debug }} >> .env
echo AI_ENABLED="false" >> .env
echo WP_CONTENT_URL="https://www.windesheim.tech" >> .env
echo WP_DATA_URL="https://www.windesheim.ai" >> .env
echo WP_USERNAME=${{ inputs.wp-username }} >> .env
echo WP_PASSWORD=${{ inputs.wp-password }} >> .env
cat .env
65 changes: 8 additions & 57 deletions .github/workflows/app.build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & test
name: Build

on:
push:
Expand All @@ -20,24 +20,14 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
- uses: ./.github/prepare-action
with:
node-version: ${{ matrix.node-version }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
app-debug: false
wp-username: ${{ secrets.WP_USERNAME }}
wp-password: ${{ secrets.WP_PASSWORD }}

- name: 'Create & configure env file'
run: |
touch .env
echo OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} >> .env
echo APP_DEBUG="false" >> .env
echo AI_ENABLED="false" >> .env
echo WP_CONTENT_URL="https://www.windesheim.tech" >> .env
echo WP_DATA_URL="https://www.windesheim.ai" >> .env
echo WP_USERNAME=${{ secrets.WP_USERNAME }} >> .env
echo WP_PASSWORD=${{ secrets.WP_PASSWORD }} >> .env
cat .env
- name: Install dependencies
- name: Install NPM dependencies
run: npm install

- name: Run ESLint
Expand All @@ -52,43 +42,4 @@ jobs:
- name: Run Unit & Component tests
run: npm run test:jest-less-strict

- name: 'Remove env file'
run: |
rm .env
end-to-end-testing:
runs-on: self-hosted
needs: build
strategy:
matrix:
test-platform: [firefox]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: 'Create & configure env file'
run: |
touch .env
echo OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} >> .env
echo APP_DEBUG="false" >> .env
echo AI_ENABLED="false" >> .env
echo WP_CONTENT_URL="https://www.windesheim.tech" >> .env
echo WP_DATA_URL="https://www.windesheim.ai" >> .env
echo WP_USERNAME=${{ secrets.WP_USERNAME }} >> .env
echo WP_PASSWORD=${{ secrets.WP_PASSWORD }} >> .env
cat .env
- name: Cypress run
uses: cypress-io/github-action@v6
with:
start: npm run web
browser: ${{ matrix.test-platform }}

- name: 'Remove env file'
run: |
rm .env
- uses: ./.github/cleanup-action
36 changes: 36 additions & 0 deletions .github/workflows/app.e2e_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: End to end tests

on:
push:
branches:
- main
- development
pull_request:
branches:
- main
- development

jobs:
tests:
runs-on: self-hosted
strategy:
matrix:
test-platform: [firefox, electron]
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: ./.github/prepare-action
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
app-debug: false
wp-username: ${{ secrets.WP_USERNAME }}
wp-password: ${{ secrets.WP_PASSWORD }}

- name: Cypress run
uses: cypress-io/github-action@v6
with:
start: npm run web
browser: ${{ matrix.test-platform }}

- uses: ./.github/cleanup-action
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ coverage-jest/
.nyc_output/
instrumented/
*.snap
.eslintcache

%ProgramData%/**/.*
/%ProgramData%/Microsoft/Windows/UUS/State/_active.uusver
Expand Down
4 changes: 1 addition & 3 deletions cypress/e2e/0.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
describe('wait for server', () => {
it('waits for server', () => {
// Wait for the server to start up
cy.wait(30_000);
it('waits for server', { retries: 3 }, () => {
cy.visit('/');
});
});
82 changes: 44 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"web": "expo start --web",
"eject": "expo eject",
"cypress": "cypress open",
"lint": "echo \"Running eslint check\" && eslint . --max-warnings=0",
"expo:fix": "npx expo install --fix",
"lint": "echo \"Running eslint check\" && eslint . --max-warnings=0 --cache **/*.ts",
"test:eslint": "npm run lint",
"lint:fix": "echo \"Running eslint check\" && eslint . --fix --max-warnings=0",
"lint:fix": "echo \"Running eslint check\" && eslint . --fix --max-warnings=0 --cache **/*.ts",
"test:eslint-fix": "npm run lint-fix",
"prettier": "echo \"Running prettier check\" && prettier . --check",
"test:prettier": "npm run prettier",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.lint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"app.config.ts",
"metro.config.js"
],
"exclude": ["cypress/*"]
"exclude": ["cypress/*", "node_modules/*"]
}

0 comments on commit 3661637

Please sign in to comment.