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

Conversation

cgilly2fast
Copy link

Fix Testing Suite to Work Out of the Box and Add GitHub Workflow

This PR addresses issues with the testing suite to ensure it works correctly out of the box for the Payload CMS plugin template. It also adds a GitHub workflow to automatically run tests.

Changes

Updated Dependencies

  • Upgraded @payloadcms/plugin-cloud from ^2.0.0 to ^3.0.2
  • Upgraded dotenv from ^8.2.0 to ^16.4.5
  • Upgraded payload from ^2.0.0 to ^2.27.0
  • Added mongodb-memory-server version ^10.0.0
  • Upgraded nodemon from ^2.0.6 to ^3.1.4
  • Upgraded ts-node from ^9.1.1 to ^10.9.2

Testing Configuration

  • Updated jest.config.js to use @swc/jest for transformation
  • Modified plugin.spec.ts to improve test setup and teardown:
    • Added a delay after server start to ensure Payload is fully initialized
    • Increased the timeout for the beforeAll hook to 30 seconds
    • Increased the timeout for the afterAll hook to 10 seconds
    • Added example test for checking seeded data

Build and Development Scripts

  • Updated payload.config.ts to import the plugin from the dist directory instead of src
  • Modified server.ts to return a Promise resolving to the server instance, allowing for better test control

Added GitHub Workflow

  • Created .github/workflows/test.yml to run tests automatically:
    • Uses Ubuntu latest
    • Sets up Node.js 18.x
    • Installs dependencies for both root and dev directories
    • Sets up environment variables for testing
    • Runs the test suite

Other Improvements

  • Updated dev/package.json script with "test": "jest --forceExit --detectOpenHandles"
  • Ensured consistent formatting across files

Testing

The new GitHub workflow will automatically run tests on push and pull requests. You can also verify that the testing suite works correctly locally by running:

yarn install
yarn build
cd dev 
yarn install
cd ..
yarn test

All tests should pass without any configuration issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant