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

[Server] Testing order matters that DB.test.js is the first to be run #105

Closed
devYaoYH opened this issue Jun 19, 2020 · 1 comment · Fixed by #117
Closed

[Server] Testing order matters that DB.test.js is the first to be run #105

devYaoYH opened this issue Jun 19, 2020 · 1 comment · Fixed by #117
Assignees
Labels
Backend Stuff to do with express in `/server` Testing Writing Test/Framework to Test

Comments

@devYaoYH
Copy link
Collaborator

Potential test ordering fix for Jest:
jestjs/jest#6194 (comment)

Currently we are doing:

  1. Clear DB in yarn pretest script
  2. Populate DB in jest globalSetup script
  3. Run tests

OK:
DB.test.js -> routes.test.js
Problem:
routes.test.js -> DB.test.js as we are adding an item to Orders Collection in one of our tests in routes.test.js. This results in one test in DB.test.js to fail as we do not expect this added item.

Solutions:

  1. Avoid side effects by dropping this document after we assert it has been successfully added
  2. Refactor code such that we clear DB and re-populate in jest beforeAll for each test suite (but then DB.test.js isn't really that useful anymore?)

For now, I've taken the earlier approach

Originally posted by @devYaoYH in #104

@devYaoYH devYaoYH added Backend Stuff to do with express in `/server` Testing Writing Test/Framework to Test labels Jun 19, 2020
@devYaoYH devYaoYH changed the title Testing order matters that DB.test.js is the first to be run [Server] Testing order matters that DB.test.js is the first to be run Jun 19, 2020
@devYaoYH
Copy link
Collaborator Author

SGTM!
2# seems like a better approach in long run! Perhaps just copy over the DB from DB.test.js into a new one in beforeAll and then delete it in AfterAll. The items stay neat then.

Originally posted by @BhavyaLight in #104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Stuff to do with express in `/server` Testing Writing Test/Framework to Test
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants