Skip to content

Unit and Integration testing #255

Unit and Integration testing

Unit and Integration testing #255

Workflow file for this run

name: Unit and Integration testing
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: '0 3 * * *' # Runs nightly at 3 AM UTC
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Setup Chrome browser and ChromeDriver
uses: browser-actions/setup-chrome@latest
id: setup-chrome
with:
chrome-version: 'stable'
install-chromedriver: true
- name: Verify Chrome version
run: |
${{ steps.setup-chrome.outputs.chrome-path }} --version
- name: Symlink Chrome binary to default path
run: |
sudo ln -sf ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome
- name: Install dependencies
run: npm install
- name: Set up env vars
run: |
echo "AWS_ACCESS_KEY_ID=fakeMyKeyId" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=fakeSecretAccessKey" >> $GITHUB_ENV
echo "AWS_REGION=fakeRegion" >> $GITHUB_ENV
echo "AWS_DEFAULT_REGION=fakeRegion" >> $GITHUB_ENV
echo "DYNAMODB_ENDPOINT=http://127.0.0.1:8000" >> $GITHUB_ENV
echo "DYNAMODB_TABLE_NAME=RoomsTest" >> $GITHUB_ENV
# IMPORTANT: Make sure this matches the port your Express app uses
echo "BASE_URL=http://localhost:8081" >> $GITHUB_ENV
echo "HOTEL_NAME=AWS App Runner Hotel" >> $GITHUB_ENV
echo "CI=true" >> $GITHUB_ENV
- name: Start DynamoDB Local
run: docker run -d -p 8000:8000 amazon/dynamodb-local
- name: Wait for DynamoDB to become ready
run: |
until aws dynamodb list-tables --endpoint-url http://127.0.0.1:8000; do
echo "Waiting for local DynamoDB..."
sleep 1
done
- name: Create Rooms table for testing
run: node test/integration-tests/scripts/create-local-table.js
- name: Start server
run: |
npm start &
# Give the server a few seconds to spin up before running tests
sleep 5
- name: Run unit tests
run: npm run unit-test
- name: Run integration tests
env:
CHROME_BIN: /opt/hostedtoolcache/setup-chrome/chromium/stable/x64/chrome
run: npm run integration-tests