diff --git a/packages/adapter-drizzle/test/mysql-multi-project-schema/test.sh b/packages/adapter-drizzle/test/mysql-multi-project-schema/test.sh index 6785032f94..7f1e5aa78e 100755 --- a/packages/adapter-drizzle/test/mysql-multi-project-schema/test.sh +++ b/packages/adapter-drizzle/test/mysql-multi-project-schema/test.sh @@ -18,7 +18,6 @@ echo "Waiting 10s for db to start..." && sleep 10 # Push schema and seed drizzle-kit generate:mysql --config=./test/mysql-multi-project-schema/drizzle.config.ts -NODE_OPTIONS='--import tsx' tsx ./test/mysql-multi-project-schema/migrator.ts if vitest run -c ../utils/vitest.config.ts ./test/mysql-multi-project-schema/index.test.ts; then diff --git a/packages/adapter-drizzle/test/pg-multi-project-schema/test.sh b/packages/adapter-drizzle/test/pg-multi-project-schema/test.sh index 08689093fe..66acddac31 100755 --- a/packages/adapter-drizzle/test/pg-multi-project-schema/test.sh +++ b/packages/adapter-drizzle/test/pg-multi-project-schema/test.sh @@ -21,7 +21,6 @@ echo "Waiting 5s for db to start..." && sleep 5 # Push schema and seed drizzle-kit generate:pg --config=./test/pg-multi-project-schema/drizzle.config.ts -NODE_OPTIONS='--import tsx' tsx ./test/pg-multi-project-schema/migrator.ts if vitest run -c ../utils/vitest.config.ts ./test/pg-multi-project-schema/index.test.ts; then diff --git a/packages/adapter-drizzle/test/pg/test.sh b/packages/adapter-drizzle/test/pg/test.sh index 3c46a8f0fd..72441cf233 100755 --- a/packages/adapter-drizzle/test/pg/test.sh +++ b/packages/adapter-drizzle/test/pg/test.sh @@ -21,7 +21,6 @@ echo "Waiting 5s for db to start..." && sleep 5 # Push schema and seed drizzle-kit generate:pg --config=./test/pg/drizzle.config.ts -NODE_OPTIONS='--import tsx' tsx ./test/pg/migrator.ts if vitest run -c ../utils/vitest.config.ts ./test/pg/index.test.ts; then diff --git a/packages/adapter-drizzle/test/sqlite/test.sh b/packages/adapter-drizzle/test/sqlite/test.sh index acea7dcbab..3959b2e94d 100755 --- a/packages/adapter-drizzle/test/sqlite/test.sh +++ b/packages/adapter-drizzle/test/sqlite/test.sh @@ -7,11 +7,8 @@ echo "Running SQLite tests." rm -f db.sqlite drizzle-kit generate:sqlite --config=./test/sqlite/drizzle.config.ts -NODE_OPTIONS='--import tsx' tsx ./test/sqlite/migrator.ts -vitest run -c ../utils/vitest.config.ts ./test/sqlite/index.test.ts - if vitest run -c ../utils/vitest.config.ts ./test/sqlite/index.test.ts; then rm -f db.sqlite else diff --git a/packages/adapter-typeorm/package.json b/packages/adapter-typeorm/package.json index fd2e743de8..3f30f66124 100644 --- a/packages/adapter-typeorm/package.json +++ b/packages/adapter-typeorm/package.json @@ -39,12 +39,10 @@ "build": "tsc", "dev": "tsc -w", "clean": "rm -rf dist", - "init:db": "test/init.sh", - "mysql": "pnpm init:db && test/mysql/test.sh", - "postgres": "pnpm init:db && test/postgresql/test.sh", - "sqlite": "test/sqlite/test.sh", - "test:containers": "test/test.sh", - "test": "test/test.sh" + "test": "pnpm test:mysql && pnpm test:sqlite && pnpm test:pg", + "test:mysql": "pnpm clean && ./test/mysql/test.sh", + "test:pg": "pnpm clean && ./test/postgresql/test.sh", + "test:sqlite": "pnpm clean && ./test/sqlite/test.sh" }, "dependencies": { "@auth/core": "workspace:*" diff --git a/packages/adapter-typeorm/test/init.sh b/packages/adapter-typeorm/test/init.sh deleted file mode 100755 index 430883d386..0000000000 --- a/packages/adapter-typeorm/test/init.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -# Init PostgreSQL container -echo "Initializing container for PostgreSQL tests" - -PGUSER=nextauth -PGDATABASE=nextauth -PG_CONTAINER_NAME=next-auth-postgres-test - -docker run -d --rm \ - -e POSTGRES_USER=${PGUSER} \ - -e POSTGRES_DB=${PGDATABASE} \ - -e POSTGRES_HOST_AUTH_METHOD=trust \ - --name "${PG_CONTAINER_NAME}" \ - -p 5432:5432 \ - postgres:13.3 - -# Init MyDQL container -echo "Initializing container for MySQL tests" - -MYSQL_DATABASE=next-auth -MYSQL_ROOT_PASSWORD=password -MYSQL_CONTAINER_NAME=next-auth-mysql-test - -docker run -d --rm \ - -e MYSQL_DATABASE=${MYSQL_DATABASE} \ - -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} \ - --name "${MYSQL_CONTAINER_NAME}" \ - -p 3306:3306 \ - mysql:8 --default-authentication-plugin=mysql_native_password diff --git a/packages/adapter-typeorm/test/mysql/test.sh b/packages/adapter-typeorm/test/mysql/test.sh index a052bd4dea..3257b9cefc 100755 --- a/packages/adapter-typeorm/test/mysql/test.sh +++ b/packages/adapter-typeorm/test/mysql/test.sh @@ -1,13 +1,39 @@ #!/usr/bin/env bash set -eu -echo "Waiting 5s for db to start..." -sleep 5 +# Init MySQL container +echo "Initializing container for MySQL tests" +MYSQL_DATABASE=next-auth +MYSQL_ROOT_PASSWORD=password +MYSQL_CONTAINER_NAME=next-auth-mysql-test + +function startDatabase { + docker run -d --rm \ + -e MYSQL_DATABASE=${MYSQL_DATABASE} \ + -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} \ + --name "${MYSQL_CONTAINER_NAME}" \ + -p 3306:3306 \ + mysql:8 --default-authentication-plugin=mysql_native_password + + echo "Waiting 5s for db to start..." + sleep 5 +} + +startDatabase echo "Started running MySQL tests with default models." -vitest run -c ../utils/vitest.config.ts mysql/index.test.ts +if vitest run -c ../utils/vitest.config.ts mysql/index.test.ts; then + docker stop ${MYSQL_CONTAINER_NAME} +else + docker stop ${MYSQL_CONTAINER_NAME} && exit 1 +fi echo "Finished running MySQL tests with default models." +startDatabase echo "Started running MySQL tests with custom models." -CUSTOM_MODEL=1 vitest run -c ../utils/vitest.config.ts mysql/index.custom.test.ts +if CUSTOM_MODEL=1 vitest run -c ../utils/vitest.config.ts mysql/index.custom.test.ts; then + docker stop ${MYSQL_CONTAINER_NAME} +else + docker stop ${MYSQL_CONTAINER_NAME} && exit 1 +fi echo "Finished running MySQL tests with custom models." diff --git a/packages/adapter-typeorm/test/postgresql/test.sh b/packages/adapter-typeorm/test/postgresql/test.sh index 8f34a3236a..9368fb55e6 100755 --- a/packages/adapter-typeorm/test/postgresql/test.sh +++ b/packages/adapter-typeorm/test/postgresql/test.sh @@ -1,13 +1,40 @@ #!/usr/bin/env bash set -eu -echo "Waiting 5s for db to start..." -sleep 5 +# Init PostgreSQL container +echo "Initializing container for PostgreSQL tests" +PGUSER=nextauth +PGDATABASE=nextauth +PG_CONTAINER_NAME=next-auth-postgres-test + +function startDatabase { + docker run -d --rm \ + -e POSTGRES_USER=${PGUSER} \ + -e POSTGRES_DB=${PGDATABASE} \ + -e POSTGRES_HOST_AUTH_METHOD=trust \ + --name "${PG_CONTAINER_NAME}" \ + -p 5432:5432 \ + postgres:13.3 + + echo "Waiting 5s for db to start..." + sleep 5 +} + +startDatabase echo "Started running PostgreSQL tests with default models." -vitest run -c ../utils/vitest.config.ts postgresql/index.test.ts +if vitest run -c ../utils/vitest.config.ts postgresql/index.test.ts; then + docker stop ${PG_CONTAINER_NAME} +else + docker stop ${PG_CONTAINER_NAME} && exit 1 +fi echo "Finished running PostgreSQL tests with default models." +startDatabase echo "Started running PostgreSQL tests with custom models." -CUSTOM_MODEL=1 vitest run -c ../utils/vitest.config.ts postgresql/index.custom.test.ts +if CUSTOM_MODEL=1 vitest run -c ../utils/vitest.config.ts postgresql/index.custom.test.ts; then + docker stop ${PG_CONTAINER_NAME} +else + docker stop ${PG_CONTAINER_NAME} && exit 1 +fi echo "Finished running PostgreSQL tests with custom models." diff --git a/packages/adapter-typeorm/test/sqlite/test.sh b/packages/adapter-typeorm/test/sqlite/test.sh index 8ffbf3f5b1..8c8f1f7bf5 100755 --- a/packages/adapter-typeorm/test/sqlite/test.sh +++ b/packages/adapter-typeorm/test/sqlite/test.sh @@ -4,11 +4,21 @@ set -eu rm -f test/sqlite/dev.db echo "Started running SQLite tests with default models." -vitest run -c ../utils/vitest.config.ts sqlite/index.test.ts +if vitest run -c ../utils/vitest.config.ts sqlite/index.test.ts; then + rm -f db.sqlite +else + rm -f db.sqlite && exit 1 +fi echo "Finished running SQLite tests with default models." rm -f test/sqlite/dev.db echo "Started running SQLite tests with custom models." -CUSTOM_MODEL=1 vitest run -c ../utils/vitest.config.ts sqlite/index.custom.test.ts +if CUSTOM_MODEL=1 vitest run -c ../utils/vitest.config.ts sqlite/index.custom.test.ts; then + rm -f db.sqlite +else + rm -f db.sqlite && exit 1 +fi echo "Finished running SQLite tests with custom models." + +rm -f test/sqlite/dev.db diff --git a/packages/adapter-typeorm/test/test.sh b/packages/adapter-typeorm/test/test.sh deleted file mode 100755 index 96a6737e49..0000000000 --- a/packages/adapter-typeorm/test/test.sh +++ /dev/null @@ -1,35 +0,0 @@ -#! /usr/bin/env bash -# -# Run parallel commands and fail if any of them fails. -# shellcheck disable=SC2046 -# Based on: https://gist.github.com/mjambon/79adfc5cf6b11252e78b75df50793f24#gistcomment-3861511 - -set -eu - -pids=() - -./test/init.sh - -./test/sqlite/test.sh & pids+=($!) - -./test/postgresql/test.sh & pids+=($!) - -./test/mysql/test.sh & pids+=($!) - -for _ in "${pids[@]}"; do - if wait -n; then - : - else - status=$? - echo "One of the subprocesses exited with nonzero status $status. Aborting." - for pid in "${pids[@]}"; do - # Send a termination signal to all the children, and ignore errors - # due to children that no longer exist. - kill "$pid" 2> /dev/null || : - done - docker kill $(docker ps -q) - exit "$status" - fi -done - -docker kill $(docker ps -q)