Comments (9)
@iambumblehead "pnp" (yarn feature, no node_modules on the disk) != "pnpm" (package manager), so undefined is expected.
from esmock.
Thanks for opening the issue. I don't use pnpm myself and the person who added pnpm support hasn't been around lately @koshic
The main file using pnpm resolver is here https://github.com/iambumblehead/esmock/blob/main/src/pnpResolver.js
from esmock.
the demo you made looks great and would probably be a good thing to copy into the esmock tests. It needs this, however,
diff --git a/package.json b/package.json
index bcd50f7..1cc3c44 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
"test": "TSIMP_PROJECT=./test/tsconfig.json node --import tsimp/import --test-reporter spec --test 'test/example.test.ts'"
},
"dependencies": {
- "@nestjs/core": "^10.3.8"
+ "@nestjs/core": "^10.3.8",
"@nestjs/platform-express": "^10.3.8"
},
"devDependencies": {
There are many esmock tests, but currently no tests for pnpm specifically
from esmock.
failed test output here looks like this btw
> test
> TSIMP_PROJECT=./test/tsconfig.json node --import tsimp/import --test-reporter spec --test 'test/example.test.ts'
[Nest] 48166 - 2024/05/03 7:56:54 LOG [NestFactory] Starting Nest application...
[Nest] 48166 - 2024/05/03 7:56:54 ERROR [ExceptionHandler] metatype is not a constructor
TypeError: metatype is not a constructor
at Injector.instantiateClass (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:365:19)
at callback (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:65:45)
at async Injector.resolveConstructorParams (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:144:24)
at async Injector.loadInstance (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:70:13)
at async Injector.loadProvider (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:97:9)
at async /home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/instance-loader.js:56:13
at async Promise.all (index 0)
at async InstanceLoader.createInstancesOfProviders (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/instance-loader.js:55:9)
at async /home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/instance-loader.js:40:13
at async Promise.all (index 1)
✖ test/example.test.ts (2044.283154ms)
'test failed'
from esmock.
@darcyrush both conditions at this pnpResolver.js line fail
const pnpapi = process.versions.pnp && (await import('pnpapi')).default
process.versions.pnp
is undefined
and pnpapi
is not found when it is imported. Any ideas how to resolve?
from esmock.
'nothing to add here, but any thoughts @darcyrush
(I don't know enough about these tools to offer any assistance or input)
from esmock.
adding console.log to esmockModule.js
shows the following (differing) paths are resolved for npm vs pnpm
pnpm
{
moduleId: '../src/example.js',
fileURL: 'file:///home/bumble/software/esmock-scoped-package/src/example.ts'
}
{
moduleId: '@nestjs/core',
fileURL: 'file:///home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/index.js'
}
npm
{
moduleId: '../src/example.js',
fileURL: 'file:///home/bumble/software/esmock-scoped-package/src/example.ts'
}
{
moduleId: '@nestjs/core',
fileURL: 'file:///home/bumble/software/esmock-scoped-package/node_modules/@nestjs/core/index.js'
}
changing the resolver removing realpath conversion; tests still fail with the same error TypeError: metatype is not a constructor
pnpm
{
moduleId: '../src/example.js',
fileURL: 'file:///home/bumble/software/esmock-scoped-package/src/example.ts'
}
{
moduleId: '@nestjs/core',
fileURL: 'file:///home/bumble/software/esmock-scoped-package/node_modules/@nestjs/core/index.js'
}
from esmock.
Per the finding in the previous comment, the error occurs regardless of how esmock resolves the modules so my hunch is that a similar symlink/truepath thing affects tsimp which possibly causes the issue.
from esmock.
failed test output here looks like this btw
> test
> TSIMP_PROJECT=./test/tsconfig.json node --import tsimp/import --test-reporter spec --test 'test/example.test.ts'
[Nest] 48166 - 2024/05/03 7:56:54 LOG [NestFactory] Starting Nest application...
[Nest] 48166 - 2024/05/03 7:56:54 ERROR [ExceptionHandler] metatype is not a constructor
TypeError: metatype is not a constructor
at Injector.instantiateClass (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:365:19)
at callback (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:65:45)
at async Injector.resolveConstructorParams (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:144:24)
at async Injector.loadInstance (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:70:13)
at async Injector.loadProvider (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/injector.js:97:9)
at async /home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/instance-loader.js:56:13
at async Promise.all (index 0)
at async InstanceLoader.createInstancesOfProviders (/home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/instance-loader.js:55:9)
at async /home/bumble/software/esmock-scoped-package/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/injector/instance-loader.js:40:13
at async Promise.all (index 1)
✖ test/example.test.ts (2044.283154ms)
'test failed'
Yes, this is output for the test failing due to the mock not taking effect. Apologies, I should have stated that in the issue. The test and test case implementation itself is nonsensical, but I couldn't find a more simple name-spaced package to use as a better example.
Thank you for taking the time to look into this. Before opening an issue with tsimp
, I wanted to see if other TS runners were affected so I added both tsx
and ts-node
. It appears they are all impacted by this, which makes me think this may still be related to esmock
.
I updated the minimal reproduction repository to help streamline the investigation.
from esmock.
Related Issues (20)
- yarn pnp issues HOT 14
- Is it possible to mock json imports with assert? HOT 6
- Support Yarn PnP resolver out of the box HOT 11
- Get rid of old Node versions support HOT 8
- resolve error introduced with 2.5.2 HOT 10
- Error when mocking a file that exports an array. HOT 1
- c8 incorrect branch coverage; modules and `import` globals HOT 11
- how to mock globalThis HOT 4
- import('node:fs/promises') called within a library does not seem to be replaced HOT 30
- Path alias support HOT 1
- Unexpected strict mode reserved word syntax error when mocking express HOT 2
- incompatible with eslint-plugin-import HOT 3
- No support for subpath patterns? HOT 14
- Version 2.6.3 changed the way to mock libraries HOT 7
- ESMock seems to wrongfully alter Sinon stubs. HOT 1
- Using `import:` to mock globals messes up coverage (with c8) HOT 7
- [Question] Is it possible to mock indirect imports? HOT 10
- esmock static import for classes not matching HOT 3
- upstream issue, worker threads unable to register loader
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esmock.