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

test: migrate jest -> node:test

Open AugustinMauroy opened this issue 2 years ago • 20 comments

Description

Migrate jest to nodejs internal test runer

Validation

all test should pass

Related Issues

#6123

Check List

  • [X] I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • [ ] I have run npx turbo lint to ensure the code follows the style guide. And run npx turbo lint:fix to fix the style errors if necessary.
  • [ ] I have run npx turbo format to ensure the code follows the style guide.
  • [ ] I have run npx turbo test to check if all tests are passing.
  • NA I've covered new added functionality with unit tests if necessary.

AugustinMauroy avatar Nov 17 '23 20:11 AugustinMauroy

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 25, 2023 10:22pm

vercel[bot] avatar Nov 17 '23 20:11 vercel[bot]

hummmm something strange I din't get any error for other test (not migrated yet). I mean node didn't read-it but on junit.xml it's output error for these tests 🤔

AugustinMauroy avatar Nov 17 '23 20:11 AugustinMauroy

hummmm something strange I din't get any error for other test (not migrated yet).

I mean node didn't read-it

but on junit.xml it's output error for these tests 🤔

Wdym? Is it not generating junit.xml when passing the right args?

ovflowd avatar Nov 17 '23 20:11 ovflowd

Wdym? Is it not generating junit.xml when passing the right args?

on terminal it's doesn't output any error but on junit.xml it's write error. Alors if I remove **/__tests__/*.test.mjs there any issue it's display correctly

AugustinMauroy avatar Nov 17 '23 21:11 AugustinMauroy

huston we go a problem. TSX loader doesn't support jsx REF I'm deep diving @educandu/node-jsx-loader a jsx loader

AugustinMauroy avatar Nov 18 '23 09:11 AugustinMauroy

huston we go a problem. TSX loader doesn't support jsx REF I'm deep diving @educandu/node-jsx-loader a jsx loader

I'm deep diving @educandu/node-jsx-loader a jsx loader

Afaik it does... Why do you think it doesn't? It should support React natively :)

I even have seen users using it with React in the past (I also used it with React in the past, so I wonder what errors you're hitting?)

ovflowd avatar Nov 19 '23 11:11 ovflowd

@ovflowd I think there's been a misunderstanding. tsx and tsc are loaders that allow you to interpret typescript. But neither of them understands JSX. That's why I looked at @educandu/node-jsx-loader. It supports JSX but not TSX. So I'm still looking for what/how. Also if a component imports style with CSS module node will try to load it.

AugustinMauroy avatar Nov 20 '23 15:11 AugustinMauroy

@ovflowd I think there's been a misunderstanding. tsx and tsc are loaders that allow you to interpret typescript. But neither of them understands JSX. That's why I looked at @educandu/node-jsx-loader. It supports JSX but not TSX. So I'm still looking for what/how. Also if a component imports style with CSS module node will try to load it.

Again, you're wrong. tsx is a loader that supports JSX. tsc/esm is a loader that does not support JSX. tsx uses esbuild and supports jsx. You can even see that the codebase supports those extensions: https://github.com/search?q=repo%3Aprivatenumber%2Ftsx%20jsx&type=code

ovflowd avatar Nov 20 '23 16:11 ovflowd

gotcha !!!

AugustinMauroy avatar Nov 20 '23 17:11 AugustinMauroy

gotcha !!!

If you're still struggling, please feel free to share errors. We're here to help.

ovflowd avatar Nov 20 '23 18:11 ovflowd

Any progress over here? 👀

ovflowd avatar Nov 25 '23 11:11 ovflowd

I'ill come back in now I have time 😀

AugustinMauroy avatar Nov 25 '23 11:11 AugustinMauroy

I'm getting trouble with react test. with module css nodejs can't load file

AugustinMauroy avatar Nov 25 '23 22:11 AugustinMauroy

I'm getting trouble with react test.

with module css nodejs can't load file

Can you share the errors?

ovflowd avatar Nov 25 '23 23:11 ovflowd

I think we truly dont care about css imports; So probably we should stub/mock these imports... I know esbuild supports css and probably css modules by default, but I doubt it is something we really want to import.

ovflowd avatar Nov 25 '23 23:11 ovflowd

@nodejs/loaders does anyone here know how we can stub/mock part of the module resolution process?

More specifically some of our files import .css files but we definitely dont want to load them with the Node.js Test Runner (node:test) and we're using "--import=tsx" that adds a loader for TypeScript and React (JSX).

Should we make another loader just to stub these CSS imports or is there something else we can do here? Like a builtin functionality to simply stub these imports?

ovflowd avatar Nov 26 '23 00:11 ovflowd

I think I found a solution for my own question. https://github.com/coderaiser/mock-import

👆 this might help you, Augustin.

ovflowd avatar Nov 26 '23 00:11 ovflowd

(Im also assuming https://www.npmjs.com/package/sinon can do the trick) as the state of node:test mocking and spying is kinda supbar atm (the whole thing is still experimental. We could definitely raise a feature request on node core

cc @nodejs/test_runner)

ovflowd avatar Nov 26 '23 00:11 ovflowd

I use Testdouble to do this in a pure ESM environment.

JakobJingleheimer avatar Nov 26 '23 21:11 JakobJingleheimer

Lots of git conflicts are listed below...

cclauss avatar Jan 23 '24 12:01 cclauss

Closing because it's too old. And I can't rebase GitHub desktop just crash. an new branch is WIP https://github.com/nodejs/nodejs.org/tree/test-node if someone with write access can help. But let me know.

AugustinMauroy avatar Apr 04 '24 10:04 AugustinMauroy