feat: async plugins (#2030)

* feat: async plugins

* wip: async config

* fix: async config
This commit is contained in:
Jacob Fletcher
2023-02-13 10:46:55 -05:00
committed by GitHub
parent 11532857d2
commit 9f30553813
25 changed files with 218 additions and 119 deletions

1
test/plugins/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
media

40
test/plugins/config.ts Normal file
View File

@@ -0,0 +1,40 @@
import { buildConfig } from '../buildConfig';
import { devUser } from '../credentials';
export const pagesSlug = 'pages';
export default buildConfig({
collections: [
{
slug: 'users',
auth: true,
fields: [],
},
],
plugins: [
async (config) => ({
...config,
collections: [
...config.collections || [],
{
slug: pagesSlug,
fields: [
{
name: 'title',
type: 'text',
},
],
},
],
}),
],
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
});
},
});

View File

28
test/plugins/int.spec.ts Normal file
View File

@@ -0,0 +1,28 @@
import { initPayloadTest } from '../helpers/configHelpers';
import { RESTClient } from '../helpers/rest';
import configPromise, { pagesSlug } from './config';
import payload from '../../src';
require('isomorphic-fetch');
let client;
describe('Collections - Plugins', () => {
beforeAll(async () => {
const { serverURL } = await initPayloadTest({ __dirname, init: { local: false } });
const config = await configPromise;
client = new RESTClient(config, { serverURL, defaultSlug: pagesSlug });
await client.login();
});
it('created pages collection', async () => {
const { id } = await payload.create({
collection: pagesSlug,
data: {
title: 'Test Page',
},
});
expect(id).toEqual(expect.any(String));
});
});