Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts for test database setup #398

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
ports:
- 3306:3306
env:
MYSQL_DATABASE: starchart
MYSQL_DATABASE: starchart_test
MYSQL_USER: starchart
MYSQL_PASSWORD: starchart_password
MYSQL_ROOT_PASSWORD: root_password
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
- name: Seed database
run: |
cp .env.example .env
npm run setup
npm run setup:test

- name: Run tests
run: npm test
Expand All @@ -133,7 +133,7 @@ jobs:
ports:
- 3306:3306
env:
MYSQL_DATABASE: starchart
MYSQL_DATABASE: starchart_test
MYSQL_USER: starchart
MYSQL_PASSWORD: starchart_password
MYSQL_ROOT_PASSWORD: root_password
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
- name: Seed database
run: |
cp .env.example .env
npm run setup
npm run setup:test

- name: Run Playwright tests
run: npm run test:e2e:run
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ $ npm install
# Setup the database
$ npm run setup

# (Optional) Setup test database
$ npm run setup:test

# Generate a build folder the first time running the app
$ npm run build

Expand All @@ -55,13 +58,16 @@ $ npm run dev

# Visually see the database in a GUI:
$ npm run db:studio

# Visually see the test database in a GUI
$ npm run db:studio:test
```

> **Note** `npm run setup` creates a local `mysql-data/` directory, and is a one time setup. That directory can be safely deleted if the database needs to be reset, or if errors occur during database startup.

> **Note** `npm run build` needs to be executed the first time running the project. As it generates a `build/server.js` script that `npm run dev` depends on. Subsequent times, only `npm run dev` is needed to run the app in development mode.

> **Note** If you are running test scripts for the first time, change `DATABASE_URL` in `.env` to `DATABASE_URL="mysql://starchart:[email protected]:3306/starchart"` and run `npm run setup` to setup the test database. You can change this back afterward.
> **Note** `npm run setup:test` is required for running tests locally

## SAML Accounts to use in Dev

Expand Down
2 changes: 1 addition & 1 deletion app/db.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getClient() {
process.env.NODE_ENV === 'production'
? secrets.DATABASE_URL
: // Allow using env or secrets in dev/testing only
secrets.DATABASE_URL || process.env.DATABASE_URL;
process.env.DATABASE_URL || secrets.DATABASE_URL;

if (typeof DATABASE_URL !== 'string') {
throw new Error('DATABASE_URL secret not set');
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"db:reset": "prisma migrate reset",
"db:format": "prisma format",
"db:studio": "prisma studio",
"db:studio:test": "cross-env DATABASE_URL='mysql://root:[email protected]:3306/starchart_test' prisma studio",
"setup": "run-s db:generate db:push db:seed",
"setup:test": "cross-env DATABASE_URL='mysql://root:[email protected]:3306/starchart_test' run-s db:generate db:push db:seed",
"start": "cross-env NODE_ENV=production node ./build/server.js",
"start:e2e": "cross-env NODE_ENV=test node --require dotenv/config ./build/server.js",
"test": "cross-env SECRETS_OVERRIDE=1 DATABASE_URL='mysql://root:[email protected]:3306/starchart_test' NODE_OPTIONS=--require=dotenv/config vitest",
Expand Down