Skip to content

feat: add unit test framework #13

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

Merged
merged 24 commits into from
Apr 10, 2025
Merged

feat: add unit test framework #13

merged 24 commits into from
Apr 10, 2025

Conversation

blva
Copy link
Collaborator

@blva blva commented Apr 8, 2025

  • adds jest as a testing framework

@blva blva marked this pull request as draft April 8, 2025 15:32
@gagik
Copy link
Collaborator

gagik commented Apr 9, 2025

Don't have strong feelings about this but we might have a better time using https://vitest.dev/ as it has built-in TypeScript and ESM support

@blva
Copy link
Collaborator Author

blva commented Apr 9, 2025

Don't have strong feelings about this but we might have a better time using https://vitest.dev/ as it has built-in TypeScript and ESM support

no strong opinions on my side as well, is it something we use in other js repos within MDB? if so I'm happy to shift!

@gagik
Copy link
Collaborator

gagik commented Apr 9, 2025

@blva It's newer so doesn't seem to be used by other projects much; I originally was gonna suggest mocha as that's what we use in other repos but actually jest seems simpler to setup for our purpose right now. Thinking more, maybe let's just stick to jest since the basic configuration looks already done anyhow

@blva
Copy link
Collaborator Author

blva commented Apr 9, 2025

@blva It's newer so doesn't seem to be used by other projects much; I originally was gonna suggest mocha as that's what we use in other repos but actually jest seems simpler to setup for our purpose right now. Thinking more, maybe let's just stick to jest since the basic configuration looks already done anyhow

cool! I'll continue with this then, I'd rather stick with technologies we've been working with for now, so jest it is and we can revisit!

@blva blva changed the title chore: add unit test framework feat: add unit test framework Apr 10, 2025
jest.config.js Outdated
@@ -0,0 +1,207 @@
/**
* For a detailed explanation regarding each configuration property, visit:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-generated via npm init jest@latest, we can clean up the comments

};
});

describe("Server initialization", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a smalll test for now so that we can add tests in next PRs and I'll slowly backfill tests

@blva blva marked this pull request as ready for review April 10, 2025 12:06
@blva blva marked this pull request as draft April 10, 2025 13:03
@blva blva marked this pull request as ready for review April 10, 2025 13:41
@blva blva requested a review from fmenezes April 10, 2025 13:43
@blva blva requested a review from Copilot April 10, 2025 13:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • package.json: Language not supported
  • tsconfig.jest.json: Language not supported

{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually contradicting main tsconfig.json, do we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the module, but I can update to esnext as it seems to work

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry actually, we can't use nodenext here, it doesn't work well w/ isolated modules, but esnext works

@blva blva requested a review from fmenezes April 10, 2025 14:01
@blva blva requested a review from gagik April 10, 2025 14:11
@gagik
Copy link
Collaborator

gagik commented Apr 10, 2025

@blva https://jestjs.io/docs/ecmascript-modules Seems like ESM support is experimental in Jest.
With us using "type": "module" (which we should because ESM is what's recommended now, CommonJS is more of a legacy thing). We can either
a) continue trying with Jest, I think some configuration is possible with ESM but it does seem like library mocking is not going to be great regardless with our setup.
b) maybe use Mocha + Chai + Sinon as they do support ESM and would also be more consistent with rest of DevTools. If you need help setting this up let me know, I could create a PR copying some of the mongosh configuration.

@gagik
Copy link
Collaborator

gagik commented Apr 10, 2025

@blva I opened #50 to try to see how Mocha goes, it actually seems simpler to set up because of the ESM stuff, wasn't too familiar with how jest was working with it. Let me know what you think

@blva blva closed this Apr 10, 2025
@blva
Copy link
Collaborator Author

blva commented Apr 10, 2025

@gagik works for me, can you fix the tests in the PR so we can merge to start adding mroe tests

@gagik gagik reopened this Apr 10, 2025
@gagik
Copy link
Collaborator

gagik commented Apr 10, 2025

@blva Actually upon further investigation, I think this is actually the best experience after all, mocha isn't much different 😅 Sorry for the bunch of back and forth, was just trying to make sure we're not regressing the TS setup but this should work best.

If we can rename __tests__/ => tests/, LGTM

@blva blva merged commit 3b5f0b4 into main Apr 10, 2025
2 checks passed
@blva blva deleted the unit-jest branch April 10, 2025 16:50
nirinchev added a commit that referenced this pull request Apr 10, 2025
* main:
  feat: refactor state, store it securely (#48)
  feat: add unit test framework (#13)
  chore: update readme (#51)

# Conflicts:
#	src/tools/mongodb/connect.ts
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.

3 participants