From e079f7046dd219e81e281b5319ff2070f1761146 Mon Sep 17 00:00:00 2001 From: Eakampreet Date: Mon, 20 Mar 2023 20:15:49 -0400 Subject: [PATCH 1/4] Give higher priority to DATABASE_URL value in process.env --- app/db.server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/db.server.ts b/app/db.server.ts index 4c86dbd0..8ed534d1 100644 --- a/app/db.server.ts +++ b/app/db.server.ts @@ -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'); From 827cc0ad5978f34821ce5484ec2b948ebdb4a315 Mon Sep 17 00:00:00 2001 From: Eakampreet Date: Mon, 20 Mar 2023 20:16:17 -0400 Subject: [PATCH 2/4] Add test script for setup and db studio --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 7cc73833..dd5e178c 100644 --- a/package.json +++ b/package.json @@ -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:root_password@127.0.0.1:3306/starchart_test' prisma studio", "setup": "run-s db:generate db:push db:seed", + "setup:test": "cross-env DATABASE_URL='mysql://root:root_password@127.0.0.1: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:root_password@127.0.0.1:3306/starchart_test' NODE_OPTIONS=--require=dotenv/config vitest", From 8c076f477576d44c68b0d47c2e9cf235b3a4112d Mon Sep 17 00:00:00 2001 From: Eakam Date: Mon, 20 Mar 2023 20:24:01 -0400 Subject: [PATCH 3/4] Add test database setup info --- CONTRIBUTING.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0d6e57d..d9af79fa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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:starchart_password@127.0.0.1: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 From fc21ec7264ce942cb9aa809ac98421e15fc13f4c Mon Sep 17 00:00:00 2001 From: Eakampreet Date: Mon, 20 Mar 2023 20:40:54 -0400 Subject: [PATCH 4/4] Update ci workflow to use test database --- .github/workflows/ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3143d183..cf70ea28 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 @@ -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 @@ -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 @@ -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