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

mocha vs jest #629

Closed
LoicPoullain opened this issue Feb 9, 2020 · 7 comments
Closed

mocha vs jest #629

LoicPoullain opened this issue Feb 9, 2020 · 7 comments

Comments

@LoicPoullain
Copy link
Member

I've had several feedback from users preferring "jest" to "mocha". This issue is open so as to start on discussion on this. If you have used both and prefer one, feel free to give your opinion.

@geekflyer
Copy link

geekflyer commented Feb 15, 2020

ok, here's my perspective:
I've used both (in fact I've probably used mocha more than jest), and prefer jest nowadays because:

  • jest has a very good assertion library out of the box
  • jest as built-in snapshot testing (which I use a lot, in the backend)

Altogether Jest is just a better "batteries included" thing. With mocha one has to first make all those boring choices on top and hope they work well together.

Furthermore, while this isn't sooo much of a prio for me, most frontend folks, esp in React, use Jest and using the same testing library for both frontend and backend makes it easier to work on both.

Jest used to be immature and there was a time i definitely preferred mocha, but nowadays Jest my way to go.

@sinclairnick
Copy link
Contributor

I would vote Jest. Just migrated my Foal app from mocha to jest, and the more concise test interface is alone worth it. Haven't yet managed to set it up so it only tests changed files, but this is another reason why it would be better (unsure if mocha has this functionality)

@jondot
Copy link
Contributor

jondot commented Feb 27, 2020

@LoicPoullain I'd prefer Jest. Can you maybe scope the amount of work needed to convert? just in outline form. If it's small enough or reasonable enough maybe one of us (including myself) can give it a go.

@anonimusprogramus
Copy link
Contributor

Please keep going, been wacthing this all, I haven't used either Mocha or Jest.

@LoicPoullain
Copy link
Member Author

Thank you all for sharing your thoughts on this. We can work on adding a --jest flag to the createapp command. This would make foal createapp and foal generate <name> use jest instead of mocha.

Design

Using a flag has two advantages IMO:

  • It allows us to start testing Jest with Foal/TypeScript and see how it goes.
  • It does not break all existing documentation, examples and generators based on mocha.

Steps

To implement this, I think the best approach would be to go through these steps:

  1. Create a separate repo with an example of a FoalTS project with Jest configuration. This would allow us to discuss the difference possible choices and see how it works in practice.
  2. Once done, we will be able to update the generators with some tests. Version 1.9 refactors a lot of the CLI code so that it will be easier to implement.

Requirements

  • The e2e tests should be executed with the env variable NODE_ENV=e2e and the unit tests with the env variable NODE_ENV=test.
  • Watch mode should be available for both e2e and unit tests.
  • No use of webpack. I can't really go into the details of this orientation but, to sum up, many parts of the framework would break with webpack.
  • In version 2 of the framework, the CLI commands will be reduced and simplified: https://github.com/FoalTS/foal/blob/c54d27dd2f9d25282b6bbeee18414e674edd5ca3/packages/cli/src/generate/specs/app/package.json. Basing the proposition(s) on these commands would save us extra work (npm run build:test, npm run start:test, npm run test, npm run build:e2e, npm run start:e2e, npm run e2e).
  • Current testing commands are divided in two parts: the build (compiling and copying files) and the test run (mocha, jest). I have a preference to this approach (and not using ts-node for example) because it makes sure there is no difference between the production build that is deployed and the test build that is tested.

@jondot you seemed to be interested in contributing on this subject. Do you want to submit a proposition (i.e. a repo)?

@EmilCataranciuc
Copy link

Symfony has a very neat functionality called recipes. Maybe instead of adding flags for different tools and setup it would make more sense to enable foal CLI to support a similar feature. This way developers could even bundle foal distros under different recipes. Just to have an example of what Symfony devs achieve with the recipes have a look at API Platform and how it allows you to build a REST API in around 30 minutes.

@LoicPoullain
Copy link
Member Author

Seems that this issue is not active anymore. Closing it for now.

Feel free to leave comment if you want to submit a proposal.

@LoicPoullain LoicPoullain moved this to Done / Closed This Release in Issue tracking Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants