Open birkskyum opened 1 year ago
And trying to bypass this using deno --unstable run -A npm:jest
yields:
➜ deno --unstable run -A npm:jest
watchman warning: Recrawled this watch 5 times, most recently because:
MustScanSubDirs UserDroppedTo resolve, please review the information on
https://facebook.github.io/watchman/docs/troubleshooting.html#recrawl
To clear this warning, run:
`watchman watch-del '/Users/admin/repos/deno-kitchensink/nest-project' ; watchman watch-project '/Users/admin/repos/deno-kitchensink/nest-project'`
TypeError: this._child.send is not a function
at ChildProcessWorker.initialize (file:///Users/admin/repos/deno-kitchensink/nest-project/node_modules/.deno/jest-worker@29.7.0/node_modules/jest-worker/build/workers/ChildProcessWorker.js:169:17)
This is blocked by IPC support in node:child_process
module. I will be looking into that.
With deno 1.38, I can't get past this message:
➜ deno task --unstable test
Task test jest
Unstable API 'Deno.connect'. The --unstable flag must be provided.
@birkskyum out of curiosity - does it get any further if you create deno.json
with:
{
"unstable": ["net"]
}
?
Yes, with the deno.json I see:
➜ deno task test
Task test jest
TypeError: this._child.send is not a function
at ChildProcessWorker.initialize (file:///Users/admin/repos/nest-test/project/node_modules/.deno/jest-worker@29.7.0/node_modules/jest-worker/build/workers/ChildProcessWorker.js:169:17)
So we're back at the missing IPC support - good news is: we figured out a way forward to provide this mechanism and I'll be working on PoC for Unix systems this week.
You can run tests in-band using -i
which doesn't require a child-process worker.
$ deno --unstable run -A npm:jest -i
But Jest relies on v8.serialize which is not implemented by Deno. The compatibility notes mention that:
[these APIs] could be polyfilled, but due inherent lack of format stability between the V8 versions, the Deno team is considering requiring a special flag to use them.
with deno 1.39 i get:
➜ deno task test
Task test jest
Error: Not implemented: v8.serialize
at notImplemented (ext:deno_node/_utils.ts:9:9)
at serialize (node:v8:59:3)
at HasteMap._persist (file:///Users/admin/repos/deno-kitchensink/project/node_modules/.deno/jest-haste-map@29.7.0/node_modules/jest-haste-map/build/index.js:716:26)
at file:///Users/admin/repos/deno-kitchensink/project/node_modules/.deno/jest-haste-map@29.7.0/node_modules/jest-haste-map/build/index.js:380:16
at Object.runMicrotasks (ext:core/01_core.js:820:30)
at processTicksAndRejections (ext:deno_node/_next_tick.ts:53:10)
at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
at eventLoopTick (ext:core/01_core.js:188:21)
at async file:///Users/admin/repos/deno-kitchensink/project/node_modules/.deno/@jest+core@29.7.0/node_modules/@jest/core/build/cli/index.js:268:9
at async Promise.all (index 0)
I tried the same thing. Deno 1.43.1.
Cloned the typescript-starter like @birkskyum
TypeError: Class constructor Process cannot be invoked without 'new'
Since I'm invested in seeing NestJs properly supported by Deno or Bun (we have many apis in our corporation developed in nest) I did some additional testing.
So I created a brand new project with the nest cli and made the following changes to get as close to a runnable project as possible:
Running deno test yields these results:
Please verify these results by cloning: https://github.com/GerbenRampaart/deno-nestjs-vanilla
This error is decorator related right?
Ok, a bit weird. If I add "emitDecoratorMetadata": true to deno.json (which is not documented in the deno.json schema), it does work.
@birkskyum @bartlomieju
Integration test works, unit test works. Check the repo.
Further changes from vanilla nestjs project:
I think we can call this issue closed. Deno happily supports nestjs from the looks of it.
Did you find a solution to the "TypeError: Class constructor Process cannot be invoked without 'new'" issue?
https://github.com/denoland/deno/issues/20619#issuecomment-2093269631
Did you find a solution to the "TypeError: Class constructor Process cannot be invoked without 'new'" issue?
I didn't continue with the cloned variant of that typescript-starter of nestjs you started this issue with.
I figured that the @nest/cli also scaffolds a new vanilla nest project and with the most modern approach, the typescript-starter was initially committed a couple of years ago.
I tried making an new project with the cli approach instead just now, and I got the same TypeError: Class constructor Process cannot be invoked without 'new'
error when running test
.
I tried making an new project with the cli approach instead just now, and I got the same
TypeError: Class constructor Process cannot be invoked without 'new'
error when runningtest
.
Do you mind cloning my repo: https://github.com/GerbenRampaart/deno-nestjs-vanilla and share the output you get?
deno task test or deno test
and
deno task test:e2e
cloning my repo: https://github.com/GerbenRampaart/deno-nestjs-vanilla
These tests passed, both for test:e2e and test
So deno can run nestjs projects tailored specifically to deno, but it would be nice to be able to run existing projects with node compat.
I think this is a good starting point for me @birkskyum, maybe your explicit goal was to make sure Deno executed the jest code explicitly, and not use Deno.test.
But honestly I'm not going to chase that dragon, the Deno.test looks very clean and the core issue for me was that nestjs was supported as platform/framework, with working dependency injection and so on, which it does.
That's reasonable - my focus was indeed on making initial adoption of deno frictionless, but using/migrating to the deno primitives like you do is ofc. ideal.
Is there an official starter for deno, like the one you shared?
Is there an official starter for deno, like the one you shared?
If there is, I haven't found it. The nestjs people can be, with respect, ever so slightly stringent. If you open a Deno issue there it's closed before you can say 'ecmascript modu...'. I don't really blame them, they get mountains of questions and issues not caused by nestjs.
Regardless, I guess we're free to publish a Deno+Nest demo project for interested people to see anywhere, including somewhere in the Deno recipes in their docs.
For reference, I did just stumble across this issue #20595 who's repo (https://github.com/mfulton26/deno-nest) draws some of the same conclusions I did. And they re-wrote the test using a BDD approach (like jest is):
https://deno.land/std@0.224.0/testing/bdd.ts
While I haven't pulled that repo and ran the test, I guess this is also an approach.
It still involves somewhat altering the test a bit (the import), but less so than Deno.test.
Maybe that's closer to your out-of-the-box support for jest-like testing @birkskyum .
Thanks for the updates @GerbenRampaart @birkskyum, happy to hear that NestJS is now somewhat usable with Deno!
I tried making an new project with the cli approach instead just now, and I got the same
TypeError: Class constructor Process cannot be invoked without 'new'
error when runningtest
.
This error is gonna really painful to fix 😬 the problem seems to be that we use class Process
and the code of interest is using ES5 syntax to instantiate, eg.:
if (!(this instanceof Process)) {
Process.call(...)
}
I wonder if we should try to fix it upstream 🤔
I think it makes sense to fix jest-worker upstream, because it's so widely used. It's somewhat similar to this issue
Alright, I took the Deno 2 rc.2 for a spin, and could run this:
git clone https://github.com/nestjs/typescript-starter.git project
cd project
deno i
deno task test
deno task build
But what fails still is:
deno task test:e2e
➜ deno task test:e2e
Task test:e2e jest --config ./test/jest-e2e.json
FAIL test/app.e2e-spec.ts
AppController (e2e)
✕ / (GET) (7 ms)
● AppController (e2e) › / (GET)
TypeError: error sending request for url (http://127.0.0.1:0/): client error (Connect): tcp connect error: Can't assign requested address (os error 49): Can't assign requested address (os error 49)
at Test.end [as _end] (../node_modules/.deno/superagent@8.1.2/node_modules/superagent/src/node/index.js:1274:9)
at Test._end [as end] (../node_modules/.deno/superagent@8.1.2/node_modules/superagent/src/node/index.js:1000:8)
at Test.end (../node_modules/.deno/supertest@6.3.4/node_modules/supertest/lib/test.js:118:11)
at end (../node_modules/.deno/superagent@8.1.2/node_modules/superagent/src/request-base.js:285:12)
at undefined
at Test.Object.<anonymous>.RequestBase.then (../node_modules/.deno/superagent@8.1.2/node_modules/superagent/src/request-base.js:267:31)
at undefined
at Object.runMicrotasks (../ext:core/01_core.js:672:26)
at processTicksAndRejections (../ext:deno_node/_next_tick.ts:57:10)
at runNextTicks (../ext:deno_node/_next_tick.ts:75:3)
at eventLoopTick (../ext:core/01_core.js:182:21)
Repro:
git clone https://github.com/nestjs/typescript-starter.git project
(From Nest docs frontpage)cd project
deno task test
ordeno task --unstable test
ordeno --unstable task test
Expected:
Actual