nodejs.org icon indicating copy to clipboard operation
nodejs.org copied to clipboard

Switch from Jest to Node.js's Native Test Runner

Open ovflowd opened this issue 2 years ago • 15 comments

This issue about moving away from Jest to Node.js's Native Test Runner

Why

It would be great if we adopted Node.js's Test Runner (and moved away from Jest) because:

  • Way less dependencies
    • We only need JSDom to be set before the tests start running
      • https://github.com/nodejs/nodejs.org/blob/main/jest.setup.mjs
    • We can remove all the reporters/coverage generators and other dependencies
  • It's way faster and native to Node.js
  • It's natively ESM compatible which Jest isn't
  • We don't need snapshots nor any fancy Jest functionality

Migration

  • We still generate JUnit Test Reports for our GitHub Action
    • https://nodejs.org/api/test.html#test-reporters
  • Mocking of Modules cannot be done on "module name mapping" (https://github.com/nodejs/nodejs.org/blob/main/jest.config.mjs#L15-L17)
    • Meaning the mocks we have on __mocks__ folders need to be manually imported when used and need to be changed to use the Mocking API https://nodejs.org/api/test.html#mocking
  • Any usage of jest. APIs need to be replaced to Node Test Runners APIs
    • https://nodejs.org/api/test.html
  • Any usage of expect needs to be changed to assert (https://nodejs.org/api/assert.html)
  • Some pieces of code/tests might also need to be changed

ovflowd avatar Nov 16 '23 10:11 ovflowd

This issue is open to grabs by anyone interested :)

ovflowd avatar Nov 16 '23 10:11 ovflowd

Hey ! I'm trying to work on this but I got a problem. It's because node doesn't found ts file. So should we build ts before test ?

AugustinMauroy avatar Nov 17 '23 08:11 AugustinMauroy

Hey ! I'm trying to work on this but I got a problem. It's because node doesn't found ts file. So should we build ts before test ?

No. You want to use node --loader=ts-node/esm

Node.js supports custom loaders. (You need to add ts-node as a dev dependency btw)

ovflowd avatar Nov 17 '23 10:11 ovflowd

Or if you also need react compatibility. You might want to use the tsx loader (also a package)

ovflowd avatar Nov 17 '23 10:11 ovflowd

hummm interessing

AugustinMauroy avatar Nov 17 '23 13:11 AugustinMauroy

Have you considered ditching JSDOM + RTL in favor of Cypress/Playwright Component Testing?

TKDev7 avatar Nov 18 '23 01:11 TKDev7

Have you considered ditching JSDOM + RTL in favor of Cypress/Playwright Component Testing?

We already have Visual Regression Testing. The only tests we have for Components at the moment are for specific states.

And no, we dont want yet another tool and library and platform. Thank you.

ovflowd avatar Nov 18 '23 01:11 ovflowd

To clarify, our testing of components here is really bare bones, just to certify that for example, a select actually renders said items.

Adding browser testing (even if headless) is overkill for our needs.

So pretty much Node.js itself provides everything we need here with its native test runner; + we only want to unit test utilities, helpers, hooks and certain components that are stateful.

Everything else is already covered by Chromatic + Storybook

ovflowd avatar Nov 18 '23 01:11 ovflowd

@AugustinMauroy are you still working on this?

araujogui avatar Dec 01 '23 21:12 araujogui

@araujogui I'm stuck in my pr with the dom. If you want you can commit on my pr it is in "allow edit by maintainer" so in theory you could commit. It's up to you to finish it 😁

AugustinMauroy avatar Dec 01 '23 21:12 AugustinMauroy

@AugustinMauroy can you share the link on PR?

etroynov avatar Jan 13 '24 00:01 etroynov

its linked above https://github.com/nodejs/nodejs.org/pull/6129

bmuenzenmeyer avatar Jan 13 '24 02:01 bmuenzenmeyer

NEWS:

  • I've created a new, cleaner branch.
  • Nodejs Loaders to loading css-module; ts; jsx

AugustinMauroy avatar Apr 04 '24 10:04 AugustinMauroy

I would like to contribute (first time to this repo, Hello 👋🏻), but I can't see the PR @AugustinMauroy. Can you share the link so maybe I can run it locally and potentially review it to start familiarising myself with the code?

akdsco avatar Apr 04 '24 13:04 akdsco

I didn't make any pr for moment. But you can try on this branch any feedback is welcome

AugustinMauroy avatar Apr 04 '24 18:04 AugustinMauroy