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

tests: add integration and unit test suites #1

Open
4 tasks
gamemaker1 opened this issue Oct 8, 2022 · 7 comments
Open
4 tasks

tests: add integration and unit test suites #1

gamemaker1 opened this issue Oct 8, 2022 · 7 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed tests Improving tests

Comments

@gamemaker1
Copy link
Contributor

Overview

The integration test suite should simply test each and every API - ensuring all possible successful responses, error responses and server crash cases are covered.

The unit test suite should test every function in the utilities/ and services/ folders.

Tasks

  • Add integration test suite for each API.
  • Add unit tests for utility functions.
  • Add unit tests for services.
  • Ensure coverage is close to 95% using c8

Each of these tasks can be completed in a separate PR. The last task (regarding coverage) should be completed after the first 3.

If you wish to take up this issue, reply to it below so I can assign you to it. If you are stuck/need any help, you could ask me here itself :)

@gamemaker1 gamemaker1 added good first issue Good for newcomers help wanted Extra attention is needed tests Improving tests labels Oct 8, 2022
@TechManTejas
Copy link

Screenshot (261)

Hi! I have taken this issue, I imported the smoke.ts file in server.ts and then ran the following commands:-

  1. pnpm install
  2. node build/server.ts

Doing so I got the above error. Currently, how are you testing things writting in smoke.ts file? And are you getting the same error as well?

Also I have figured out that we get almost only 4-5 ServerErrors/Responses 3 out of which are covered in smoke.ts

@gamemaker1
Copy link
Contributor Author

Hi!

Thanks for taking up the issue :)

You don't need to import the test file anywhere, the tests are run using ava. Run pnpm test to run them.

To add the unit tests, simply add another file in the tests/suites/unit.ts, similar to the smoke test file.

Once you have added tests to the tests/suites/unit.ts, you can run them using pnpm test.

@TechManTejas
Copy link

Okay thanks for this I'll update on this soon

@TechManTejas
Copy link

Hello! When I run the command pnpm test I get the following errors (there is a long chain of error)
Tried solving this but not getting anything.

Is it issue with version or am I missing something here?

`source\server.ts:1:20
✖ 1:20 Delete ␍ prettier/prettier
✖ 2:75 Delete ␍ prettier/prettier
✖ 3:75 Delete ␍ prettier/prettier
✖ 4:9 Delete ␍ prettier/prettier
✖ 5:1 Delete ␍ prettier/prettier
✖ 6:43 Delete ␍ prettier/prettier
✖ 7:47 Delete ␍ prettier/prettier
✖ 8:47 Delete ␍ prettier/prettier
✖ 9:1 Delete ␍ prettier/prettier
✖ 10:76 Delete ␍ prettier/prettier
✖ 11:13 Delete ␍ prettier/prettier
✖ 12:23 Delete ␍ prettier/prettier
✖ 13:9 Delete ␍ prettier/prettier
✖ 14:30 Delete ␍ prettier/prettier
✖ 15:3 Delete ␍ prettier/prettier
✖ 16:63 Delete ␍ prettier/prettier
✖ 17:55 Delete ␍ prettier/prettier
✖ 18:1 Delete ␍ prettier/prettier
✖ 19:27 Delete ␍ prettier/prettier
✖ 20:72 Delete ␍ prettier/prettier

test\helpers\fixtures.ts:1:29
✖ 1:29 Delete ␍ prettier/prettier
✖ 2:57 Delete ␍ prettier/prettier
✖ 3:1 Delete ␍ prettier/prettier
✖ 4:39 Delete ␍ prettier/prettier
✖ 5:1 Delete ␍ prettier/prettier
✖ 6:4 Delete ␍ prettier/prettier
✖ 7:74 Delete ␍ prettier/prettier
✖ 8:3 Delete ␍ prettier/prettier
✖ 9:51 Delete ␍ prettier/prettier
✖ 10:3 Delete ␍ prettier/prettier
✖ 11:53 Delete ␍ prettier/prettier
✖ 12:4 Delete ␍ prettier/prettier
✖ 13:49 Delete ␍ prettier/prettier
✖ 14:52 Delete ␍ prettier/prettier

source\handlers\index.ts:1:28
✖ 1:28 Delete ␍ prettier/prettier
✖ 2:44 Delete ␍ prettier/prettier
✖ 3:1 Delete ␍ prettier/prettier
✖ 4:42 Delete ␍ prettier/prettier
✖ 5:1 Delete ␍ prettier/prettier
✖ 6:26 Delete ␍ prettier/prettier
✖ 7:11 Delete ␍ prettier/prettier
✖ 8:2 Delete ␍ prettier/prettier

672 errors
 ELIFECYCLE  Command failed with exit code 1.
ERROR: "test:lint" exited with 1.
 ELIFECYCLE  Test failed. See above for more details.`

@gamemaker1
Copy link
Contributor Author

gamemaker1 commented Dec 3, 2022

These are lint errors, you can fix them by running pnpm test:lint -- --fix. They are happening because Windows inserts a CRLF character when you hit enter, while the linter expects only an LF character (which is the default on Mac and Linux). You can change this behaviour in VSCode if you want.

Also, to run only the tests instead of the linter as well, you can add a command in the scripts section of package.json below the test: smoke command, like test:unit to run only the unit tests:

"test:unit": "ava --match unit*",

@TechManTejas
Copy link

Thanks a lot for this! from what I understood I have added more testcases in unit.ts file in the test/suites/ folder. If there is any issue with that then please let me know.

@gamemaker1
Copy link
Contributor Author

Yes, that's correct :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed tests Improving tests
Projects
None yet
Development

No branches or pull requests

2 participants