Compare commits
3 Commits
v3.0.0-bet
...
allow-cust
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8308f9eb2e | ||
|
|
2ae5bc6ca2 | ||
|
|
70e71d7a18 |
@@ -49,6 +49,12 @@ The directory split up in this way specifically to reduce friction when creating
|
||||
|
||||
The following command will start Payload with your config: `yarn dev my-test-dir`. This command will start up Payload using your config and refresh a test database on every restart.
|
||||
|
||||
If you wish to use to your own Mongo database for the `test` directory instead of using the in memory database, all you need to do is add the following env vars to the `test/dev.ts` file:
|
||||
|
||||
- `process.env.NODE_ENV`
|
||||
- `process.env.PAYLOAD_TEST_MONGO_URL`
|
||||
- Simply set `process.env.NODE_ENV` to `test` and set `process.env.PAYLOAD_TEST_MONGO_URL` to your mongo url e.g. `mongodb://127.0.0.1/your-test-db`.
|
||||
|
||||
NOTE: It is recommended to add the test credentials (located in `test/credentials.ts`) to your autofill for `localhost:3000/admin` as this will be required on every nodemon restart. The default credentials are `dev@payloadcms.com` as E-Mail and `test` as password.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
@@ -11,7 +11,7 @@ const connectMongoose = async (
|
||||
logger: pino.Logger,
|
||||
): Promise<void | any> => {
|
||||
let urlToConnect = url;
|
||||
let successfulConnectionMessage = 'Connected to Mongo server successfully!';
|
||||
let successfulConnectionMessage = 'Connected to MongoDB server successfully!';
|
||||
|
||||
const connectionOptions: ConnectOptions & { useFacet: undefined } = {
|
||||
autoIndex: true,
|
||||
@@ -22,20 +22,23 @@ const connectMongoose = async (
|
||||
let mongoMemoryServer;
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
connectionOptions.dbName = 'payloadmemory';
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const getPort = require('get-port');
|
||||
if (process.env.PAYLOAD_TEST_MONGO_URL) {
|
||||
urlToConnect = process.env.PAYLOAD_TEST_MONGO_URL;
|
||||
} else {
|
||||
connectionOptions.dbName = 'payloadmemory';
|
||||
const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const getPort = require('get-port');
|
||||
|
||||
const port = await getPort();
|
||||
mongoMemoryServer = await MongoMemoryServer.create({
|
||||
instance: {
|
||||
dbName: connection.name,
|
||||
port,
|
||||
},
|
||||
});
|
||||
|
||||
urlToConnect = mongoMemoryServer.getUri();
|
||||
successfulConnectionMessage = 'Connected to in-memory Mongo server successfully!';
|
||||
const port = await getPort();
|
||||
mongoMemoryServer = await MongoMemoryServer.create({
|
||||
instance: {
|
||||
dbName: connection.name,
|
||||
port,
|
||||
},
|
||||
});
|
||||
urlToConnect = mongoMemoryServer.getUri();
|
||||
successfulConnectionMessage = 'Connected to in-memory MongoDB server successfully!';
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -46,10 +49,12 @@ const connectMongoose = async (
|
||||
await mongoose.connection.dropDatabase();
|
||||
logger.info('---- DROPPED DATABASE ----');
|
||||
}
|
||||
|
||||
logger.info(successfulConnectionMessage);
|
||||
} catch (err) {
|
||||
logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err);
|
||||
logger.error(
|
||||
`Error: cannot connect to MongoDB. Details: ${err.message}`,
|
||||
err,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import path from 'path';
|
||||
import mongoose from 'mongoose';
|
||||
import { Config as GeneratedTypes } from 'payload/generated-types';
|
||||
import { OperationArgs, Request as graphQLRequest } from 'graphql-http/lib/handler';
|
||||
import { SendMailOptions } from 'nodemailer';
|
||||
import { BulkOperationResult, Collection, CollectionModel } from './collections/config/types';
|
||||
import { EmailOptions, InitOptions, SanitizedConfig } from './config/types';
|
||||
import { TypeWithVersion } from './versions/types';
|
||||
@@ -17,7 +18,7 @@ import { ErrorHandler } from './express/middleware/errorHandler';
|
||||
import localOperations from './collections/operations/local';
|
||||
import localGlobalOperations from './globals/operations/local';
|
||||
import { decrypt, encrypt } from './auth/crypto';
|
||||
import { BuildEmailResult, Message } from './email/types';
|
||||
import { BuildEmailResult } from './email/types';
|
||||
import { Preferences } from './preferences/types';
|
||||
|
||||
import { Options as CreateOptions } from './collections/operations/local/create';
|
||||
@@ -88,7 +89,7 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
|
||||
|
||||
email: BuildEmailResult;
|
||||
|
||||
sendEmail: (message: Message) => Promise<unknown>;
|
||||
sendEmail: (message: SendMailOptions) => Promise<unknown>;
|
||||
|
||||
secret: string;
|
||||
|
||||
@@ -210,7 +211,7 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
|
||||
|
||||
serverInitTelemetry(this);
|
||||
|
||||
if (options.local !== false) {
|
||||
if (options.local !== false && this.mongoURL) {
|
||||
if (typeof options.onInit === 'function') await options.onInit(this);
|
||||
if (typeof this.config.onInit === 'function') await this.config.onInit(this);
|
||||
}
|
||||
@@ -260,11 +261,11 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
|
||||
* @param options
|
||||
* @returns Updated document(s)
|
||||
*/
|
||||
update<T extends keyof TGeneratedTypes['collections']>(options: UpdateByIDOptions<T>):Promise<TGeneratedTypes['collections'][T]>
|
||||
update<T extends keyof TGeneratedTypes['collections']>(options: UpdateByIDOptions<T>): Promise<TGeneratedTypes['collections'][T]>
|
||||
|
||||
update<T extends keyof TGeneratedTypes['collections']>(options: UpdateManyOptions<T>):Promise<BulkOperationResult<T>>
|
||||
update<T extends keyof TGeneratedTypes['collections']>(options: UpdateManyOptions<T>): Promise<BulkOperationResult<T>>
|
||||
|
||||
update<T extends keyof TGeneratedTypes['collections']>(options: UpdateOptions<T>):Promise<TGeneratedTypes['collections'][T] | BulkOperationResult<T>> {
|
||||
update<T extends keyof TGeneratedTypes['collections']>(options: UpdateOptions<T>): Promise<TGeneratedTypes['collections'][T] | BulkOperationResult<T>> {
|
||||
const { update } = localOperations;
|
||||
return update<T>(this, options);
|
||||
}
|
||||
@@ -274,11 +275,11 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
|
||||
* @param options
|
||||
* @returns Updated document(s)
|
||||
*/
|
||||
delete<T extends keyof TGeneratedTypes['collections']>(options: DeleteByIDOptions<T>):Promise<TGeneratedTypes['collections'][T]>
|
||||
delete<T extends keyof TGeneratedTypes['collections']>(options: DeleteByIDOptions<T>): Promise<TGeneratedTypes['collections'][T]>
|
||||
|
||||
delete<T extends keyof TGeneratedTypes['collections']>(options: DeleteManyOptions<T>):Promise<BulkOperationResult<T>>
|
||||
delete<T extends keyof TGeneratedTypes['collections']>(options: DeleteManyOptions<T>): Promise<BulkOperationResult<T>>
|
||||
|
||||
delete<T extends keyof TGeneratedTypes['collections']>(options: DeleteOptions<T>):Promise<TGeneratedTypes['collections'][T] | BulkOperationResult<T>> {
|
||||
delete<T extends keyof TGeneratedTypes['collections']>(options: DeleteOptions<T>): Promise<TGeneratedTypes['collections'][T] | BulkOperationResult<T>> {
|
||||
const { deleteLocal } = localOperations;
|
||||
return deleteLocal<T>(this, options);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import express from 'express';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import * as dotenv from 'dotenv';
|
||||
import payload from '../src';
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
@@ -30,7 +30,7 @@ const expressApp = express();
|
||||
const startDev = async () => {
|
||||
await payload.init({
|
||||
secret: uuid(),
|
||||
mongoURL: process.env.MONGO_URL || 'mongodb://127.0.0.1/payload',
|
||||
mongoURL: 'mongodb://127.0.0.1/payload',
|
||||
express: expressApp,
|
||||
email: {
|
||||
logMockCredentials: true,
|
||||
|
||||
Reference in New Issue
Block a user