Skip to content

Fix unit tests - Backend#264

Closed
nickbeaird wants to merge 32 commits intohackforla:developmentfrom
nickbeaird:add_jest_from_develop
Closed

Fix unit tests - Backend#264
nickbeaird wants to merge 32 commits intohackforla:developmentfrom
nickbeaird:add_jest_from_develop

Conversation

@nickbeaird
Copy link
Contributor

@nickbeaird nickbeaird commented Aug 22, 2020

Goal: Get the tests working

The tests have been disabled for some time and there seems to be a growing number of regressions when pulling up the application. The goal of this projects was to get the tests working, which largely centered on setting up test frameworks for the development environment.

Work Done:

  • The backend was split into it's own directory. This was a requirement to get the test runners working in the backend. The errors were raised by two different test runners.
  • Implement a universal unit test runner. As the project is largely a react app, I aimed to get use the same test runner that is being used in the front end. Jest requires some additional and nuanced setup for backend Node purposes, which is largely caught in in-memory-mongodb setup.
  • Get working unit tests and write unit test examples
  • Get working integration tests for the API and write examples
  • Get documentation for developers to use their local database
  • Make the database for the automated tests be idempotent and not relate to their local development environments.

How to test that this work?

  1. Pull my branch locally
  • git remote add nickbeaird GIT REPO LINK
  • git fetch nickbeaird
  • git checkout nickbeaird/add_frontend_testing
  • Note that you now have a backend directory
  1. Add your .env file at the root directory to the backend directory

  2. Delete all of your package.json file and nod_modules directories

  3. Run npm install in the root, backend, and client directories.

  • cd root && npm install
  • cd client && npm install
  • cd ../backend && npm install
  1. Navigate to the backend directory and run the tests
  • npm run test (see package.json)

Moving the instantiation of the server away from the application itself
allows us to import the express app as a moodule and test it. This keeps
us from actually spinning up a server instance on every import.
The slack app is starting every time the application is initialized,
which is causing the tests to be unable to close. This work will be
refactored out here soon.
These test cases showcase being able to write unit test and integration
tests using the database, models, and api.
@nickbeaird nickbeaird changed the title Add jest from develop Fix unit tests Aug 23, 2020
This was referenced Aug 25, 2020
@nickbeaird nickbeaird changed the title Fix unit tests Fix unit tests - Backend Aug 25, 2020
@nickbeaird
Copy link
Contributor Author

This PR may be superseded by this PR here, #269

@nickbeaird nickbeaird closed this Aug 27, 2020
@nickbeaird nickbeaird reopened this Aug 27, 2020
@nickbeaird nickbeaird linked an issue Aug 27, 2020 that may be closed by this pull request
@nickbeaird nickbeaird closed this Aug 29, 2020
@nickbeaird nickbeaird deleted the add_jest_from_develop branch August 29, 2020 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spike: Frontend unit and end-2-end testing

2 participants