diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a30f45ef..c12bf417 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,6 +59,8 @@ $ npm run db:studio > **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. + ## SAML Accounts to use in Dev Our IDP is configured with a few accounts that exist for testing, the usernames and passwords to use are as follows: diff --git a/config/01-databases.sql b/config/01-databases.sql new file mode 100644 index 00000000..7b248e21 --- /dev/null +++ b/config/01-databases.sql @@ -0,0 +1,6 @@ +-- create test databases +CREATE DATABASE IF NOT EXISTS `starchart_test`; + +-- create root user and grant rights +CREATE USER 'root'@'localhost' IDENTIFIED BY 'root_password'; +GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'; diff --git a/docker-compose.yml b/docker-compose.yml index 16adc209..28e04d65 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,8 @@ services: volumes: # Persist data to ./mysql-data. Remove if you want to clear the db. - ./mysql-data:/var/lib/mysql + # Locate SQL file to setup test database + - ./config/01-databases.sql:/docker-entrypoint-initdb.d/init/01-databases.sql environment: MYSQL_DATABASE: starchart MYSQL_USER: starchart diff --git a/package.json b/package.json index 666de185..be744016 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,10 @@ "setup": "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 NODE_OPTIONS=--require=dotenv/config vitest", - "test:e2e:dev": "cross-env PORT=8080 start-server-and-test dev http://localhost:8080 \"playwright test\"", + "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", + "test:e2e:dev": "cross-env PORT=8080 DATABASE_URL='mysql://root:root_password@127.0.0.1:3306/starchart_test' start-server-and-test dev http://localhost:8080 \"playwright test\"", "pretest:e2e:run": "cross-env NODE_ENV=test SECRETS_OVERRIDE=1 run-s build", - "test:e2e:run": "cross-env SECRETS_OVERRIDE=1 PORT=8080 start-server-and-test start:e2e http://localhost:8080 \"playwright test\"", + "test:e2e:run": "cross-env SECRETS_OVERRIDE=1 PORT=8080 DATABASE_URL='mysql://root:root_password@127.0.0.1:3306/starchart_test' start-server-and-test start:e2e http://localhost:8080 \"playwright test\"", "typecheck": "tsc", "validate": "run-p \"test -- --run\" lint typecheck test:e2e:run", "prepare": "husky install"