From 7054ae8a8866b20fcf36165cc996177e519d803b Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Tue, 2 Apr 2024 12:00:32 -0400 Subject: [PATCH] chore: unit/int test CI stuff --- .github/workflows/main.yml | 46 +++---------------- jest.config.js | 9 ++-- package.json | 5 +- packages/db-mongodb/{.swcrc => .swcrc-build} | 0 packages/db-mongodb/package.json | 2 +- .../plugin-cloud/{.swcrc => .swcrc-build} | 2 +- packages/plugin-cloud/jest.config.js | 21 +++++++++ packages/plugin-cloud/package.json | 2 +- .../plugin-sentry/{.swcrc => .swcrc-build} | 2 +- packages/plugin-sentry/jest.config.js | 21 +++++++++ packages/plugin-sentry/package.json | 2 +- test/jest.config.js | 25 +++++----- 12 files changed, 73 insertions(+), 64 deletions(-) rename packages/db-mongodb/{.swcrc => .swcrc-build} (100%) rename packages/plugin-cloud/{.swcrc => .swcrc-build} (84%) rename packages/plugin-sentry/{.swcrc => .swcrc-build} (84%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5636990e0..d2c91b9e2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -201,6 +201,12 @@ jobs: echo "POSTGRES_URL=postgresql://postgres:postgres@127.0.0.1:54322/postgres" >> $GITHUB_ENV if: matrix.database == 'supabase' + - name: Unit Tests + if: false # Disable until tests are updated for 3.0 + run: pnpm test:unit + env: + NODE_OPTIONS: --max-old-space-size=8096 + - name: Integration Tests run: pnpm test:int env: @@ -292,46 +298,6 @@ jobs: - name: Generate GraphQL schema file run: pnpm dev:generate-graphql-schema graphql-schema-gen - plugins: - runs-on: ubuntu-latest - needs: core-build - strategy: - fail-fast: false - matrix: - pkg: - - create-payload-app - - plugin-cloud - - plugin-cloud-storage - - plugin-form-builder - - plugin-nested-docs - - plugin-search - - plugin-sentry - - plugin-seo - - steps: - - name: Use Node.js 18 - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Install pnpm - uses: pnpm/action-setup@v3 - with: - version: 8 - run_install: false - - - name: Restore build - uses: actions/cache@v4 - with: - path: ./* - key: ${{ github.sha }}-${{ github.run_number }} - - - name: Build ${{ matrix.pkg }} - run: pnpm turbo run build --filter=${{ matrix.pkg }} - - - name: Test ${{ matrix.pkg }} - run: pnpm --filter ${{ matrix.pkg }} run test - templates: needs: changes if: false # Disable until templates are updated for 3.0 diff --git a/jest.config.js b/jest.config.js index 63a691389..c92e0bbf5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ /** @type {import('jest').Config} */ -const customJestConfig = { +const baseJestConfig = { extensionsToTreatAsEsm: ['.ts', '.tsx'], setupFilesAfterEnv: ['/test/jest.setup.ts'], moduleNameMapper: { @@ -8,9 +8,8 @@ const customJestConfig = { '/test/helpers/mocks/fileMock.js', '^(\\.{1,2}/.*)\\.js$': '$1', }, - reporters: ['default', ['github-actions', { silent: false }], 'summary'], testEnvironment: 'node', - testMatch: ['/packages/payload/src/**/*.spec.ts', '/test/**/*int.spec.ts'], + testMatch: ['/packages/*/src/**/*.spec.ts'], testTimeout: 90000, transform: { '^.+\\.(t|j)sx?$': ['@swc/jest'], @@ -19,7 +18,7 @@ const customJestConfig = { } if (process.env.CI) { - customJestConfig.reporters = [['github-actions', { silent: false }], 'summary'] + baseJestConfig.reporters = [['github-actions', { silent: false }], 'summary'] } -export default customJestConfig +export default baseJestConfig diff --git a/package.json b/package.json index 324578279..d90842cba 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,9 @@ "test:e2e": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 tsx ./test/runE2E.ts", "test:e2e:debug": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 PWDEBUG=1 DISABLE_LOGGING=true playwright test", "test:e2e:headed": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 DISABLE_LOGGING=true playwright test --headed", - "test:int:postgres": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 PAYLOAD_DATABASE=postgres DISABLE_LOGGING=true jest --forceExit --detectOpenHandles", - "test:int": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 DISABLE_LOGGING=true jest --forceExit --detectOpenHandles", + "test:int:postgres": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 PAYLOAD_DATABASE=postgres DISABLE_LOGGING=true jest --forceExit --detectOpenHandles --config=jest.config.js", + "test:int": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 DISABLE_LOGGING=true jest --forceExit --detectOpenHandles --config=test/jest.config.js", + "test:unit": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 DISABLE_LOGGING=true jest --forceExit --detectOpenHandles --config=jest.config.js", "translateNewKeys": "pnpm --filter payload run translateNewKeys" }, "devDependencies": { diff --git a/packages/db-mongodb/.swcrc b/packages/db-mongodb/.swcrc-build similarity index 100% rename from packages/db-mongodb/.swcrc rename to packages/db-mongodb/.swcrc-build diff --git a/packages/db-mongodb/package.json b/packages/db-mongodb/package.json index 53443ed6a..52c407e03 100644 --- a/packages/db-mongodb/package.json +++ b/packages/db-mongodb/package.json @@ -15,7 +15,7 @@ "types": "./src/types.ts", "scripts": { "build": "pnpm build:swc && pnpm build:types", - "build:swc": "swc ./src -d ./dist --config-file .swcrc", + "build:swc": "swc ./src -d ./dist --config-file .swcrc-build", "build:types": "tsc --emitDeclarationOnly --outDir dist", "clean": "rimraf {dist,*.tsbuildinfo}", "prepublishOnly": "pnpm clean && pnpm turbo build" diff --git a/packages/plugin-cloud/.swcrc b/packages/plugin-cloud/.swcrc-build similarity index 84% rename from packages/plugin-cloud/.swcrc rename to packages/plugin-cloud/.swcrc-build index f698b8f45..c3d33ab63 100644 --- a/packages/plugin-cloud/.swcrc +++ b/packages/plugin-cloud/.swcrc-build @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/swcrc", "sourceMaps": true, - "exclude": ["/**/mocks"], + "exclude": ["/**/mocks", "/**/*.spec.ts"], "jsc": { "target": "esnext", "parser": { diff --git a/packages/plugin-cloud/jest.config.js b/packages/plugin-cloud/jest.config.js index 1e145605e..b0539a179 100644 --- a/packages/plugin-cloud/jest.config.js +++ b/packages/plugin-cloud/jest.config.js @@ -6,6 +6,27 @@ const customJestConfig = { setupFilesAfterEnv: null, testMatch: ['**/src/**/?(*.)+(spec|test|it-test).[tj]s?(x)'], testTimeout: 20000, + transform: { + '^.+\\.(t|j)sx?$': [ + '@swc/jest', + { + $schema: 'https://json.schemastore.org/swcrc', + sourceMaps: true, + exclude: ['/**/mocks'], + jsc: { + target: 'esnext', + parser: { + syntax: 'typescript', + tsx: true, + dts: true, + }, + }, + module: { + type: 'es6', + }, + }, + ], + }, } export default customJestConfig diff --git a/packages/plugin-cloud/package.json b/packages/plugin-cloud/package.json index 6d46f81ee..7bd0d734e 100644 --- a/packages/plugin-cloud/package.json +++ b/packages/plugin-cloud/package.json @@ -8,7 +8,7 @@ "type": "module", "scripts": { "build": "pnpm build:swc && pnpm build:types", - "build:swc": "swc ./src -d ./dist --config-file .swcrc", + "build:swc": "swc ./src -d ./dist --config-file .swcrc-build", "build:types": "tsc --emitDeclarationOnly --outDir dist", "clean": "rimraf {dist,*.tsbuildinfo} && rimraf dev/yarn.lock", "prepublishOnly": "pnpm clean && pnpm turbo build", diff --git a/packages/plugin-sentry/.swcrc b/packages/plugin-sentry/.swcrc-build similarity index 84% rename from packages/plugin-sentry/.swcrc rename to packages/plugin-sentry/.swcrc-build index 9e8175c9c..c3d33ab63 100644 --- a/packages/plugin-sentry/.swcrc +++ b/packages/plugin-sentry/.swcrc-build @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/swcrc", "sourceMaps": true, - "exclude": ["/**/*.spec.ts"], + "exclude": ["/**/mocks", "/**/*.spec.ts"], "jsc": { "target": "esnext", "parser": { diff --git a/packages/plugin-sentry/jest.config.js b/packages/plugin-sentry/jest.config.js index 1e145605e..b0539a179 100644 --- a/packages/plugin-sentry/jest.config.js +++ b/packages/plugin-sentry/jest.config.js @@ -6,6 +6,27 @@ const customJestConfig = { setupFilesAfterEnv: null, testMatch: ['**/src/**/?(*.)+(spec|test|it-test).[tj]s?(x)'], testTimeout: 20000, + transform: { + '^.+\\.(t|j)sx?$': [ + '@swc/jest', + { + $schema: 'https://json.schemastore.org/swcrc', + sourceMaps: true, + exclude: ['/**/mocks'], + jsc: { + target: 'esnext', + parser: { + syntax: 'typescript', + tsx: true, + dts: true, + }, + }, + module: { + type: 'es6', + }, + }, + ], + }, } export default customJestConfig diff --git a/packages/plugin-sentry/package.json b/packages/plugin-sentry/package.json index 19453dbac..9b4579fd6 100644 --- a/packages/plugin-sentry/package.json +++ b/packages/plugin-sentry/package.json @@ -9,7 +9,7 @@ "type": "module", "scripts": { "build": "echo \"Build temporarily disabled.\" && exit 0", - "build:swc": "swc ./src -d ./dist --config-file .swcrc", + "build:swc": "swc ./src -d ./dist --config-file .swcrc-build", "build:types": "tsc --emitDeclarationOnly --outDir dist", "clean": "rimraf {dist,*.tsbuildinfo}", "prepublishOnly": "pnpm clean && pnpm turbo build" diff --git a/test/jest.config.js b/test/jest.config.js index 188c3c621..7f4c5ea14 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -1,28 +1,29 @@ import path from 'path' import { fileURLToPath } from 'url' +import jestBaseConfig from '../jest.config.js' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) /** @type {import('jest').Config} */ const customJestConfig = { - extensionsToTreatAsEsm: ['.ts', '.tsx'], - setupFilesAfterEnv: ['/jest.setup.ts'], + ...jestBaseConfig, + testMatch: ['/**/*int.spec.ts'], + setupFilesAfterEnv: [ + //path.resolve(dirname, './helpers/startMemoryDB.ts'), + '/jest.setup.ts', + ], + globalSetup: path.resolve(dirname, './helpers/startMemoryDB.ts'), moduleNameMapper: { '\\.(css|scss)$': '/helpers/mocks/emptyModule.js', '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/test/helpers/mocks/fileMock.js', + '/helpers/mocks/fileMock.js', '^(\\.{1,2}/.*)\\.js$': '$1', }, - reporters: ['default', ['github-actions', { silent: false }], 'summary'], - testEnvironment: 'node', - globalSetup: path.resolve(dirname, './helpers/startMemoryDB.ts'), - testMatch: ['/**/*int.spec.ts'], - testTimeout: 90000, - transform: { - '^.+\\.(t|j)sx?$': ['@swc/jest'], - }, - verbose: true, +} + +if (process.env.CI) { + customJestConfig.reporters = [['github-actions', { silent: false }], 'summary'] } export default customJestConfig