diff --git a/.github/actions/prepare-test-env/action.yml b/.github/actions/prepare-test-env/action.yml deleted file mode 100644 index 5a674a134b..0000000000 --- a/.github/actions/prepare-test-env/action.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Prepare Test Env -description: Prepare the test environment - -runs: - using: 'composite' - steps: - - name: Prepare - uses: ./.github/actions/prepare - - # See https://github.com/pnpm/pnpm/issues/6300 - - name: Disable peer deduplication - shell: bash - run: pnpm config --location=project set dedupe-peer-dependents=false - - - name: Reinstall production dependencies only - shell: bash - run: pnpm install --prod - - - name: Reinstall dev dependencies in workspace root - shell: bash - run: pnpm install --workspace-root --dev diff --git a/.github/actions/prepare/action.yml b/.github/actions/prepare/action.yml index f74d05bb71..c9ae8889ab 100644 --- a/.github/actions/prepare/action.yml +++ b/.github/actions/prepare/action.yml @@ -45,6 +45,7 @@ runs: - name: Build if: inputs.build == 'true' shell: bash - run: pnpm run -r --workspace-concurrency=1 build + run: pnpm run build env: + npm_config_workspace_concurrency: '1' NODE_OPTIONS: --max_old_space_size=6144 diff --git a/.github/workflows/blackbox-main.yml b/.github/workflows/blackbox-main.yml index c1e4c3606f..923289ebea 100644 --- a/.github/workflows/blackbox-main.yml +++ b/.github/workflows/blackbox-main.yml @@ -6,7 +6,7 @@ on: - main paths: - api/** - - tests-blackbox/** + - tests/blackbox/** - packages/** - package.json - pnpm-lock.yaml @@ -40,8 +40,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Prepare test env - uses: ./.github/actions/prepare-test-env + - name: Prepare + uses: ./.github/actions/prepare - name: Install Oracle client if: matrix.vendor == 'oracle' @@ -56,13 +56,13 @@ jobs: - name: Start services (SQLite) if: matrix.vendor == 'sqlite3' run: - docker compose -f tests-blackbox/docker-compose.yml up auth-saml redis minio minio-mc -d --quiet-pull --wait + docker compose -f tests/blackbox/docker-compose.yml up auth-saml redis minio minio-mc -d --quiet-pull --wait - name: Start services (other vendors) if: matrix.vendor != 'sqlite3' run: - docker compose -f tests-blackbox/docker-compose.yml up ${{ matrix.vendor }} auth-saml redis minio minio-mc -d + docker compose -f tests/blackbox/docker-compose.yml up ${{ matrix.vendor }} auth-saml redis minio minio-mc -d --quiet-pull --wait - name: Run tests - run: TEST_DB=${{ matrix.vendor }} pnpm run -w test:blackbox + run: TEST_DB=${{ matrix.vendor }} pnpm run test:blackbox diff --git a/.github/workflows/blackbox-pr.yml b/.github/workflows/blackbox-pr.yml index a1f7151ef7..098ce456eb 100644 --- a/.github/workflows/blackbox-pr.yml +++ b/.github/workflows/blackbox-pr.yml @@ -6,7 +6,7 @@ on: - main paths: - api/** - - tests-blackbox/** + - tests/blackbox/** - packages/** - package.json - pnpm-lock.yaml @@ -27,12 +27,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Prepare test env - uses: ./.github/actions/prepare-test-env + - name: Prepare + uses: ./.github/actions/prepare - name: Start services run: - docker compose -f tests-blackbox/docker-compose.yml up auth-saml redis minio minio-mc -d --quiet-pull --wait + docker compose -f tests/blackbox/docker-compose.yml up auth-saml redis minio minio-mc -d --quiet-pull --wait - name: Run tests - run: TEST_DB=sqlite3 pnpm run -w test:blackbox + run: TEST_DB=sqlite3 pnpm run test:blackbox diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4e0ac71c8c..b630c3e780 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -44,7 +44,7 @@ jobs: uses: ./.github/actions/prepare - name: Run Tests - run: pnpm -r test + run: pnpm test analyze: name: CodeQL Analysis diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ba3e832ea8..58fb8777c7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,7 +37,7 @@ jobs: - name: Publish packages to NPM env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: pnpm -r publish --access=public --no-git-checks + run: pnpm --recursive publish --access=public --no-git-checks build-images: name: Build Images diff --git a/.gitignore b/.gitignore index c937207c0d..618dbbfc4b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ storybook-static coverage *.tsbuildinfo **/.vitepress/cache +**/.vitepress/.temp .thumbsmith # Dotenv configs @@ -20,7 +21,6 @@ coverage npm-debug.log debug .clinic -/tests-blackbox/server-log-* # IDEs / Editors .vscode @@ -37,10 +37,11 @@ debug # Temporary files TODO -# Directus data +# Directus /schema.yaml /schema.json -/uploads /api/uploads /api/extensions +/tests/blackbox/uploads +/tests/blackbox/server-log-* *.db diff --git a/api/package.json b/api/package.json index df9ded3232..b4a2b1d250 100644 --- a/api/package.json +++ b/api/package.json @@ -69,9 +69,7 @@ "cli": "NODE_ENV=development SERVE_APP=false tsx src/cli/run.ts", "dev": "NODE_ENV=development SERVE_APP=false tsx watch --clear-screen=false src/start.ts", "start": "node cli.js start", - "test": "vitest run", - "test:coverage": "vitest run --coverage", - "test:watch": "vitest" + "test": "vitest --watch=false" }, "dependencies": { "@authenio/samlify-node-xmllint": "2.0.0", @@ -207,6 +205,7 @@ "@types/sanitize-html": "2.9.0", "@types/sharp": "0.31.1", "@types/stream-json": "1.7.3", + "@types/supertest": "2.0.12", "@types/uuid": "9.0.1", "@types/uuid-validate": "0.0.1", "@types/wellknown": "0.5.4", @@ -214,6 +213,7 @@ "copyfiles": "2.4.1", "form-data": "4.0.0", "knex-mock-client": "2.0.0", + "supertest": "6.3.3", "typescript": "4.9.5", "vitest": "0.29.3" }, diff --git a/api/src/utils/merge-permissions.ts b/api/src/utils/merge-permissions.ts index b78554f9af..55a587590f 100644 --- a/api/src/utils/merge-permissions.ts +++ b/api/src/utils/merge-permissions.ts @@ -16,7 +16,11 @@ export function mergePermissions(strategy: 'and' | 'or', ...permissions: Permiss return Array.from(mergedPermissions); } -export function mergePermission(strategy: 'and' | 'or', currentPerm: Permission, newPerm: Permission) { +export function mergePermission( + strategy: 'and' | 'or', + currentPerm: Permission, + newPerm: Permission +): Omit { const logicalKey = `_${strategy}` as keyof LogicalFilterOR | keyof LogicalFilterAND; let permissions = currentPerm.permissions; diff --git a/app/package.json b/app/package.json index 61ea905e3d..da9f2713e2 100644 --- a/app/package.json +++ b/app/package.json @@ -24,9 +24,7 @@ "build-storybook": "storybook build", "dev": "vite --clearScreen false", "storybook": "storybook dev -p 6006", - "test": "vitest run", - "test:coverage": "vitest run --coverage", - "test:watch": "vitest" + "test": "vitest --watch=false" }, "devDependencies": { "@babel/core": "7.21.3", diff --git a/docs/package.json b/docs/package.json index 623eb8f13a..f64818f9d9 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,5 +1,5 @@ { - "name": "@directus/docs", + "name": "docs", "private": true, "main": "dist/index.js", "exports": { diff --git a/package.json b/package.json index 0558a06773..4e8096d8a7 100644 --- a/package.json +++ b/package.json @@ -1,51 +1,22 @@ { "name": "directus-monorepo", "private": true, - "workspaces": [ - "./app", - "./api", - "./packages/*" - ], "scripts": { + "build": "pnpm --recursive --filter '!docs' run build", "format": "prettier --write \"**/*.{md,y?(a)ml,json}\"", "lint": "eslint .", - "test:blackbox": "jest tests -c tests-blackbox/jest.config.js", - "test:blackbox:watch": "jest tests -c tests-blackbox/jest.config.js --watch", - "posttest:blackbox:watch": "ts-node --project ./tests-blackbox/tsconfig.json --transpile-only ./tests-blackbox/setup/teardown.ts" + "test": "pnpm --recursive --filter '!tests-blackbox' test", + "test:blackbox": "pnpm --filter directus deploy --prod dist && pnpm --filter tests-blackbox test" }, "devDependencies": { - "@directus/constants": "workspace:*", - "@directus/types": "workspace:*", - "@directus/utils": "workspace:*", - "@types/jest": "29.4.4", - "@types/js-yaml": "4.0.5", - "@types/lodash": "4.14.191", - "@types/seedrandom": "3.0.5", - "@types/supertest": "2.0.12", - "@types/uuid": "9.0.1", "@typescript-eslint/eslint-plugin": "5.55.0", "@typescript-eslint/parser": "5.55.0", - "autocannon": "7.10.0", - "axios": "1.3.4", "eslint": "8.36.0", "eslint-config-prettier": "8.7.0", "eslint-plugin-jest": "27.2.1", "eslint-plugin-prettier": "4.2.1", "eslint-plugin-vue": "9.9.0", - "globby": "11.1.0", - "jest": "29.5.0", - "jest-environment-node": "29.5.0", - "js-yaml": "4.1.0", - "json-to-graphql-query": "2.2.5", - "knex": "2.4.2", - "listr2": "5.0.8", - "lodash": "4.17.21", - "prettier": "2.8.4", - "seedrandom": "3.0.5", - "supertest": "6.3.3", - "ts-jest": "29.0.5", - "typescript": "4.9.5", - "uuid": "9.0.0" + "prettier": "2.8.4" }, "packageManager": "pnpm@8.1.0", "engines": { diff --git a/packages/composables/package.json b/packages/composables/package.json index 5764b7a417..d648cca0c2 100644 --- a/packages/composables/package.json +++ b/packages/composables/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Shared Vue composables for Directus use", "repository": { diff --git a/packages/exceptions/package.json b/packages/exceptions/package.json index 85f3be492a..2e722a5169 100644 --- a/packages/exceptions/package.json +++ b/packages/exceptions/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Shared exceptions in Directus", "repository": { diff --git a/packages/extensions-sdk/package.json b/packages/extensions-sdk/package.json index ca3823716c..075614dd9e 100644 --- a/packages/extensions-sdk/package.json +++ b/packages/extensions-sdk/package.json @@ -32,9 +32,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "dependencies": { "@directus/composables": "workspace:*", diff --git a/packages/schema/package.json b/packages/schema/package.json index 98bbd5b7ec..f2388c8ede 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -40,7 +40,7 @@ ], "scripts": { "build": "tsc --build", - "dev": "pnpm build -w --preserveWatchOutput --incremental" + "dev": "tsc --watch" }, "dependencies": { "knex": "2.4.2" diff --git a/packages/storage-driver-azure/package.json b/packages/storage-driver-azure/package.json index 202ec721a4..f0ba9bcd3b 100644 --- a/packages/storage-driver-azure/package.json +++ b/packages/storage-driver-azure/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Azure file storage abstraction for `@directus/storage`", "repository": { diff --git a/packages/storage-driver-cloudinary/package.json b/packages/storage-driver-cloudinary/package.json index a530d18c09..84db5d400f 100644 --- a/packages/storage-driver-cloudinary/package.json +++ b/packages/storage-driver-cloudinary/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Cloudinary file storage abstraction for `@directus/storage`", "repository": { diff --git a/packages/storage-driver-gcs/package.json b/packages/storage-driver-gcs/package.json index 9503699119..fa2a0181d6 100644 --- a/packages/storage-driver-gcs/package.json +++ b/packages/storage-driver-gcs/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "GCS file storage abstraction for `@directus/storage`", "repository": { diff --git a/packages/storage-driver-local/package.json b/packages/storage-driver-local/package.json index 5bf1731983..0cf716c39d 100644 --- a/packages/storage-driver-local/package.json +++ b/packages/storage-driver-local/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Local file storage abstraction for `@directus/storage`", "repository": { diff --git a/packages/storage-driver-s3/package.json b/packages/storage-driver-s3/package.json index 562d9d1bb8..a3a08438d9 100644 --- a/packages/storage-driver-s3/package.json +++ b/packages/storage-driver-s3/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "S3 file storage abstraction for `@directus/storage`", "repository": { diff --git a/packages/storage/package.json b/packages/storage/package.json index 05b05b66f8..770cb759e3 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Object storage abstraction layer for Directus", "repository": { diff --git a/packages/update-check/package.json b/packages/update-check/package.json index 2a42843d4c..47a14f1d93 100644 --- a/packages/update-check/package.json +++ b/packages/update-check/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --build", "dev": "tsc --watch", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Check if an update is available for a given package", "repository": { diff --git a/packages/utils/package.json b/packages/utils/package.json index 304447f850..9097311927 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -5,9 +5,7 @@ "scripts": { "build": "tsc --project browser/tsconfig.json && tsc --project node/tsconfig.json && tsc --project shared/tsconfig.json", "dev": "concurrently \"tsc --watch --project browser/tsconfig.json\" \"tsc --watch --project node/tsconfig.json\" \"tsc --watch --project shared/tsconfig.json\"", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage" + "test": "vitest --watch=false" }, "description": "Utilities shared between the Directus packages", "repository": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 290314dc87..85e4e7c669 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,45 +4,12 @@ importers: .: devDependencies: - '@directus/constants': - specifier: workspace:* - version: link:packages/constants - '@directus/types': - specifier: workspace:* - version: link:packages/types - '@directus/utils': - specifier: workspace:* - version: link:packages/utils - '@types/jest': - specifier: 29.4.4 - version: 29.4.4 - '@types/js-yaml': - specifier: 4.0.5 - version: 4.0.5 - '@types/lodash': - specifier: 4.14.191 - version: 4.14.191 - '@types/seedrandom': - specifier: 3.0.5 - version: 3.0.5 - '@types/supertest': - specifier: 2.0.12 - version: 2.0.12 - '@types/uuid': - specifier: 9.0.1 - version: 9.0.1 '@typescript-eslint/eslint-plugin': specifier: 5.55.0 version: 5.55.0(@typescript-eslint/parser@5.55.0)(eslint@8.36.0)(typescript@4.9.5) '@typescript-eslint/parser': specifier: 5.55.0 version: 5.55.0(eslint@8.36.0)(typescript@4.9.5) - autocannon: - specifier: 7.10.0 - version: 7.10.0 - axios: - specifier: 1.3.4 - version: 1.3.4 eslint: specifier: 8.36.0 version: 8.36.0 @@ -51,55 +18,16 @@ importers: version: 8.7.0(eslint@8.36.0) eslint-plugin-jest: specifier: 27.2.1 - version: 27.2.1(@typescript-eslint/eslint-plugin@5.55.0)(eslint@8.36.0)(jest@29.5.0)(typescript@4.9.5) + version: 27.2.1(@typescript-eslint/eslint-plugin@5.55.0)(eslint@8.36.0)(typescript@4.9.5) eslint-plugin-prettier: specifier: 4.2.1 version: 4.2.1(eslint-config-prettier@8.7.0)(eslint@8.36.0)(prettier@2.8.4) eslint-plugin-vue: specifier: 9.9.0 version: 9.9.0(eslint@8.36.0) - globby: - specifier: 11.1.0 - version: 11.1.0 - jest: - specifier: 29.5.0 - version: 29.5.0 - jest-environment-node: - specifier: 29.5.0 - version: 29.5.0 - js-yaml: - specifier: 4.1.0 - version: 4.1.0 - json-to-graphql-query: - specifier: 2.2.5 - version: 2.2.5 - knex: - specifier: 2.4.2 - version: 2.4.2(mysql@2.18.1)(pg@8.10.0)(sqlite3@5.1.6)(tedious@15.1.3) - listr2: - specifier: 5.0.8 - version: 5.0.8 - lodash: - specifier: 4.17.21 - version: 4.17.21 prettier: specifier: 2.8.4 version: 2.8.4 - seedrandom: - specifier: 3.0.5 - version: 3.0.5 - supertest: - specifier: 6.3.3 - version: 6.3.3 - ts-jest: - specifier: 29.0.5 - version: 29.0.5(@babel/core@7.21.3)(jest@29.5.0)(typescript@4.9.5) - typescript: - specifier: 4.9.5 - version: 4.9.5 - uuid: - specifier: 9.0.0 - version: 9.0.0 api: dependencies: @@ -403,7 +331,7 @@ importers: version: 2.18.1 nodemailer-mailgun-transport: specifier: 2.1.5 - version: 2.1.5(lodash@4.17.21) + version: 2.1.5 nodemailer-sendgrid: specifier: 1.0.3 version: 1.0.3 @@ -525,6 +453,9 @@ importers: '@types/stream-json': specifier: 1.7.3 version: 1.7.3 + '@types/supertest': + specifier: 2.0.12 + version: 2.0.12 '@types/uuid': specifier: 9.0.1 version: 9.0.1 @@ -546,6 +477,9 @@ importers: knex-mock-client: specifier: 2.0.0 version: 2.0.0(knex@2.4.2) + supertest: + specifier: 6.3.3 + version: 6.3.3 typescript: specifier: 4.9.5 version: 4.9.5 @@ -1407,6 +1341,75 @@ importers: specifier: 0.29.3 version: 0.29.3(happy-dom@8.9.0)(sass@1.59.3) + tests/blackbox: + devDependencies: + '@directus/types': + specifier: workspace:* + version: link:../../packages/types + '@types/jest': + specifier: 29.4.4 + version: 29.4.4 + '@types/js-yaml': + specifier: 4.0.5 + version: 4.0.5 + '@types/lodash': + specifier: 4.14.191 + version: 4.14.191 + '@types/seedrandom': + specifier: 3.0.5 + version: 3.0.5 + '@types/supertest': + specifier: 2.0.12 + version: 2.0.12 + '@types/uuid': + specifier: 9.0.1 + version: 9.0.1 + autocannon: + specifier: 7.10.0 + version: 7.10.0 + axios: + specifier: 1.3.4 + version: 1.3.4 + globby: + specifier: 11.1.0 + version: 11.1.0 + jest: + specifier: 29.5.0 + version: 29.5.0 + jest-environment-node: + specifier: 29.5.0 + version: 29.5.0 + js-yaml: + specifier: 4.1.0 + version: 4.1.0 + json-to-graphql-query: + specifier: 2.2.5 + version: 2.2.5 + knex: + specifier: 2.4.2 + version: 2.4.2 + listr2: + specifier: 5.0.8 + version: 5.0.8 + lodash: + specifier: 4.17.21 + version: 4.17.21 + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + supertest: + specifier: 6.3.3 + version: 6.3.3 + ts-jest: + specifier: 29.0.5 + version: 29.0.5(@babel/core@7.21.3)(jest@29.5.0)(typescript@4.9.5) + typescript: + specifier: 4.9.5 + version: 4.9.5 + uuid: + specifier: 9.0.0 + version: 9.0.0 + packages: /@algolia/autocomplete-core@1.7.4: @@ -4949,13 +4952,6 @@ packages: jest-mock: 29.5.0 dev: true - /@jest/expect-utils@29.4.2: - resolution: {integrity: sha512-Dd3ilDJpBnqa0GiPN7QrudVs0cczMMHtehSo2CSTjm3zdHx0RcpmhFNVEltuEFeqfLIyWKFI224FsMSQ/nsJQA==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - jest-get-type: 29.4.2 - dev: true - /@jest/expect-utils@29.5.0: resolution: {integrity: sha512-fmKzsidoXQT2KwnrwE0SQq3uj8Z763vzR8LnLBwC2qYWEFpjX8daRsk6rHUM1QvNlEW/UJXNXm59ztmJJWs2Mg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -5034,13 +5030,6 @@ packages: - supports-color dev: true - /@jest/schemas@29.4.2: - resolution: {integrity: sha512-ZrGzGfh31NtdVH8tn0mgJw4khQuNHiKqdzJAFbCaERbyCP9tHlxWuL/mnMu8P7e/+k4puWjI1NOzi/sFsjce/g==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - '@sinclair/typebox': 0.25.21 - dev: true - /@jest/schemas@29.4.3: resolution: {integrity: sha512-VLYKXQmtmuEz6IxJsrZwzG9NvtkQsWNnWMsKxqWNu3+CnfzJQhp0WDDKWLVV9hLKr0l3SLLFRqcYHjhtyuDVxg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -5100,18 +5089,6 @@ packages: - supports-color dev: true - /@jest/types@29.4.2: - resolution: {integrity: sha512-CKlngyGP0fwlgC1BRUtPZSiWLBhyS9dKwKmyGxk8Z6M82LBEGB2aLQSg+U1MyLsU+M7UjnlLllBM2BLWKVm/Uw==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - '@jest/schemas': 29.4.3 - '@types/istanbul-lib-coverage': 2.0.4 - '@types/istanbul-reports': 3.0.1 - '@types/node': 18.15.3 - '@types/yargs': 17.0.22 - chalk: 4.1.2 - dev: true - /@jest/types@29.5.0: resolution: {integrity: sha512-qbu7kN6czmVRc3xWFQcAN03RAUamgppVUdXrvl1Wr3jlNF93o9mJbGcDWrwGB6ht44u7efB1qCFgVQmca24Uog==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -7001,8 +6978,8 @@ packages: /@types/jest@29.4.4: resolution: {integrity: sha512-qezb65VIH7X1wobSnd6Lvdve7PXSyQRa3dljTkhTtDhi603RvHQCshSlJcuyMLHJpeHgY3NKwvDJWxMOOHxGDQ==} dependencies: - expect: 29.4.2 - pretty-format: 29.4.2 + expect: 29.5.0 + pretty-format: 29.5.0 dev: true /@types/js-yaml@4.0.5: @@ -9225,7 +9202,7 @@ packages: /console-control-strings@1.1.0: resolution: {integrity: sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==} - /consolidate@0.15.1(lodash@4.17.21): + /consolidate@0.15.1: resolution: {integrity: sha512-DW46nrsMJgy9kqAbPt5rKaCr7uFtpo4mSUvLHIUbJEjm0vo+aY5QLwBUq3FK4tRnJr/X0Psc0C4jf/h+HtXSMw==} engines: {node: '>= 0.10.0'} peerDependencies: @@ -9391,7 +9368,6 @@ packages: optional: true dependencies: bluebird: 3.7.2 - lodash: 4.17.21 dev: false optional: true @@ -9445,10 +9421,6 @@ packages: resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==} engines: {node: '>= 0.6'} - /cookiejar@2.1.3: - resolution: {integrity: sha512-JxbCBUdrfr6AQjOXrxoTvAMJO4HBTUIlBzslcJPAz+/KT8yk53fXun51u+RenNYvad/+Vc2DIz5o9UxlCDymFQ==} - dev: true - /cookiejar@2.1.4: resolution: {integrity: sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==} dev: true @@ -9904,11 +9876,6 @@ packages: resolution: {integrity: sha512-WDCaSzHMtayCIEa2hPq0rL8ds603SKNzMzNXU0kbLM7kzXoaXaKeHgPXJHKjKMxxnozKLMsg+rES7hC6Lxe7iA==} dev: true - /diff-sequences@29.4.2: - resolution: {integrity: sha512-R6P0Y6PrsH3n4hUXxL3nns0rbRk6Q33js3ygJBeEpbzLzgcNuJ61+u0RXasFpTKISw99TxUzFnumSnRLsjhLaw==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dev: true - /diff-sequences@29.4.3: resolution: {integrity: sha512-ofrBgwpPhCD85kMKtE9RYFFq6OC1A89oW2vvgWZNCwxrUpRUILopY7lsYyMDSjc8g6U6aiO0Qubg6r4Wgt5ZnA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -10338,7 +10305,7 @@ packages: eslint: 8.36.0 dev: true - /eslint-plugin-jest@27.2.1(@typescript-eslint/eslint-plugin@5.55.0)(eslint@8.36.0)(jest@29.5.0)(typescript@4.9.5): + /eslint-plugin-jest@27.2.1(@typescript-eslint/eslint-plugin@5.55.0)(eslint@8.36.0)(typescript@4.9.5): resolution: {integrity: sha512-l067Uxx7ZT8cO9NJuf+eJHvt6bqJyz2Z29wykyEdz/OtmcELQl2MQGQLX8J94O1cSJWAwUSEvCjwjA7KEK3Hmg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: @@ -10354,7 +10321,6 @@ packages: '@typescript-eslint/eslint-plugin': 5.55.0(@typescript-eslint/parser@5.55.0)(eslint@8.36.0)(typescript@4.9.5) '@typescript-eslint/utils': 5.50.0(eslint@8.36.0)(typescript@4.9.5) eslint: 8.36.0 - jest: 29.5.0 transitivePeerDependencies: - supports-color - typescript @@ -10602,17 +10568,6 @@ packages: engines: {node: '>=6'} dev: false - /expect@29.4.2: - resolution: {integrity: sha512-+JHYg9O3hd3RlICG90OPVjRkPBoiUH7PxvDVMnRiaq1g6JUgZStX514erMl0v2Dc5SkfVbm7ztqbd6qHHPn+mQ==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - '@jest/expect-utils': 29.4.2 - jest-get-type: 29.4.2 - jest-matcher-utils: 29.4.2 - jest-message-util: 29.4.2 - jest-util: 29.5.0 - dev: true - /expect@29.5.0: resolution: {integrity: sha512-yM7xqUrCO2JdpFo4XpM82t+PJBFybdqoQuJLDGeDX2ij8NZzqRHyu3Hp188/JX7SWqud+7t4MUdvcgGBICMHZg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -12329,16 +12284,6 @@ packages: - supports-color dev: true - /jest-diff@29.4.2: - resolution: {integrity: sha512-EK8DSajVtnjx9sa1BkjZq3mqChm2Cd8rIzdXkQMA8e0wuXq53ypz6s5o5V8HRZkoEt2ywJ3eeNWFKWeYr8HK4g==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - chalk: 4.1.2 - diff-sequences: 29.4.2 - jest-get-type: 29.4.3 - pretty-format: 29.5.0 - dev: true - /jest-diff@29.5.0: resolution: {integrity: sha512-LtxijLLZBduXnHSniy0WMdaHjmQnt3g5sa16W4p0HqukYTTsyTW3GD1q41TyGl5YFXj/5B2U6dlh5FM1LIMgxw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -12379,11 +12324,6 @@ packages: jest-util: 29.5.0 dev: true - /jest-get-type@29.4.2: - resolution: {integrity: sha512-vERN30V5i2N6lqlFu4ljdTqQAgrkTFMC9xaIIfOPYBw04pufjXRty5RuXBiB1d72tGbURa/UgoiHB90ruOSivg==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dev: true - /jest-get-type@29.4.3: resolution: {integrity: sha512-J5Xez4nRRMjk8emnTpWrlkyb9pfRQQanDrvWHhsR1+VUfbwxi30eVcZFlcdGInRibU4G5LwHXpI7IRHU0CY+gg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -12416,16 +12356,6 @@ packages: pretty-format: 29.5.0 dev: true - /jest-matcher-utils@29.4.2: - resolution: {integrity: sha512-EZaAQy2je6Uqkrm6frnxBIdaWtSYFoR8SVb2sNLAtldswlR/29JAgx+hy67llT3+hXBaLB0zAm5UfeqerioZyg==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - chalk: 4.1.2 - jest-diff: 29.4.2 - jest-get-type: 29.4.2 - pretty-format: 29.5.0 - dev: true - /jest-matcher-utils@29.5.0: resolution: {integrity: sha512-lecRtgm/rjIK0CQ7LPQwzCs2VwW6WAahA55YBuI+xqmhm7LAaxokSB8C97yJeYyT+HvQkH741StzpU41wohhWw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -12436,21 +12366,6 @@ packages: pretty-format: 29.5.0 dev: true - /jest-message-util@29.4.2: - resolution: {integrity: sha512-SElcuN4s6PNKpOEtTInjOAA8QvItu0iugkXqhYyguRvQoXapg5gN+9RQxLAkakChZA7Y26j6yUCsFWN+hlKD6g==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - '@babel/code-frame': 7.18.6 - '@jest/types': 29.5.0 - '@types/stack-utils': 2.0.1 - chalk: 4.1.2 - graceful-fs: 4.2.10 - micromatch: 4.0.5 - pretty-format: 29.5.0 - slash: 3.0.0 - stack-utils: 2.0.6 - dev: true - /jest-message-util@29.5.0: resolution: {integrity: sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -12513,7 +12428,7 @@ packages: jest-util: 29.5.0 jest-validate: 29.5.0 resolve: 1.22.1 - resolve.exports: 2.0.0 + resolve.exports: 2.0.2 slash: 3.0.0 dev: true @@ -12607,18 +12522,6 @@ packages: - supports-color dev: true - /jest-util@29.4.1: - resolution: {integrity: sha512-bQy9FPGxVutgpN4VRc0hk6w7Hx/m6L53QxpDreTZgJd9gfx/AV2MjyPde9tGyZRINAUrSv57p2inGBu2dRLmkQ==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - '@jest/types': 29.4.2 - '@types/node': 18.15.3 - chalk: 4.1.2 - ci-info: 3.7.1 - graceful-fs: 4.2.10 - picomatch: 2.3.1 - dev: true - /jest-util@29.5.0: resolution: {integrity: sha512-RYMgG/MTadOr5t8KdhejfvUU82MxsCu5MF6KuDUHl+NuwzUt+Sm6jJWxTJVrDR1j5M/gJVCPKQEpWXY+yIQ6lQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -13053,6 +12956,52 @@ packages: lodash.clonedeep: 4.5.0 dev: true + /knex@2.4.2: + resolution: {integrity: sha512-tMI1M7a+xwHhPxjbl/H9K1kHX+VncEYcvCx5K00M16bWvpYPKAZd6QrCu68PtHAdIZNQPWZn0GVhqVBEthGWCg==} + engines: {node: '>=12'} + hasBin: true + peerDependencies: + better-sqlite3: '*' + mysql: '*' + mysql2: '*' + pg: '*' + pg-native: '*' + sqlite3: '*' + tedious: '*' + peerDependenciesMeta: + better-sqlite3: + optional: true + mysql: + optional: true + mysql2: + optional: true + pg: + optional: true + pg-native: + optional: true + sqlite3: + optional: true + tedious: + optional: true + dependencies: + colorette: 2.0.19 + commander: 9.5.0 + debug: 4.3.4 + escalade: 3.1.1 + esm: 3.2.25 + get-package-type: 0.1.0 + getopts: 2.3.0 + interpret: 2.2.0 + lodash: 4.17.21 + pg-connection-string: 2.5.0 + rechoir: 0.8.0 + resolve-from: 5.0.0 + tarn: 3.0.2 + tildify: 2.0.0 + transitivePeerDependencies: + - supports-color + dev: true + /knex@2.4.2(mysql@2.18.1)(pg@8.10.0)(sqlite3@5.1.6)(tedious@15.1.3): resolution: {integrity: sha512-tMI1M7a+xwHhPxjbl/H9K1kHX+VncEYcvCx5K00M16bWvpYPKAZd6QrCu68PtHAdIZNQPWZn0GVhqVBEthGWCg==} engines: {node: '>=12'} @@ -14406,11 +14355,11 @@ packages: resolution: {integrity: sha512-71UV2HRUP+djvHpdyatiuv+Y1o8hI4ZI7bMfuuoACMLR1JJCErM4WXAclNeHd6BgHXkqeqnnAk3wpDkSQWmFXw==} dev: false - /nodemailer-mailgun-transport@2.1.5(lodash@4.17.21): + /nodemailer-mailgun-transport@2.1.5: resolution: {integrity: sha512-hF7POkaxFgMvYEd5aHLaQJI2511ld+aQlQi7JH6bGjhjlZ33cIbTB9PimlIrLu5XC3z76Kde6e65OIwL9lOdTA==} requiresBuild: true dependencies: - consolidate: 0.15.1(lodash@4.17.21) + consolidate: 0.15.1 form-data: 4.0.0 mailgun.js: 8.0.6 transitivePeerDependencies: @@ -15658,15 +15607,6 @@ packages: react-is: 17.0.2 dev: true - /pretty-format@29.4.2: - resolution: {integrity: sha512-qKlHR8yFVCbcEWba0H0TOC8dnLlO4vPlyEjRPw31FZ2Rupy9nLa8ZLbYny8gWEl8CkEhJqAE6IzdNELTBVcBEg==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - dependencies: - '@jest/schemas': 29.4.2 - ansi-styles: 5.2.0 - react-is: 18.2.0 - dev: true - /pretty-format@29.5.0: resolution: {integrity: sha512-V2mGkI31qdttvTFX7Mt4efOqHXqJWMu4/r66Xh3Z3BwZaPfPJgp6/gbwoujRpPUtfEF6AUUWx3Jim3GCw5g/Qw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -16413,8 +16353,8 @@ packages: protocol-buffers-schema: 3.6.0 dev: true - /resolve.exports@2.0.0: - resolution: {integrity: sha512-6K/gDlqgQscOlg9fSRpWstA8sYe8rbELsSTNpx+3kTrsVCzvSl0zIvRErM7fdl9ERWDsKnrLnwB+Ne89918XOg==} + /resolve.exports@2.0.2: + resolution: {integrity: sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg==} engines: {node: '>=10'} dev: true @@ -17491,7 +17431,7 @@ packages: deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) dependencies: component-emitter: 1.3.0 - cookiejar: 2.1.3 + cookiejar: 2.1.4 debug: 4.3.4 fast-safe-stringify: 2.1.1 form-data: 4.0.0 @@ -18016,7 +17956,7 @@ packages: bs-logger: 0.2.6 fast-json-stable-stringify: 2.1.0 jest: 29.5.0 - jest-util: 29.4.1 + jest-util: 29.5.0 json5: 2.2.3 lodash.memoize: 4.1.2 make-error: 1.3.6 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index b0c1856060..e6432fd1ce 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -3,3 +3,4 @@ packages: - api - docs - packages/* + - tests/* diff --git a/tests-blackbox/tsconfig.json b/tests-blackbox/tsconfig.json deleted file mode 100644 index 74a70b2977..0000000000 --- a/tests-blackbox/tsconfig.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "esModuleInterop": true, - "target": "ES2019", - "moduleResolution": "node", - "sourceMap": true, - "outDir": "dist", - "rootDir": "../", - "strict": true, - "lib": ["es2019"], - "skipLibCheck": true, - "declaration": true, - "resolveJsonModule": true, - "baseUrl": "./", - "paths": { - "@directus/cli/*": ["../packages/cli/src/*"], - "@directus/create-directus-project/*": ["../packages/create-directus-project/src/*"], - "@directus/storage/*": ["../packages/storage/src/*"], - "@directus/storage-driver-azure/*": ["../packages/storage-driver-azure/src/*"], - "@directus/storage-driver-local/*": ["../packages/storage-driver-local/src/*"], - "@directus/storage-driver-cloudinary/*": ["../packages/storage-driver-cloudinary/src/*"], - "@directus/storage-driver-gcs/*": ["../packages/storage-driver-gcs/src/*"], - "@directus/storage-driver-s3/*": ["../packages/storage-driver-s3/src/*"], - "@directus/extension-sdk/*": ["../packages/extension-sdk/src/*"], - "@directus/format-title/*": ["../packages/format-title/src/*"], - "@directus/gatsby-source-directus/*": ["../packages/gatsby-source-directus/src/*"], - "@directus/schema/*": ["../packages/schema/src/*"], - "@directus/sdk/*": ["../packages/sdk/src/*"], - "@directus/specs/*": ["../packages/specs/*"], - "@common/*": ["./common/*"], - "@query/*": ["./query/*"], - "@schema/*": ["./schema/*"], - "@utils/*": ["./utils/*"] - } - }, - "exclude": ["node_modules", "dist", "extensions"] -} diff --git a/tests-blackbox/assets/directus.png b/tests/blackbox/assets/directus.png similarity index 100% rename from tests-blackbox/assets/directus.png rename to tests/blackbox/assets/directus.png diff --git a/tests-blackbox/assets/layers.png b/tests/blackbox/assets/layers.png similarity index 100% rename from tests-blackbox/assets/layers.png rename to tests/blackbox/assets/layers.png diff --git a/tests-blackbox/common/common.seed.ts b/tests/blackbox/common/common.seed.ts similarity index 100% rename from tests-blackbox/common/common.seed.ts rename to tests/blackbox/common/common.seed.ts diff --git a/tests-blackbox/common/common.test.ts b/tests/blackbox/common/common.test.ts similarity index 100% rename from tests-blackbox/common/common.test.ts rename to tests/blackbox/common/common.test.ts diff --git a/tests-blackbox/common/config.ts b/tests/blackbox/common/config.ts similarity index 97% rename from tests-blackbox/common/config.ts rename to tests/blackbox/common/config.ts index efb111f3ae..54036d689e 100644 --- a/tests-blackbox/common/config.ts +++ b/tests/blackbox/common/config.ts @@ -1,4 +1,5 @@ import { Knex } from 'knex'; +import path from 'node:path'; import { promisify } from 'util'; import { allVendors } from './get-dbs-to-test'; @@ -11,8 +12,13 @@ export type Config = { envs: Env; }; -const migrationsDir = './tests-blackbox/setup/migrations'; -const seedsDir = './tests-blackbox/setup/seeds'; +export const paths = { + cli: path.join(__dirname, '..', '..', '..', 'dist', 'cli'), + cwd: path.join(__dirname, '..'), +}; + +const migrationsDir = './setup/migrations'; +const seedsDir = './setup/seeds'; const knexConfig = { waitTestSQL: 'SELECT 1', @@ -70,7 +76,7 @@ const directusConfig = { DB_EXCLUDE_TABLES: 'knex_migrations,knex_migrations_lock,spatial_ref_sys,sysdiagrams', MAX_RELATIONAL_DEPTH: '5', MAX_PAYLOAD_SIZE: '10mb', - EXTENSIONS_PATH: './tests-blackbox/extensions', + EXTENSIONS_PATH: './extensions', ASSETS_TRANSFORM_MAX_CONCURRENT: '2', MAX_BATCH_MUTATION: '100', // Must be in multiples of 10 for tests ACCESS_TOKEN_TTL: '25d', // should be larger than 24.86 days to test Expires value larger than 32-bit signed integer diff --git a/tests-blackbox/common/functions.ts b/tests/blackbox/common/functions.ts similarity index 100% rename from tests-blackbox/common/functions.ts rename to tests/blackbox/common/functions.ts diff --git a/tests-blackbox/common/get-dbs-to-test.ts b/tests/blackbox/common/get-dbs-to-test.ts similarity index 100% rename from tests-blackbox/common/get-dbs-to-test.ts rename to tests/blackbox/common/get-dbs-to-test.ts diff --git a/tests-blackbox/common/index.ts b/tests/blackbox/common/index.ts similarity index 100% rename from tests-blackbox/common/index.ts rename to tests/blackbox/common/index.ts diff --git a/tests-blackbox/common/seed-database.test.ts b/tests/blackbox/common/seed-database.test.ts similarity index 100% rename from tests-blackbox/common/seed-database.test.ts rename to tests/blackbox/common/seed-database.test.ts diff --git a/tests-blackbox/common/seed-functions.ts b/tests/blackbox/common/seed-functions.ts similarity index 100% rename from tests-blackbox/common/seed-functions.ts rename to tests/blackbox/common/seed-functions.ts diff --git a/tests-blackbox/common/test-logger.ts b/tests/blackbox/common/test-logger.ts similarity index 100% rename from tests-blackbox/common/test-logger.ts rename to tests/blackbox/common/test-logger.ts diff --git a/tests-blackbox/common/transport.ts b/tests/blackbox/common/transport.ts similarity index 100% rename from tests-blackbox/common/transport.ts rename to tests/blackbox/common/transport.ts diff --git a/tests-blackbox/common/types.ts b/tests/blackbox/common/types.ts similarity index 100% rename from tests-blackbox/common/types.ts rename to tests/blackbox/common/types.ts diff --git a/tests-blackbox/common/variables.ts b/tests/blackbox/common/variables.ts similarity index 100% rename from tests-blackbox/common/variables.ts rename to tests/blackbox/common/variables.ts diff --git a/tests-blackbox/docker-compose.yml b/tests/blackbox/docker-compose.yml similarity index 100% rename from tests-blackbox/docker-compose.yml rename to tests/blackbox/docker-compose.yml diff --git a/tests-blackbox/extensions/hooks/action-verify-create/index.js b/tests/blackbox/extensions/hooks/action-verify-create/index.js similarity index 100% rename from tests-blackbox/extensions/hooks/action-verify-create/index.js rename to tests/blackbox/extensions/hooks/action-verify-create/index.js diff --git a/tests-blackbox/extensions/hooks/action-verify-schema/index.js b/tests/blackbox/extensions/hooks/action-verify-schema/index.js similarity index 100% rename from tests-blackbox/extensions/hooks/action-verify-schema/index.js rename to tests/blackbox/extensions/hooks/action-verify-schema/index.js diff --git a/tests-blackbox/jest.config.js b/tests/blackbox/jest.config.js similarity index 100% rename from tests-blackbox/jest.config.js rename to tests/blackbox/jest.config.js diff --git a/tests-blackbox/logger/redact.test.ts b/tests/blackbox/logger/redact.test.ts similarity index 98% rename from tests-blackbox/logger/redact.test.ts rename to tests/blackbox/logger/redact.test.ts index d7d485f5d8..1b669dddda 100644 --- a/tests-blackbox/logger/redact.test.ts +++ b/tests/blackbox/logger/redact.test.ts @@ -1,12 +1,12 @@ -import config, { getUrl } from '@common/config'; +import config, { getUrl, paths } from '@common/config'; import vendors from '@common/get-dbs-to-test'; import * as common from '@common/index'; import { TestLogger } from '@common/test-logger'; import { awaitDirectusConnection } from '@utils/await-connection'; import { ChildProcess, spawn } from 'child_process'; import { EnumType } from 'json-to-graphql-query'; -import knex from 'knex'; import type { Knex } from 'knex'; +import knex from 'knex'; import { cloneDeep } from 'lodash'; import request from 'supertest'; @@ -28,7 +28,7 @@ describe('Logger Redact Tests', () => { for (const vendor of vendors) { databases.set(vendor, knex(config.knexConfig[vendor]!)); - const server = spawn('node', ['api/cli', 'start'], { env: env[vendor] }); + const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env[vendor] }); directusInstances[vendor] = server; promises.push(awaitDirectusConnection(Number(env[vendor].PORT))); diff --git a/tests/blackbox/package.json b/tests/blackbox/package.json new file mode 100644 index 0000000000..cbc7f68313 --- /dev/null +++ b/tests/blackbox/package.json @@ -0,0 +1,31 @@ +{ + "name": "tests-blackbox", + "private": true, + "scripts": { + "test": "jest" + }, + "devDependencies": { + "@directus/types": "workspace:*", + "@types/jest": "29.4.4", + "@types/js-yaml": "4.0.5", + "@types/lodash": "4.14.191", + "@types/seedrandom": "3.0.5", + "@types/supertest": "2.0.12", + "@types/uuid": "9.0.1", + "autocannon": "7.10.0", + "axios": "1.3.4", + "globby": "11.1.0", + "jest": "29.5.0", + "jest-environment-node": "29.5.0", + "js-yaml": "4.1.0", + "json-to-graphql-query": "2.2.5", + "knex": "2.4.2", + "listr2": "5.0.8", + "lodash": "4.17.21", + "seedrandom": "3.0.5", + "supertest": "6.3.3", + "ts-jest": "29.0.5", + "typescript": "4.9.5", + "uuid": "9.0.0" + } +} diff --git a/tests-blackbox/query/filter/index.ts b/tests/blackbox/query/filter/index.ts similarity index 100% rename from tests-blackbox/query/filter/index.ts rename to tests/blackbox/query/filter/index.ts diff --git a/tests-blackbox/query/index.ts b/tests/blackbox/query/index.ts similarity index 100% rename from tests-blackbox/query/index.ts rename to tests/blackbox/query/index.ts diff --git a/tests-blackbox/readme.md b/tests/blackbox/readme.md similarity index 59% rename from tests-blackbox/readme.md rename to tests/blackbox/readme.md index 6fec9a7e11..03a62af5cc 100644 --- a/tests-blackbox/readme.md +++ b/tests/blackbox/readme.md @@ -4,16 +4,20 @@ Make sure the containers for the databases are running by running `docker compose up -d` in this folder. +Directus needs to be deployed with `pnpm --filter directus deploy --prod dist`. When using the `test:blackbox` script in the workspace root (`pnpm -w run test:blackbox`) this is already done. + ## Running tests locally -Run `npm run test:blackbox` to run the blackbox tests for every supported database vendor. +Run `pnpm -w run test:blackbox` to run the blackbox tests for every supported database vendor. + +Prepend `TEST_SAVE_LOGS=trace` to get trace logs at `server-logs-*` in this folder. ### Testing a specific database Provide a csv of database drivers in the `TEST_DB` environment variable to test specific databases: ``` -TEST_DB=cockroachdb npm run test:blackbox +TEST_DB=cockroachdb pnpm -w run test:blackbox ``` ### Using an existing Directus instance @@ -22,15 +26,8 @@ The test suite will spin up a fresh copy of the Directus API from the current bu Directus, set the `TEST_LOCAL` flag: ``` -TEST_DB=cockroachdb TEST_LOCAL=true npm run test:blackbox +TEST_DB=cockroachdb TEST_LOCAL=true pnpm -w run test:blackbox ``` This will use `127.0.0.1:8055` as the URL for every test. Note: make sure to connect your local Directus database instance to the test database container found in docker-compose in this folder. - -### Watching for (test) changes - -Use `npm run test:blackbox:watch` to enable Jest's `--watch` mode, especially useful in combination with the flags -above. - -This _does not_ watch changes to Directus; it only watches changes to the tests. diff --git a/tests-blackbox/routes/assets/concurrency.test.ts b/tests/blackbox/routes/assets/concurrency.test.ts similarity index 100% rename from tests-blackbox/routes/assets/concurrency.test.ts rename to tests/blackbox/routes/assets/concurrency.test.ts diff --git a/tests-blackbox/routes/assets/limit.test.ts b/tests/blackbox/routes/assets/limit.test.ts similarity index 100% rename from tests-blackbox/routes/assets/limit.test.ts rename to tests/blackbox/routes/assets/limit.test.ts diff --git a/tests-blackbox/routes/assets/read.test.ts b/tests/blackbox/routes/assets/read.test.ts similarity index 100% rename from tests-blackbox/routes/assets/read.test.ts rename to tests/blackbox/routes/assets/read.test.ts diff --git a/tests-blackbox/routes/auth/login.test.ts b/tests/blackbox/routes/auth/login.test.ts similarity index 100% rename from tests-blackbox/routes/auth/login.test.ts rename to tests/blackbox/routes/auth/login.test.ts diff --git a/tests-blackbox/routes/auth/refresh.test.ts b/tests/blackbox/routes/auth/refresh.test.ts similarity index 100% rename from tests-blackbox/routes/auth/refresh.test.ts rename to tests/blackbox/routes/auth/refresh.test.ts diff --git a/tests-blackbox/routes/auth/saml.test.ts b/tests/blackbox/routes/auth/saml.test.ts similarity index 100% rename from tests-blackbox/routes/auth/saml.test.ts rename to tests/blackbox/routes/auth/saml.test.ts diff --git a/tests-blackbox/routes/collections/crud.test.ts b/tests/blackbox/routes/collections/crud.test.ts similarity index 100% rename from tests-blackbox/routes/collections/crud.test.ts rename to tests/blackbox/routes/collections/crud.test.ts diff --git a/tests-blackbox/routes/collections/files.test.ts b/tests/blackbox/routes/collections/files.test.ts similarity index 100% rename from tests-blackbox/routes/collections/files.test.ts rename to tests/blackbox/routes/collections/files.test.ts diff --git a/tests-blackbox/routes/collections/schema-cache.test.ts b/tests/blackbox/routes/collections/schema-cache.test.ts similarity index 73% rename from tests-blackbox/routes/collections/schema-cache.test.ts rename to tests/blackbox/routes/collections/schema-cache.test.ts index a826a6b7a3..7cd92836f8 100644 --- a/tests-blackbox/routes/collections/schema-cache.test.ts +++ b/tests/blackbox/routes/collections/schema-cache.test.ts @@ -1,12 +1,12 @@ -import config, { Env, getUrl } from '@common/config'; +import config, { Env, getUrl, paths } from '@common/config'; import vendors from '@common/get-dbs-to-test'; -import request from 'supertest'; -import knex from 'knex'; -import type { Knex } from 'knex'; -import { spawn, ChildProcess } from 'child_process'; -import { awaitDirectusConnection } from '@utils/await-connection'; import * as common from '@common/index'; +import { awaitDirectusConnection } from '@utils/await-connection'; +import { ChildProcess, spawn } from 'child_process'; +import type { Knex } from 'knex'; +import knex from 'knex'; import { cloneDeep } from 'lodash'; +import request from 'supertest'; describe('Schema Caching Tests', () => { const databases = new Map(); @@ -20,47 +20,47 @@ describe('Schema Caching Tests', () => { for (const vendor of vendors) { databases.set(vendor, knex(config.knexConfig[vendor]!)); - const env = cloneDeep(config.envs); - env[vendor].CACHE_ENABLED = 'true'; - env[vendor].CACHE_AUTO_PURGE = 'true'; - env[vendor].CACHE_SCHEMA = 'true'; - env[vendor].CACHE_STORE = 'memory'; - env[vendor].CACHE_NAMESPACE = 'directus-schema-cache'; - env[vendor].MESSENGER_STORE = 'redis'; - env[vendor].MESSENGER_NAMESPACE = `directus-${vendor}`; - env[vendor].MESSENGER_REDIS = `redis://localhost:6108/4`; + const env1 = cloneDeep(config.envs); + env1[vendor].CACHE_ENABLED = 'true'; + env1[vendor].CACHE_AUTO_PURGE = 'true'; + env1[vendor].CACHE_SCHEMA = 'true'; + env1[vendor].CACHE_STORE = 'memory'; + env1[vendor].CACHE_NAMESPACE = 'directus-schema-cache'; + env1[vendor].MESSENGER_STORE = 'redis'; + env1[vendor].MESSENGER_NAMESPACE = `directus-${vendor}`; + env1[vendor].MESSENGER_REDIS = `redis://localhost:6108/4`; - const env2 = cloneDeep(env); - env2[vendor].CACHE_NAMESPACE = env[vendor].CACHE_NAMESPACE + '2'; + const env2 = cloneDeep(env1); + env2[vendor].CACHE_NAMESPACE = env1[vendor].CACHE_NAMESPACE + '2'; - const env3 = cloneDeep(env); - env3[vendor].CACHE_NAMESPACE = env[vendor].CACHE_NAMESPACE + '3'; + const env3 = cloneDeep(env1); + env3[vendor].CACHE_NAMESPACE = env1[vendor].CACHE_NAMESPACE + '3'; delete env3[vendor].MESSENGER_STORE; delete env3[vendor].MESSENGER_NAMESPACE; delete env3[vendor].MESSENGER_REDIS; const env4 = cloneDeep(env3); - env4[vendor].CACHE_NAMESPACE = env[vendor].CACHE_NAMESPACE + '4'; + env4[vendor].CACHE_NAMESPACE = env1[vendor].CACHE_NAMESPACE + '4'; - const newServerPort = Number(env[vendor]!.PORT) + 150; + const newServerPort1 = Number(env1[vendor]!.PORT) + 150; const newServerPort2 = Number(env2[vendor]!.PORT) + 200; const newServerPort3 = Number(env3[vendor]!.PORT) + 250; const newServerPort4 = Number(env4[vendor]!.PORT) + 300; - env[vendor]!.PORT = String(newServerPort); + env1[vendor]!.PORT = String(newServerPort1); env2[vendor]!.PORT = String(newServerPort2); env3[vendor]!.PORT = String(newServerPort3); env4[vendor]!.PORT = String(newServerPort4); - const server = spawn('node', ['api/cli', 'start'], { env: env[vendor] }); - const server2 = spawn('node', ['api/cli', 'start'], { env: env2[vendor] }); - const server3 = spawn('node', ['api/cli', 'start'], { env: env3[vendor] }); - const server4 = spawn('node', ['api/cli', 'start'], { env: env4[vendor] }); + const server1 = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env1[vendor] }); + const server2 = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env2[vendor] }); + const server3 = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env3[vendor] }); + const server4 = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env4[vendor] }); - tzDirectus[vendor] = [server, server2, server3, server4]; - envs[vendor] = [env, env2, env3, env4]; + tzDirectus[vendor] = [server1, server2, server3, server4]; + envs[vendor] = [env1, env2, env3, env4]; - promises.push(awaitDirectusConnection(newServerPort)); + promises.push(awaitDirectusConnection(newServerPort1)); promises.push(awaitDirectusConnection(newServerPort2)); promises.push(awaitDirectusConnection(newServerPort3)); promises.push(awaitDirectusConnection(newServerPort4)); @@ -84,15 +84,15 @@ describe('Schema Caching Tests', () => { describe('schema change propagates across nodes using messenger', () => { it.each(vendors)('%s', async (vendor) => { // Setup - const env = envs[vendor][0]; + const env1 = envs[vendor][0]; const env2 = envs[vendor][1]; - await common.CreateCollection(vendor, { collection: newCollectionName, env }); + await common.CreateCollection(vendor, { collection: newCollectionName, env: env1 }); - await request(getUrl(vendor, env)) + await request(getUrl(vendor, env1)) .post(`/utils/cache/clear`) .set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); - await request(getUrl(vendor, env)).get(`/fields`).set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); + await request(getUrl(vendor, env1)).get(`/fields`).set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); await request(getUrl(vendor, env2)) .post(`/utils/cache/clear`) @@ -100,18 +100,18 @@ describe('Schema Caching Tests', () => { await request(getUrl(vendor, env2)).get(`/fields`).set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); // Action - const responseBefore = await request(getUrl(vendor, env)) + const responseBefore = await request(getUrl(vendor, env1)) .get(`/collections/${newCollectionName}`) .set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); const responseBefore2 = await request(getUrl(vendor, env2)) .get(`/collections/${newCollectionName}`) .set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); - await request(getUrl(vendor, env)) + await request(getUrl(vendor, env1)) .delete(`/collections/${newCollectionName}`) .set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); - const responseAfter = await request(getUrl(vendor, env)) + const responseAfter = await request(getUrl(vendor, env1)) .get(`/collections/${newCollectionName}`) .set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`); const responseAfter2 = await request(getUrl(vendor, env2)) diff --git a/tests-blackbox/routes/fields/change-fields.seed.ts b/tests/blackbox/routes/fields/change-fields.seed.ts similarity index 100% rename from tests-blackbox/routes/fields/change-fields.seed.ts rename to tests/blackbox/routes/fields/change-fields.seed.ts diff --git a/tests-blackbox/routes/fields/change-fields.test.ts b/tests/blackbox/routes/fields/change-fields.test.ts similarity index 100% rename from tests-blackbox/routes/fields/change-fields.test.ts rename to tests/blackbox/routes/fields/change-fields.test.ts diff --git a/tests-blackbox/routes/fields/crud.seed.ts b/tests/blackbox/routes/fields/crud.seed.ts similarity index 100% rename from tests-blackbox/routes/fields/crud.seed.ts rename to tests/blackbox/routes/fields/crud.seed.ts diff --git a/tests-blackbox/routes/fields/crud.test.ts b/tests/blackbox/routes/fields/crud.test.ts similarity index 100% rename from tests-blackbox/routes/fields/crud.test.ts rename to tests/blackbox/routes/fields/crud.test.ts diff --git a/tests-blackbox/routes/files/storage.test.ts b/tests/blackbox/routes/files/storage.test.ts similarity index 100% rename from tests-blackbox/routes/files/storage.test.ts rename to tests/blackbox/routes/files/storage.test.ts diff --git a/tests-blackbox/routes/items/conceal-filter.seed.ts b/tests/blackbox/routes/items/conceal-filter.seed.ts similarity index 100% rename from tests-blackbox/routes/items/conceal-filter.seed.ts rename to tests/blackbox/routes/items/conceal-filter.seed.ts diff --git a/tests-blackbox/routes/items/conceal-filter.test.ts b/tests/blackbox/routes/items/conceal-filter.test.ts similarity index 100% rename from tests-blackbox/routes/items/conceal-filter.test.ts rename to tests/blackbox/routes/items/conceal-filter.test.ts diff --git a/tests-blackbox/routes/items/hash-filter.seed.ts b/tests/blackbox/routes/items/hash-filter.seed.ts similarity index 100% rename from tests-blackbox/routes/items/hash-filter.seed.ts rename to tests/blackbox/routes/items/hash-filter.seed.ts diff --git a/tests-blackbox/routes/items/hash-filter.test.ts b/tests/blackbox/routes/items/hash-filter.test.ts similarity index 100% rename from tests-blackbox/routes/items/hash-filter.test.ts rename to tests/blackbox/routes/items/hash-filter.test.ts diff --git a/tests-blackbox/routes/items/m2a.seed.ts b/tests/blackbox/routes/items/m2a.seed.ts similarity index 100% rename from tests-blackbox/routes/items/m2a.seed.ts rename to tests/blackbox/routes/items/m2a.seed.ts diff --git a/tests-blackbox/routes/items/m2a.test.ts b/tests/blackbox/routes/items/m2a.test.ts similarity index 100% rename from tests-blackbox/routes/items/m2a.test.ts rename to tests/blackbox/routes/items/m2a.test.ts diff --git a/tests-blackbox/routes/items/m2m.seed.ts b/tests/blackbox/routes/items/m2m.seed.ts similarity index 100% rename from tests-blackbox/routes/items/m2m.seed.ts rename to tests/blackbox/routes/items/m2m.seed.ts diff --git a/tests-blackbox/routes/items/m2m.test.ts b/tests/blackbox/routes/items/m2m.test.ts similarity index 100% rename from tests-blackbox/routes/items/m2m.test.ts rename to tests/blackbox/routes/items/m2m.test.ts diff --git a/tests-blackbox/routes/items/m2o.seed.ts b/tests/blackbox/routes/items/m2o.seed.ts similarity index 100% rename from tests-blackbox/routes/items/m2o.seed.ts rename to tests/blackbox/routes/items/m2o.seed.ts diff --git a/tests-blackbox/routes/items/m2o.test.ts b/tests/blackbox/routes/items/m2o.test.ts similarity index 100% rename from tests-blackbox/routes/items/m2o.test.ts rename to tests/blackbox/routes/items/m2o.test.ts diff --git a/tests-blackbox/routes/items/no-relation.seed.ts b/tests/blackbox/routes/items/no-relation.seed.ts similarity index 100% rename from tests-blackbox/routes/items/no-relation.seed.ts rename to tests/blackbox/routes/items/no-relation.seed.ts diff --git a/tests-blackbox/routes/items/no-relation.test.ts b/tests/blackbox/routes/items/no-relation.test.ts similarity index 100% rename from tests-blackbox/routes/items/no-relation.test.ts rename to tests/blackbox/routes/items/no-relation.test.ts diff --git a/tests-blackbox/routes/items/o2m.seed.ts b/tests/blackbox/routes/items/o2m.seed.ts similarity index 100% rename from tests-blackbox/routes/items/o2m.seed.ts rename to tests/blackbox/routes/items/o2m.seed.ts diff --git a/tests-blackbox/routes/items/o2m.test.ts b/tests/blackbox/routes/items/o2m.test.ts similarity index 100% rename from tests-blackbox/routes/items/o2m.test.ts rename to tests/blackbox/routes/items/o2m.test.ts diff --git a/tests-blackbox/routes/items/seed-all-field-types.ts b/tests/blackbox/routes/items/seed-all-field-types.ts similarity index 100% rename from tests-blackbox/routes/items/seed-all-field-types.ts rename to tests/blackbox/routes/items/seed-all-field-types.ts diff --git a/tests-blackbox/routes/items/seed-relational-fields.ts b/tests/blackbox/routes/items/seed-relational-fields.ts similarity index 100% rename from tests-blackbox/routes/items/seed-relational-fields.ts rename to tests/blackbox/routes/items/seed-relational-fields.ts diff --git a/tests-blackbox/routes/items/singleton.seed.ts b/tests/blackbox/routes/items/singleton.seed.ts similarity index 100% rename from tests-blackbox/routes/items/singleton.seed.ts rename to tests/blackbox/routes/items/singleton.seed.ts diff --git a/tests-blackbox/routes/items/singleton.test.ts b/tests/blackbox/routes/items/singleton.test.ts similarity index 100% rename from tests-blackbox/routes/items/singleton.test.ts rename to tests/blackbox/routes/items/singleton.test.ts diff --git a/tests-blackbox/routes/schema/schema.seed.ts b/tests/blackbox/routes/schema/schema.seed.ts similarity index 100% rename from tests-blackbox/routes/schema/schema.seed.ts rename to tests/blackbox/routes/schema/schema.seed.ts diff --git a/tests-blackbox/routes/schema/schema.test.ts b/tests/blackbox/routes/schema/schema.test.ts similarity index 99% rename from tests-blackbox/routes/schema/schema.test.ts rename to tests/blackbox/routes/schema/schema.test.ts index fa59ef8d55..1ee65b4e38 100644 --- a/tests-blackbox/routes/schema/schema.test.ts +++ b/tests/blackbox/routes/schema/schema.test.ts @@ -24,7 +24,7 @@ import { import { cloneDeep } from 'lodash'; import { PrimaryKeyType, PRIMARY_KEY_TYPES } from '@common/index'; import { load as loadYaml } from 'js-yaml'; -import { version as currentDirectusVersion } from '../../../api/package.json'; +import { version as currentDirectusVersion } from '../../../../api/package.json'; import { v4 as uuid } from 'uuid'; describe('Schema Snapshots', () => { diff --git a/tests-blackbox/routes/server/health.test.ts b/tests/blackbox/routes/server/health.test.ts similarity index 100% rename from tests-blackbox/routes/server/health.test.ts rename to tests/blackbox/routes/server/health.test.ts diff --git a/tests-blackbox/routes/server/ping.test.ts b/tests/blackbox/routes/server/ping.test.ts similarity index 100% rename from tests-blackbox/routes/server/ping.test.ts rename to tests/blackbox/routes/server/ping.test.ts diff --git a/tests-blackbox/schema/alias/index.ts b/tests/blackbox/schema/alias/index.ts similarity index 100% rename from tests-blackbox/schema/alias/index.ts rename to tests/blackbox/schema/alias/index.ts diff --git a/tests-blackbox/schema/big-integer/index.ts b/tests/blackbox/schema/big-integer/index.ts similarity index 100% rename from tests-blackbox/schema/big-integer/index.ts rename to tests/blackbox/schema/big-integer/index.ts diff --git a/tests-blackbox/schema/boolean/index.ts b/tests/blackbox/schema/boolean/index.ts similarity index 100% rename from tests-blackbox/schema/boolean/index.ts rename to tests/blackbox/schema/boolean/index.ts diff --git a/tests-blackbox/schema/csv/index.ts b/tests/blackbox/schema/csv/index.ts similarity index 100% rename from tests-blackbox/schema/csv/index.ts rename to tests/blackbox/schema/csv/index.ts diff --git a/tests-blackbox/schema/date-time/index.ts b/tests/blackbox/schema/date-time/index.ts similarity index 100% rename from tests-blackbox/schema/date-time/index.ts rename to tests/blackbox/schema/date-time/index.ts diff --git a/tests-blackbox/schema/date/index.ts b/tests/blackbox/schema/date/index.ts similarity index 100% rename from tests-blackbox/schema/date/index.ts rename to tests/blackbox/schema/date/index.ts diff --git a/tests-blackbox/schema/decimal/index.ts b/tests/blackbox/schema/decimal/index.ts similarity index 100% rename from tests-blackbox/schema/decimal/index.ts rename to tests/blackbox/schema/decimal/index.ts diff --git a/tests-blackbox/schema/float/index.ts b/tests/blackbox/schema/float/index.ts similarity index 100% rename from tests-blackbox/schema/float/index.ts rename to tests/blackbox/schema/float/index.ts diff --git a/tests-blackbox/schema/geometry/index.ts b/tests/blackbox/schema/geometry/index.ts similarity index 100% rename from tests-blackbox/schema/geometry/index.ts rename to tests/blackbox/schema/geometry/index.ts diff --git a/tests-blackbox/schema/hash/index.ts b/tests/blackbox/schema/hash/index.ts similarity index 100% rename from tests-blackbox/schema/hash/index.ts rename to tests/blackbox/schema/hash/index.ts diff --git a/tests-blackbox/schema/index.ts b/tests/blackbox/schema/index.ts similarity index 100% rename from tests-blackbox/schema/index.ts rename to tests/blackbox/schema/index.ts diff --git a/tests-blackbox/schema/integer/index.ts b/tests/blackbox/schema/integer/index.ts similarity index 100% rename from tests-blackbox/schema/integer/index.ts rename to tests/blackbox/schema/integer/index.ts diff --git a/tests-blackbox/schema/json/index.ts b/tests/blackbox/schema/json/index.ts similarity index 100% rename from tests-blackbox/schema/json/index.ts rename to tests/blackbox/schema/json/index.ts diff --git a/tests-blackbox/schema/string/index.ts b/tests/blackbox/schema/string/index.ts similarity index 100% rename from tests-blackbox/schema/string/index.ts rename to tests/blackbox/schema/string/index.ts diff --git a/tests-blackbox/schema/text/index.ts b/tests/blackbox/schema/text/index.ts similarity index 100% rename from tests-blackbox/schema/text/index.ts rename to tests/blackbox/schema/text/index.ts diff --git a/tests-blackbox/schema/time/index.ts b/tests/blackbox/schema/time/index.ts similarity index 100% rename from tests-blackbox/schema/time/index.ts rename to tests/blackbox/schema/time/index.ts diff --git a/tests-blackbox/schema/timestamp/index.ts b/tests/blackbox/schema/timestamp/index.ts similarity index 100% rename from tests-blackbox/schema/timestamp/index.ts rename to tests/blackbox/schema/timestamp/index.ts diff --git a/tests-blackbox/schema/timezone/timezone-changed-node-tz-america.test.ts b/tests/blackbox/schema/timezone/timezone-changed-node-tz-america.test.ts similarity index 97% rename from tests-blackbox/schema/timezone/timezone-changed-node-tz-america.test.ts rename to tests/blackbox/schema/timezone/timezone-changed-node-tz-america.test.ts index c2db4bb73c..d095f30429 100644 --- a/tests-blackbox/schema/timezone/timezone-changed-node-tz-america.test.ts +++ b/tests/blackbox/schema/timezone/timezone-changed-node-tz-america.test.ts @@ -1,14 +1,14 @@ -import config, { getUrl } from '@common/config'; +import config, { getUrl, paths } from '@common/config'; import vendors from '@common/get-dbs-to-test'; -import request from 'supertest'; -import knex from 'knex'; -import type { Knex } from 'knex'; -import { cloneDeep } from 'lodash'; -import { spawn, ChildProcess } from 'child_process'; -import { awaitDirectusConnection } from '@utils/await-connection'; -import { validateDateDifference } from '@utils/validate-date-difference'; import * as common from '@common/index'; +import { awaitDirectusConnection } from '@utils/await-connection'; import { sleep } from '@utils/sleep'; +import { validateDateDifference } from '@utils/validate-date-difference'; +import { ChildProcess, spawn } from 'child_process'; +import type { Knex } from 'knex'; +import knex from 'knex'; +import { cloneDeep } from 'lodash'; +import request from 'supertest'; const collectionName = 'schema_timezone_tests'; @@ -74,7 +74,7 @@ describe('schema', () => { config.envs[vendor]!.TZ = newTz; config.envs[vendor]!.PORT = String(newServerPort); - const server = spawn('node', ['api/cli', 'start'], { env: config.envs[vendor] }); + const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: config.envs[vendor] }); tzDirectus[vendor] = server; let serverOutput = ''; diff --git a/tests-blackbox/schema/timezone/timezone-changed-node-tz-asia.test.ts b/tests/blackbox/schema/timezone/timezone-changed-node-tz-asia.test.ts similarity index 98% rename from tests-blackbox/schema/timezone/timezone-changed-node-tz-asia.test.ts rename to tests/blackbox/schema/timezone/timezone-changed-node-tz-asia.test.ts index f71f9eea30..1d6f77c499 100644 --- a/tests-blackbox/schema/timezone/timezone-changed-node-tz-asia.test.ts +++ b/tests/blackbox/schema/timezone/timezone-changed-node-tz-asia.test.ts @@ -1,14 +1,14 @@ -import config, { getUrl } from '@common/config'; +import config, { getUrl, paths } from '@common/config'; import vendors from '@common/get-dbs-to-test'; -import request from 'supertest'; -import knex from 'knex'; -import type { Knex } from 'knex'; -import { cloneDeep } from 'lodash'; -import { spawn, ChildProcess } from 'child_process'; -import { awaitDirectusConnection } from '@utils/await-connection'; -import { validateDateDifference } from '@utils/validate-date-difference'; import * as common from '@common/index'; +import { awaitDirectusConnection } from '@utils/await-connection'; import { sleep } from '@utils/sleep'; +import { validateDateDifference } from '@utils/validate-date-difference'; +import { ChildProcess, spawn } from 'child_process'; +import type { Knex } from 'knex'; +import knex from 'knex'; +import { cloneDeep } from 'lodash'; +import request from 'supertest'; const collectionName = 'schema_timezone_tests'; @@ -71,7 +71,7 @@ describe('schema', () => { config.envs[vendor]!.TZ = newTz; config.envs[vendor]!.PORT = String(newServerPort); - const server = spawn('node', ['api/cli', 'start'], { env: config.envs[vendor] }); + const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: config.envs[vendor] }); tzDirectus[vendor] = server; let serverOutput = ''; diff --git a/tests-blackbox/schema/timezone/timezone.test.ts b/tests/blackbox/schema/timezone/timezone.test.ts similarity index 100% rename from tests-blackbox/schema/timezone/timezone.test.ts rename to tests/blackbox/schema/timezone/timezone.test.ts diff --git a/tests-blackbox/schema/uuid/index.ts b/tests/blackbox/schema/uuid/index.ts similarity index 100% rename from tests-blackbox/schema/uuid/index.ts rename to tests/blackbox/schema/uuid/index.ts diff --git a/tests-blackbox/setup/customEnvironment.ts b/tests/blackbox/setup/customEnvironment.ts similarity index 95% rename from tests-blackbox/setup/customEnvironment.ts rename to tests/blackbox/setup/customEnvironment.ts index ab5764dfc2..fff8a1b6ef 100644 --- a/tests-blackbox/setup/customEnvironment.ts +++ b/tests/blackbox/setup/customEnvironment.ts @@ -14,7 +14,7 @@ declare global { class CustomEnvironment extends NodeEnvironment { constructor(config: any, context: any) { super(config, context); - this.global.testFilePath = String(context.testPath).split('tests-blackbox')[1]!; + this.global.testFilePath = String(context.testPath).split('blackbox')[1]!; } async setup() { diff --git a/tests-blackbox/setup/customSequencer.js b/tests/blackbox/setup/customSequencer.js similarity index 100% rename from tests-blackbox/setup/customSequencer.js rename to tests/blackbox/setup/customSequencer.js diff --git a/tests-blackbox/setup/global.ts b/tests/blackbox/setup/global.ts similarity index 100% rename from tests-blackbox/setup/global.ts rename to tests/blackbox/setup/global.ts diff --git a/tests-blackbox/setup/migrations/20220112001234_create_tests_flow.js b/tests/blackbox/setup/migrations/20220112001234_create_tests_flow.js similarity index 100% rename from tests-blackbox/setup/migrations/20220112001234_create_tests_flow.js rename to tests/blackbox/setup/migrations/20220112001234_create_tests_flow.js diff --git a/tests-blackbox/setup/migrations/20221107_add_extensions_testing.js b/tests/blackbox/setup/migrations/20221107_add_extensions_testing.js similarity index 100% rename from tests-blackbox/setup/migrations/20221107_add_extensions_testing.js rename to tests/blackbox/setup/migrations/20221107_add_extensions_testing.js diff --git a/tests-blackbox/setup/seeds/01_delete_existing_data.js b/tests/blackbox/setup/seeds/01_delete_existing_data.js similarity index 100% rename from tests-blackbox/setup/seeds/01_delete_existing_data.js rename to tests/blackbox/setup/seeds/01_delete_existing_data.js diff --git a/tests-blackbox/setup/seeds/02_tests_flow.js b/tests/blackbox/setup/seeds/02_tests_flow.js similarity index 100% rename from tests-blackbox/setup/seeds/02_tests_flow.js rename to tests/blackbox/setup/seeds/02_tests_flow.js diff --git a/tests-blackbox/setup/seeds/03_tests_extensions.js b/tests/blackbox/setup/seeds/03_tests_extensions.js similarity index 100% rename from tests-blackbox/setup/seeds/03_tests_extensions.js rename to tests/blackbox/setup/seeds/03_tests_extensions.js diff --git a/tests-blackbox/setup/sequentialTests.d.ts b/tests/blackbox/setup/sequentialTests.d.ts similarity index 100% rename from tests-blackbox/setup/sequentialTests.d.ts rename to tests/blackbox/setup/sequentialTests.d.ts diff --git a/tests-blackbox/setup/sequentialTests.js b/tests/blackbox/setup/sequentialTests.js similarity index 100% rename from tests-blackbox/setup/sequentialTests.js rename to tests/blackbox/setup/sequentialTests.js diff --git a/tests-blackbox/setup/setup-utils.js b/tests/blackbox/setup/setup-utils.js similarity index 100% rename from tests-blackbox/setup/setup-utils.js rename to tests/blackbox/setup/setup-utils.js diff --git a/tests-blackbox/setup/setup.ts b/tests/blackbox/setup/setup.ts similarity index 88% rename from tests-blackbox/setup/setup.ts rename to tests/blackbox/setup/setup.ts index bbcaa67f71..3a402ddf4d 100644 --- a/tests-blackbox/setup/setup.ts +++ b/tests/blackbox/setup/setup.ts @@ -1,16 +1,17 @@ /* eslint-disable no-console */ +import axios from 'axios'; +import { spawn, spawnSync } from 'child_process'; +import { writeFileSync } from 'fs'; import knex from 'knex'; import { Listr } from 'listr2'; -import vendors from '../common/get-dbs-to-test'; -import config, { getUrl } from '../common/config'; -import global from './global'; -import { spawn, spawnSync } from 'child_process'; -import axios from 'axios'; -import { writeFileSync } from 'fs'; -import { awaitDatabaseConnection, awaitDirectusConnection } from '../utils/await-connection'; -import * as common from '../common'; import { clone } from 'lodash'; +import path from 'node:path'; +import * as common from '../common'; +import config, { getUrl, paths } from '../common/config'; +import vendors from '../common/get-dbs-to-test'; +import { awaitDatabaseConnection, awaitDirectusConnection } from '../utils/await-connection'; +import global from './global'; let started = false; @@ -34,9 +35,12 @@ export default async (): Promise => { const database = knex(config.knexConfig[vendor]!); await awaitDatabaseConnection(database, config.knexConfig[vendor]!.waitTestSQL); if (vendor === 'sqlite3') { - writeFileSync('test.db', ''); + writeFileSync(path.join(paths.cwd, 'test.db'), ''); } - const bootstrap = spawnSync('node', ['api/cli', 'bootstrap'], { env: config.envs[vendor] }); + const bootstrap = spawnSync('node', [paths.cli, 'bootstrap'], { + cwd: paths.cwd, + env: config.envs[vendor], + }); if (bootstrap.stderr.length > 0) { throw new Error(`Directus-${vendor} bootstrap failed: \n ${bootstrap.stderr.toString()}`); } @@ -45,7 +49,10 @@ export default async (): Promise => { await database.destroy(); if (!process.env.TEST_LOCAL) { - const server = spawn('node', ['api/cli', 'start'], { env: config.envs[vendor] }); + const server = spawn('node', [paths.cli, 'start'], { + cwd: paths.cwd, + env: config.envs[vendor], + }); global.directus[vendor] = server; let serverOutput = ''; server.stdout.setEncoding('utf8'); @@ -54,7 +61,7 @@ export default async (): Promise => { }); server.on('exit', (code) => { if (process.env.TEST_SAVE_LOGS) { - writeFileSync(__dirname + `/../server-log-${vendor}.txt`, serverOutput); + writeFileSync(path.join(paths.cwd, `server-log-${vendor}.txt`), serverOutput); } if (code !== null) throw new Error(`Directus-${vendor} server failed: \n ${serverOutput}`); }); @@ -66,7 +73,7 @@ export default async (): Promise => { const noCacheEnv = clone(config.envs[vendor]!); noCacheEnv.CACHE_SCHEMA = 'false'; noCacheEnv.PORT = String(parseInt(noCacheEnv.PORT!) + 50); - const serverNoCache = spawn('node', ['api/cli', 'start'], { env: noCacheEnv }); + const serverNoCache = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: noCacheEnv }); global.directusNoCache[vendor] = serverNoCache; let serverNoCacheOutput = ''; serverNoCache.stdout.setEncoding('utf8'); diff --git a/tests-blackbox/setup/teardown.ts b/tests/blackbox/setup/teardown.ts similarity index 100% rename from tests-blackbox/setup/teardown.ts rename to tests/blackbox/setup/teardown.ts diff --git a/tests-blackbox/todo.md b/tests/blackbox/todo.md similarity index 100% rename from tests-blackbox/todo.md rename to tests/blackbox/todo.md diff --git a/tests/blackbox/tsconfig.json b/tests/blackbox/tsconfig.json new file mode 100644 index 0000000000..35c6bd6e52 --- /dev/null +++ b/tests/blackbox/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "ES2020", + "moduleResolution": "node", + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true, + "resolveJsonModule": true, + "paths": { + "@common/*": ["./common/*"], + "@query/*": ["./query/*"], + "@schema/*": ["./schema/*"], + "@utils/*": ["./utils/*"] + } + }, + "exclude": ["node_modules", "extensions"] +} diff --git a/tests-blackbox/utils/await-connection.ts b/tests/blackbox/utils/await-connection.ts similarity index 100% rename from tests-blackbox/utils/await-connection.ts rename to tests/blackbox/utils/await-connection.ts diff --git a/tests-blackbox/utils/get-filter-operators-for-type.ts b/tests/blackbox/utils/get-filter-operators-for-type.ts similarity index 100% rename from tests-blackbox/utils/get-filter-operators-for-type.ts rename to tests/blackbox/utils/get-filter-operators-for-type.ts diff --git a/tests-blackbox/utils/prepare-request.ts b/tests/blackbox/utils/prepare-request.ts similarity index 100% rename from tests-blackbox/utils/prepare-request.ts rename to tests/blackbox/utils/prepare-request.ts diff --git a/tests-blackbox/utils/sleep.ts b/tests/blackbox/utils/sleep.ts similarity index 100% rename from tests-blackbox/utils/sleep.ts rename to tests/blackbox/utils/sleep.ts diff --git a/tests-blackbox/utils/validate-date-difference.ts b/tests/blackbox/utils/validate-date-difference.ts similarity index 100% rename from tests-blackbox/utils/validate-date-difference.ts rename to tests/blackbox/utils/validate-date-difference.ts