diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 718e4f489..c119c246a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,7 @@ on: pull_request: types: [ opened, reopened, synchronize ] push: - branches: ['main', 'feat/next-poc'] + branches: ['main', 'alpha'] jobs: changes: @@ -196,9 +196,6 @@ jobs: echo "POSTGRES_URL=postgresql://postgres:postgres@127.0.0.1:54322/postgres" >> $GITHUB_ENV if: matrix.database == 'supabase' - - name: Component Tests - run: pnpm test:components - - name: Integration Tests run: pnpm test:int env: diff --git a/.gitignore b/.gitignore index 943505139..54311a34d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,12 +8,15 @@ test-results .devcontainer .localstack /migrations -/media .localstack .turbo .turbo +# Ignore test directory media folder/files +/media +/versions + # Created by https://www.toptal.com/developers/gitignore/api/node,macos,windows,webstorm,sublimetext,visualstudiocode # Edit at https://www.toptal.com/developers/gitignore?templates=node,macos,windows,webstorm,sublimetext,visualstudiocode @@ -285,3 +288,4 @@ $RECYCLE.BIN/ # End of https://www.toptal.com/developers/gitignore/api/node,macos,windows,webstorm,sublimetext,visualstudiocode /build +.swc \ No newline at end of file diff --git a/.swcrc b/.swcrc new file mode 100644 index 000000000..15eb20bc1 --- /dev/null +++ b/.swcrc @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "sourceMaps": "inline", + "jsc": { + "target": "esnext", + "parser": { + "syntax": "typescript", + "tsx": true, + "dts": true + } + }, + "module": { + "type": "es6" + } +} diff --git a/docs/hooks/collections.mdx b/docs/hooks/collections.mdx index 7bc1fb6cf..f895a76ef 100644 --- a/docs/hooks/collections.mdx +++ b/docs/hooks/collections.mdx @@ -292,13 +292,11 @@ For auth-enabled Collections, this hook runs after successful `forgotPassword` o ```ts import { CollectionAfterForgotPasswordHook } from 'payload/types' -const afterLoginHook: CollectionAfterForgotPasswordHook = async ({ - req, // full express request - user, // user being logged in - token, // user token -}) => { - return user -} +const afterForgotPasswordHook: CollectionAfterForgotPasswordHook = async ({ + args, // arguments passed into the operation + context, + collection, // The collection which this hook is being run on +}) => {...} ``` ## TypeScript diff --git a/docs/plugins/build-your-own.mdx b/docs/plugins/build-your-own.mdx index 7304be966..0b6970112 100644 --- a/docs/plugins/build-your-own.mdx +++ b/docs/plugins/build-your-own.mdx @@ -290,5 +290,5 @@ If you've configured tests for your package, integrate them into your workf The best way to share and allow others to use your plugin once it is complete is to publish an NPM package. This process is straightforward and well documented, find out more about [creating and publishing a NPM package here](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages/). ##### Add payload-plugin topic tag: Apply the tag **payload-plugin** to your GitHub repository. This will boost the visibility of your plugin and ensure it gets listed with [existing payload plugins](https://github.com/topics/payload-plugin). -##### Use [Semantic Versioning](https://semver.org/) (SemVar): -With the SemVar system you release version numbers that reflect the nature of changes (major, minor, patch). Ensure all major versions reference their Payload compatibility. +##### Use [Semantic Versioning](https://semver.org/) (SemVer): +With the SemVer system you release version numbers that reflect the nature of changes (major, minor, patch). Ensure all major versions reference their Payload compatibility. diff --git a/emptyModule.js b/emptyModule.js new file mode 100644 index 000000000..b1c6ea436 --- /dev/null +++ b/emptyModule.js @@ -0,0 +1 @@ +export default {} diff --git a/jest.components.config.js b/jest.components.config.js deleted file mode 100644 index eac17bfda..000000000 --- a/jest.components.config.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - moduleNameMapper: { - '\\.(css|scss)$': '/packages/payload/src/bundlers/mocks/emptyModule.js', - '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/packages/payload/src/bundlers/mocks/fileMock.js', - }, - setupFilesAfterEnv: ['./test/componentsSetup.js'], - testEnvironment: 'jsdom', - testPathIgnorePatterns: ['node_modules', 'dist'], - testRegex: '(/src/admin/.*\\.(test|spec))\\.[jt]sx?$', - testTimeout: 15000, - transform: { - '^.+\\.(t|j)sx?$': ['@swc/jest'], - }, - verbose: true, -} diff --git a/package.json b/package.json index 9c8b62c18..f68f3a0dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "payload-monorepo", - "version": "3.0.0-alpha.39", + "version": "3.0.0-alpha.44", "private": true, "type": "module", "workspaces:": [ @@ -8,9 +8,10 @@ ], "scripts": { "build": "pnpm run build:core", + "obliterate-playwright-cache": "rm -rf ~/Library/Caches/ms-playwright && find /System/Volumes/Data/private/var/folders -type d -name 'playwright*' -exec rm -rf {} ++ && npx playwright install", "build:all": "turbo build", "build:core": "turbo build --filter \"!@payloadcms/plugin-*\"", - "build:plugins": "turbo build --filter \"@payloadcms/plugin-*\" --filter \"!@payloadcms/plugin-search\" --filter \"!@payloadcms/plugin-redirects\" --filter \"!@payloadcms/plugin-nested-docs\"", + "build:plugins": "turbo build --filter \"@payloadcms/plugin-*\"", "build:app": "next build", "build:app:analyze": "cross-env ANALYZE=true next build", "build:create-payload-app": "turbo build --filter create-payload-app", @@ -40,6 +41,7 @@ "clean:build": "find . \\( -type d \\( -name dist -o -name .cache -o -name .next -o -name .turbo \\) -o -type f -name tsconfig.tsbuildinfo \\) -not -path '*/node_modules/*' -exec rm -rf {} +", "clean:all": "find . \\( -type d \\( -name node_modules -o -name dist -o -name .cache -o -name .next -o -name .turbo \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} +", "dev": "cross-env node --no-deprecation ./test/dev.js", + "devsafe": "rm -rf .next && cross-env node --no-deprecation ./test/dev.js", "dev:generate-graphql-schema": "cross-env NODE_OPTIONS=--no-deprecation tsx ./test/generateGraphQLSchema.ts", "dev:generate-types": "cross-env NODE_OPTIONS=--no-deprecation tsx ./test/generateTypes.ts", "dev:postgres": "pnpm --filter payload run dev:postgres", @@ -70,7 +72,7 @@ "@next/bundle-analyzer": "^14.1.0", "@octokit/core": "^5.1.0", "@payloadcms/eslint-config": "workspace:*", - "@playwright/test": "1.42.1", + "@playwright/test": "^1.42.1", "@swc/cli": "^0.1.62", "@swc/jest": "0.2.36", "@testing-library/jest-dom": "6.4.2", @@ -122,8 +124,8 @@ "nodemon": "3.0.3", "pino": "8.15.0", "pino-pretty": "10.2.0", - "playwright": "file:playwright-1.43.0-next.tgz", - "playwright-core": "file:playwright-core-1.43.0-next.tgz", + "playwright": "^1.42.1", + "playwright-core": "^1.42.1", "prettier": "^3.0.3", "prompts": "2.4.2", "qs": "6.11.2", @@ -155,7 +157,8 @@ }, "lint-staged": { "*.{js,jsx,ts,tsx}": [ - "prettier --write" + "prettier --write", + "eslint --cache --fix" ] }, "dependencies": { @@ -171,9 +174,7 @@ "graphql": "^16.8.1", "react": "$react", "react-dom": "$react-dom", - "typescript": "$typescript", - "playwright": "file:playwright-1.43.0-next.tgz", - "playwright-core": "file:playwright-core-1.43.0-next.tgz" + "typescript": "$typescript" }, "allowedDeprecatedVersions": { "uuid": "3.4.0", diff --git a/packages/create-payload-app/.swcrc b/packages/create-payload-app/.swcrc index d46b555fe..814897203 100644 --- a/packages/create-payload-app/.swcrc +++ b/packages/create-payload-app/.swcrc @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/swcrc", - "sourceMaps": "inline", + "sourceMaps": true, "jsc": { "target": "esnext", "parser": { diff --git a/packages/db-mongodb/.swcrc b/packages/db-mongodb/.swcrc index 15eb20bc1..14463f4b0 100644 --- a/packages/db-mongodb/.swcrc +++ b/packages/db-mongodb/.swcrc @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/swcrc", - "sourceMaps": "inline", + "sourceMaps": true, "jsc": { "target": "esnext", "parser": { diff --git a/packages/db-mongodb/package.json b/packages/db-mongodb/package.json index 9927176d9..15a0ee8a0 100644 --- a/packages/db-mongodb/package.json +++ b/packages/db-mongodb/package.json @@ -1,6 +1,6 @@ { "name": "@payloadcms/db-mongodb", - "version": "3.0.0-alpha.38", + "version": "3.0.0-alpha.44", "description": "The officially supported MongoDB database adapter for Payload - Update 2", "repository": "https://github.com/payloadcms/payload", "license": "MIT", diff --git a/packages/db-postgres/.swcrc b/packages/db-postgres/.swcrc index 15eb20bc1..14463f4b0 100644 --- a/packages/db-postgres/.swcrc +++ b/packages/db-postgres/.swcrc @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/swcrc", - "sourceMaps": "inline", + "sourceMaps": true, "jsc": { "target": "esnext", "parser": { diff --git a/packages/db-postgres/package.json b/packages/db-postgres/package.json index d60291c5a..d13802297 100644 --- a/packages/db-postgres/package.json +++ b/packages/db-postgres/package.json @@ -1,6 +1,6 @@ { "name": "@payloadcms/db-postgres", - "version": "3.0.0-alpha.38", + "version": "3.0.0-alpha.44", "description": "The officially supported Postgres database adapter for Payload", "repository": "https://github.com/payloadcms/payload", "license": "MIT", diff --git a/packages/db-postgres/src/connect.ts b/packages/db-postgres/src/connect.ts index 15a0e9679..7b02ad44f 100644 --- a/packages/db-postgres/src/connect.ts +++ b/packages/db-postgres/src/connect.ts @@ -1,14 +1,14 @@ import type { Payload } from 'payload' import type { Connect } from 'payload/database' -import { eq, sql } from 'drizzle-orm' +import { sql } from 'drizzle-orm' import { drizzle } from 'drizzle-orm/node-postgres' -import { numeric, timestamp, varchar } from 'drizzle-orm/pg-core' import pg from 'pg' -import prompts from 'prompts' import type { PostgresAdapter } from './types.js' +import { pushDevSchema } from './utilities/pushDevSchema.js' + const connectWithReconnect = async function ({ adapter, payload, @@ -93,70 +93,5 @@ export const connect: Connect = async function connect( ) return - const { pushSchema } = await import('drizzle-kit/payload') - - // This will prompt if clarifications are needed for Drizzle to push new schema - const { apply, hasDataLoss, statementsToExecute, warnings } = await pushSchema( - this.schema, - this.drizzle, - ) - - if (warnings.length) { - let message = `Warnings detected during schema push: \n\n${warnings.join('\n')}\n\n` - - if (hasDataLoss) { - message += `DATA LOSS WARNING: Possible data loss detected if schema is pushed.\n\n` - } - - message += `Accept warnings and push schema to database?` - - const { confirm: acceptWarnings } = await prompts( - { - name: 'confirm', - type: 'confirm', - initial: false, - message, - }, - { - onCancel: () => { - process.exit(0) - }, - }, - ) - - // Exit if user does not accept warnings. - // Q: Is this the right type of exit for this interaction? - if (!acceptWarnings) { - process.exit(0) - } - } - - await apply() - - // Migration table def in order to use query using drizzle - const migrationsSchema = this.pgSchema.table('payload_migrations', { - name: varchar('name'), - batch: numeric('batch'), - created_at: timestamp('created_at'), - updated_at: timestamp('updated_at'), - }) - - const devPush = await this.drizzle - .select() - .from(migrationsSchema) - .where(eq(migrationsSchema.batch, '-1')) - - if (!devPush.length) { - await this.drizzle.insert(migrationsSchema).values({ - name: 'dev', - batch: '-1', - }) - } else { - await this.drizzle - .update(migrationsSchema) - .set({ - updated_at: new Date(), - }) - .where(eq(migrationsSchema.batch, '-1')) - } + await pushDevSchema(this) } diff --git a/packages/db-postgres/src/createMigration.ts b/packages/db-postgres/src/createMigration.ts index 04be397b2..a75730ca0 100644 --- a/packages/db-postgres/src/createMigration.ts +++ b/packages/db-postgres/src/createMigration.ts @@ -3,10 +3,13 @@ import type { DrizzleSnapshotJSON } from 'drizzle-kit/payload' import type { CreateMigration } from 'payload/database' import fs from 'fs' +import { createRequire } from 'module' import prompts from 'prompts' import type { PostgresAdapter } from './types.js' +const require = createRequire(import.meta.url) + const migrationTemplate = ( upSQL?: string, downSQL?: string, @@ -60,7 +63,7 @@ export const createMigration: CreateMigration = async function createMigration( fs.mkdirSync(dir) } - const { generateDrizzleJson, generateMigration } = await import('drizzle-kit/payload') + const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload') const [yyymmdd, hhmmss] = new Date().toISOString().split('T') const formattedDate = yyymmdd.replace(/\D/g, '') diff --git a/packages/db-postgres/src/destroy.ts b/packages/db-postgres/src/destroy.ts index a1c10a77a..3ec3a4bce 100644 --- a/packages/db-postgres/src/destroy.ts +++ b/packages/db-postgres/src/destroy.ts @@ -2,7 +2,13 @@ import type { Destroy } from 'payload/database' import type { PostgresAdapter } from './types.js' +import { pushDevSchema } from './utilities/pushDevSchema.js' + export const destroy: Destroy = async function destroy(this: PostgresAdapter) { - // TODO: this hangs test suite for some reason - // await this.pool.end() + if (process.env.NODE_ENV !== 'production') { + await pushDevSchema(this) + } else { + // TODO: this hangs test suite for some reason + // await this.pool.end() + } } diff --git a/packages/db-postgres/src/migrate.ts b/packages/db-postgres/src/migrate.ts index dfbd6f92d..5c743fdea 100644 --- a/packages/db-postgres/src/migrate.ts +++ b/packages/db-postgres/src/migrate.ts @@ -3,6 +3,7 @@ import type { Payload } from 'payload' import type { Migration } from 'payload/database' import type { PayloadRequest } from 'payload/types' +import { createRequire } from 'module' import { commitTransaction, initTransaction, @@ -17,6 +18,8 @@ import { createMigrationTable } from './utilities/createMigrationTable.js' import { migrationTableExists } from './utilities/migrationTableExists.js' import { parseError } from './utilities/parseError.js' +const require = createRequire(import.meta.url) + export async function migrate(this: PostgresAdapter): Promise { const { payload } = this const migrationFiles = await readMigrationFiles({ payload }) @@ -82,7 +85,7 @@ export async function migrate(this: PostgresAdapter): Promise { } async function runMigrationFile(payload: Payload, migration: Migration, batch: number) { - const { generateDrizzleJson } = await import('drizzle-kit/payload') + const { generateDrizzleJson } = require('drizzle-kit/payload') const start = Date.now() const req = { payload } as PayloadRequest diff --git a/packages/db-postgres/src/utilities/pushDevSchema.ts b/packages/db-postgres/src/utilities/pushDevSchema.ts new file mode 100644 index 000000000..1de931beb --- /dev/null +++ b/packages/db-postgres/src/utilities/pushDevSchema.ts @@ -0,0 +1,83 @@ +import { eq } from 'drizzle-orm' +import { numeric, timestamp, varchar } from 'drizzle-orm/pg-core' +import { createRequire } from 'module' +import prompts from 'prompts' + +import type { PostgresAdapter } from '../types.js' + +const require = createRequire(import.meta.url) + +/** + * Pushes the development schema to the database using Drizzle. + * + * @param {PostgresAdapter} db - The PostgresAdapter instance connected to the database. + * @returns {Promise} - A promise that resolves once the schema push is complete. + */ +export const pushDevSchema = async (db: PostgresAdapter) => { + const { pushSchema } = require('drizzle-kit/payload') + + // This will prompt if clarifications are needed for Drizzle to push new schema + const { apply, hasDataLoss, statementsToExecute, warnings } = await pushSchema( + db.schema, + db.drizzle, + ) + + if (warnings.length) { + let message = `Warnings detected during schema push: \n\n${warnings.join('\n')}\n\n` + + if (hasDataLoss) { + message += `DATA LOSS WARNING: Possible data loss detected if schema is pushed.\n\n` + } + + message += `Accept warnings and push schema to database?` + + const { confirm: acceptWarnings } = await prompts( + { + name: 'confirm', + type: 'confirm', + initial: false, + message, + }, + { + onCancel: () => { + process.exit(0) + }, + }, + ) + + // Exit if user does not accept warnings. + // Q: Is this the right type of exit for this interaction? + if (!acceptWarnings) { + process.exit(0) + } + } + + await apply() + + // Migration table def in order to use query using drizzle + const migrationsSchema = db.pgSchema.table('payload_migrations', { + name: varchar('name'), + batch: numeric('batch'), + created_at: timestamp('created_at'), + updated_at: timestamp('updated_at'), + }) + + const devPush = await db.drizzle + .select() + .from(migrationsSchema) + .where(eq(migrationsSchema.batch, '-1')) + + if (!devPush.length) { + await db.drizzle.insert(migrationsSchema).values({ + name: 'dev', + batch: '-1', + }) + } else { + await db.drizzle + .update(migrationsSchema) + .set({ + updated_at: new Date(), + }) + .where(eq(migrationsSchema.batch, '-1')) + } +} diff --git a/packages/graphql/.swcrc b/packages/graphql/.swcrc index 15eb20bc1..14463f4b0 100644 --- a/packages/graphql/.swcrc +++ b/packages/graphql/.swcrc @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/swcrc", - "sourceMaps": "inline", + "sourceMaps": true, "jsc": { "target": "esnext", "parser": { diff --git a/packages/graphql/package.json b/packages/graphql/package.json index dcdb6632e..b1468d0dc 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -1,6 +1,6 @@ { "name": "@payloadcms/graphql", - "version": "3.0.0-alpha.38", + "version": "3.0.0-alpha.44", "main": "./src/index.ts", "types": "./src/index.d.ts", "type": "module", diff --git a/packages/live-preview-react/.swcrc b/packages/live-preview-react/.swcrc index 15eb20bc1..14463f4b0 100644 --- a/packages/live-preview-react/.swcrc +++ b/packages/live-preview-react/.swcrc @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/swcrc", - "sourceMaps": "inline", + "sourceMaps": true, "jsc": { "target": "esnext", "parser": { diff --git a/packages/live-preview/.swcrc b/packages/live-preview/.swcrc index 15eb20bc1..14463f4b0 100644 --- a/packages/live-preview/.swcrc +++ b/packages/live-preview/.swcrc @@ -1,6 +1,6 @@ { "$schema": "https://json.schemastore.org/swcrc", - "sourceMaps": "inline", + "sourceMaps": true, "jsc": { "target": "esnext", "parser": { diff --git a/packages/next/.swcrc b/packages/next/.swcrc index 15eb20bc1..696835f5d 100644 --- a/packages/next/.swcrc +++ b/packages/next/.swcrc @@ -1,12 +1,22 @@ { "$schema": "https://json.schemastore.org/swcrc", - "sourceMaps": "inline", + "sourceMaps": true, "jsc": { "target": "esnext", "parser": { "syntax": "typescript", "tsx": true, "dts": true + }, + "experimental": { + "plugins": [ + [ + "swc-plugin-transform-remove-imports", + { + "test": "\\.(scss|css)$" + } + ] + ] } }, "module": { diff --git a/packages/next/package.json b/packages/next/package.json index f115f538f..bc725b05d 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,6 +1,6 @@ { "name": "@payloadcms/next", - "version": "3.0.0-alpha.39", + "version": "3.0.0-alpha.44", "main": "./src/index.ts", "types": "./src/index.d.ts", "type": "module", @@ -8,9 +8,10 @@ "@payloadcms/next": "./dist/bin/index.js" }, "scripts": { - "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types", + "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types && pnpm build:webpack && rm dist/prod/index.js", "build:swc": "swc ./src -d ./dist --config-file .swcrc", "build:types": "tsc --emitDeclarationOnly --outDir dist", + "build:webpack": "webpack --config webpack.config.js", "clean": "rimraf {dist,*.tsbuildinfo}", "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" \"src/app/api/**\" dist/ && pnpm copyfiles:api", "copyfiles:api": "copyfiles -u 1 \"src/app/(payload)/**\" dist/template", @@ -50,7 +51,18 @@ "@types/react": "18.2.15", "@types/react-dom": "18.2.7", "@types/ws": "^8.5.10", - "payload": "workspace:*" + "css-loader": "^6.10.0", + "css-minimizer-webpack-plugin": "^6.0.0", + "mini-css-extract-plugin": "1.6.2", + "payload": "workspace:*", + "postcss-loader": "^8.1.1", + "postcss-preset-env": "^9.5.0", + "sass-loader": "^14.1.1", + "swc-loader": "^0.2.6", + "swc-plugin-transform-remove-imports": "^1.12.1", + "terser-webpack-plugin": "^5.3.10", + "webpack": "^5.78.0", + "webpack-cli": "^5.1.4" }, "dependencies": { "@dnd-kit/core": "6.0.8", @@ -79,6 +91,11 @@ "main": "./dist/exports/index.js", "types": "./dist/exports/index.d.ts", "exports": { + "./css": { + "import": "./dist/prod/styles.css", + "require": "./dist/prod/styles.css", + "default": "./dist/prod/styles.css" + }, "./withPayload": { "import": "./dist/withPayload.js", "require": "./dist/withPayload.js", diff --git a/packages/next/src/layouts/Root/index.tsx b/packages/next/src/layouts/Root/index.tsx index 7b68f201a..2dd69425c 100644 --- a/packages/next/src/layouts/Root/index.tsx +++ b/packages/next/src/layouts/Root/index.tsx @@ -1,6 +1,5 @@ import type { SanitizedConfig } from 'payload/types' -import { auth } from '@payloadcms/next/utilities/auth' import { translations } from '@payloadcms/translations/client' import { RootProvider, buildComponentMap } from '@payloadcms/ui' import '@payloadcms/ui/scss/app.scss' @@ -11,6 +10,7 @@ import React from 'react' import 'react-toastify/dist/ReactToastify.css' import { ClearRouteCache } from '../../elements/ClearRouteCache/index.js' +import { auth } from '../../utilities/auth.js' import { getPayload } from '../../utilities/getPayload.js' import { getRequestLanguage } from '../../utilities/getRequestLanguage.js' import { DefaultEditView } from '../../views/Edit/Default/index.js' diff --git a/packages/next/src/scss/app.scss b/packages/next/src/scss/app.scss index 690f201c5..308370552 100644 --- a/packages/next/src/scss/app.scss +++ b/packages/next/src/scss/app.scss @@ -1,5 +1,5 @@ -@import 'fonts'; -@import 'styles'; +@import './fonts.scss'; +@import './styles.scss'; @import './toastify.scss'; @import './colors.scss'; diff --git a/packages/next/src/utilities/getPayload.ts b/packages/next/src/utilities/getPayload.ts index 83522a49e..b32ef6f18 100644 --- a/packages/next/src/utilities/getPayload.ts +++ b/packages/next/src/utilities/getPayload.ts @@ -12,6 +12,10 @@ if (!cached) { } export const getPayload = async (options: InitOptions): Promise => { + if (!options?.config) { + throw new Error('Error: the payload config is required for getPayload to work.') + } + if (cached.payload) { const config = await options.config @@ -47,7 +51,8 @@ export const getPayload = async (options: InitOptions): Promise => { if (process.env.NODE_ENV !== 'production') { try { - const ws = new WebSocket('ws://localhost:3000/_next/webpack-hmr') + const port = process.env.PORT || '3000' + const ws = new WebSocket(`ws://localhost:${port}/_next/webpack-hmr`) ws.onmessage = (event) => { if (typeof event.data === 'string') { diff --git a/packages/next/src/views/List/Default/Cell/cellTypes.spec.tsx b/packages/next/src/views/List/Default/Cell/cellTypes.spec.tsx deleted file mode 100644 index f8a5fc318..000000000 --- a/packages/next/src/views/List/Default/Cell/cellTypes.spec.tsx +++ /dev/null @@ -1,172 +0,0 @@ -import { render } from '@testing-library/react' -import React from 'react' - -import type { BlockField, DateField, SelectField } from 'payload/types' - -import { BlocksCell } from './fields/Blocks' -import { Checkbox } from './fields/Checkbox' -import { DateCell } from './fields/Date' -import { Select } from './fields/Select' -import { Textarea } from './fields/Textarea' - -jest.mock('../../../../utilities/Config', () => ({ - useConfig: () => ({ admin: { dateFormat: 'MMMM do yyyy, h:mm a' } }), -})) - -jest.mock('../../../../providers/Translation', () => ({ - useTranslation: () => ({ t: (string) => string }), -})) - -describe('Cell Types', () => { - describe('Blocks', () => { - const field: BlockField = { - blocks: [ - { - fields: [], - labels: { - plural: 'Numbers', - singular: 'Number', - }, - slug: 'number', - }, - ], - label: 'Blocks Content', - labels: { - plural: 'Blocks Content', - singular: 'Block', - }, - name: 'blocks', - type: 'blocks', - } - - it('renders multiple', () => { - const data = [{ blockType: 'number' }, { blockType: 'number' }] - const { container } = render() - const el = container.querySelector('span') - expect(el).toHaveTextContent('2 Blocks Content - Number, Number') - }) - - it('renders zero', () => { - const data = [] - const { container } = render() - const el = container.querySelector('span') - expect(el).toHaveTextContent('0 Blocks Content') - }) - - it('renders "and X more" if over maximum of 5', () => { - const data = [ - { blockType: 'number' }, - { blockType: 'number' }, - { blockType: 'number' }, - { blockType: 'number' }, - { blockType: 'number' }, - { blockType: 'number' }, - ] - - const { container } = render() - const el = container.querySelector('span') - expect(el).toHaveTextContent('fields:itemsAndMore') - }) - }) - - describe('Date', () => { - const field: DateField = { - admin: { - date: { - pickerAppearance: 'dayOnly', - }, - }, - name: 'dayOnly', - type: 'date', - } - - it('renders date', () => { - const timeStamp = '2020-10-06T14:07:39.033Z' - const { container } = render() - const dateMatch = /October\s6th\s2020,\s\d{1,2}:07\s[A|P]M/ // Had to account for timezones in CI - const el = container.querySelector('span') - expect(el.textContent).toMatch(dateMatch) - }) - - it('handles undefined', () => { - const timeStamp = undefined - const { container } = render() - const el = container.querySelector('span') - expect(el.textContent).toBe('') - }) - }) - - describe('Checkbox', () => { - it('renders true', () => { - const { container } = render() - const el = container.querySelector('span') - expect(el).toHaveTextContent('true') - }) - it('renders false', () => { - const { container } = render() - const el = container.querySelector('span') - expect(el).toHaveTextContent('false') - }) - }) - - describe('Textarea', () => { - it('renders data', () => { - const { container } = render(