- Use
yarn
for package management
yarn install
- Setup
.env.local
per.env.local.example
yarn generate-client
yarn docker:dev
yarn migrate:dev
yarn migrate:data
- Go to
http://localhost:3000/
yarn docker:dev-stop
to stop containers
- Run
yarn migrate:dev --name '{{commit name here}}'
creates a migration file - Run
yarn generate-client
re-generate api client - Restart containers
- Add user in Auth0 Dashboard
- Run
yarn migrate:data
to sync auth0 user database with yourlocal
(orTST
)
- Will automatically generate when generating prisma client
- Disable generation with env variable
DISABLE_ERD=true
yarn prisma migrate reset
yarn migrate:data
(make sureAUTH0_TMP_API_TOKEN
is defined/fresh)
- Three different environments,
unit
,integration
,e2e
- Separate
.env.test
env file andtest-db
docker service - Make sure when setting up the test env files not to target your local db/any live dbs
- make sure to install playwright
npx playwright install
(should also install the browsers) - To test the whole app use run
yarn test:all
- To run only unit tests run
yarn test:unit
- Use the
--run
flag after to run once (default iswatch
mode)
- To run only integration tests run
yarn test:int
- To run in
watch
mode use the-w
flag - Note it skips the user migration with the
-t
flag (already defined in the npm script) but the test setup will add a dummy user - It will start a
test-db
container and run data migrations
- To run e2e tests run
yarn test:e2e
- With head (e.g. browsers popup) use the
-h
flag - To generate reports use the
-r
flag - Note: it is running 1 at a time (not parallel) because of the way nextauth/nextjs bugs out when multiple logins happen concurrently (hitting localhost)... will probably need to setup multiple test accounts or look into other solutions like saving authentication (which may still need multiple accounts)
- Debug tests with
npx playwright test {{test file}} --project={{specific browser if interested}} --debug
- ornpx playwright test --ui
- Resources: - https://playwright.dev/docs/debug#stepping-through-your-tests - https://playwright.dev/docs/running-tests
- https://github.com/nektos/act
- Workaround for
no space left on device
isdocker volume prune --force
Migrates static data and users from auth0 user database (if enabled)
- Use
-s
flag to skip options, comma-separated no space - The only option available right now is
users
- To add another option see how the
users
option is done in the script
e.g. yarn migrate:data -s users
Builds and runs a dummy test db in docker, runs integration tests via
vitest
and then tears it down when done
- Use the
-w
flag to enterwatch mode
Builds and runs a test-db in docker, runs e2e tests via
playwright
and then tears down when complete
- Use the
-h
option to turn on headed mode (see the browsers open) oryarn test:e2e:headed
Runs all unit, integration and e2e tests, basically runs the specific test commands sequentially
Loads envs into the shell and sets up the test database
- Useful to run separately for debugging tests
Example usage: Running the nextjs app with test envs and the test database
export NODE_ENV=true && yarn dev (run the nextjs app in test mode using .env.test envs)
bash ./scripts/setup_db.sh
pauses script
Auth0
managed with terraform (view read me in/terraform
for more info)- For now when making infrastructure changes, need to manually call
terraform plan
andterraform approve
to apply changes toTST
(maybe automate this later)
- Run
yarn migrate:create {{filename}}
(preferred filename format is{{category}}{{week}}
e.g.beginner1
for beginner week 1 )- This will create a new
.ts
file located inprisma/data-migrations
- Also appends the file run command to
migrate.sh
- Creates a
.ts
file inprisma/data-migrations/swim-programs
for you to add the swim program
- This will create a new
- Edit the swim program file to add one week e.g. (Week 1 of beginner program)
- Double-check the
.ts
file inprisma/data-migrations
- Test with
yarn migrate:data
and check the UI on your local (may need to runexport DATABASE_URL={{URL HERE}}
beforehand)
Testing: