Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Testing Suite to Work Out of the Box #12

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install
- run: yarn build

- name: Install root dependencies
run: yarn install

- name: Build
run: yarn build

- name: Install dev dependencies
run: |
cd dev
yarn install

- name: Set up environment variables
run: |
cd dev
echo "DATABASE_URI=mongodb://127.0.0.1:27017/test" >> .env
echo "PAYLOAD_SECRET=hellohereisasecretforyou" >> .env

- name: Run tests
run: |
yarn test
2 changes: 1 addition & 1 deletion dev/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
verbose: true,
testEnvironment: 'node',
transform: {
'^.+\\.(t|j)sx?$': '<rootDir>/node_modules/@swc/jest',
'^.+\\.(t|j)sx?$': '@swc/jest',
},
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
Expand Down
14 changes: 8 additions & 6 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@
"build": "yarn copyfiles && yarn build:payload && yarn build:server",
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
"test": "jest --forceExit --detectOpenHandles",
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema",
"payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload"
},
"dependencies": {
"@payloadcms/bundler-webpack": "^1.0.0",
"@payloadcms/db-mongodb": "^1.0.0",
"@payloadcms/plugin-cloud": "^2.0.0",
"@payloadcms/plugin-cloud": "^3.0.2",
"@payloadcms/richtext-slate": "^1.0.0",
"cross-env": "^7.0.3",
"dotenv": "^8.2.0",
"dotenv": "^16.4.5",
"express": "^4.17.1",
"payload": "^2.0.0"
"mongodb-memory-server": "^10.0.0",
"payload": "^2.27.0"
},
"devDependencies": {
"@types/express": "^4.17.9",
"copyfiles": "^2.4.1",
"nodemon": "^2.0.6",
"ts-node": "^9.1.1",
"nodemon": "^3.1.4",
"ts-node": "^10.9.2",
"typescript": "^4.8.4"
}
}
}
16 changes: 12 additions & 4 deletions dev/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ describe('Plugin tests', () => {
let server: Server

beforeAll(async () => {
await start({ local: true })
})
server = await start()
// Allow Payload to fully start
await new Promise(resolve => setTimeout(resolve, 1000))
}, 30000)

afterAll(async () => {
server.close()
await mongoose.connection.dropDatabase()
await mongoose.connection.close()
server.close()
})
}, 10000)

// Add tests to ensure that the plugin works as expected

// Example test to check for seeded data
it('seeds data accordingly', async () => {
await payload.create({
collection: 'new-collection',
data: {
title: 'Seeded title',
},
})
const newCollectionQuery = await payload.find({
collection: 'new-collection',
sort: 'createdAt',
Expand Down
10 changes: 5 additions & 5 deletions dev/src/payload.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { buildConfig } from 'payload/config';
import path from 'path';
import Users from './collections/Users';
import Examples from './collections/Examples';
import { buildConfig } from 'payload/config'
import path from 'path'
import Users from './collections/Users'
import Examples from './collections/Examples'
import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { webpackBundler } from '@payloadcms/bundler-webpack'
import { slateEditor } from '@payloadcms/richtext-slate'
import { samplePlugin } from '../../src/index'
import { samplePlugin } from '../../dist'

export default buildConfig({
admin: {
Expand Down
11 changes: 9 additions & 2 deletions dev/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Server } from 'http'
import express from 'express'
import payload from 'payload'
import { InitOptions } from 'payload/config'
Expand All @@ -23,7 +24,13 @@ export const start = async (args?: Partial<InitOptions>) => {

// Add your own express routes here

app.listen(3000)
return new Promise<Server>(resolve => {
const server = app.listen(3000, () => {
resolve(server)
})
})
}

start()
if (require.main === module) {
start()
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"eslint-plugin-import": "2.25.4",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^29.7.0",
"payload": "^2.0.14",
"payload": "^2.27.0",
"prettier": "^2.7.1",
"react": "^18.0.0",
"typescript": "^4.8.4",
Expand Down
Loading