-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Tests failures ts-jest / export {} issue. #161
Comments
hi @omnisip , |
Node. source code directly. -- whatever we get from npm install. |
We are using JSDom. But it's in our test suite. |
hi @omnisip ,
Note here, that it is loading browser/esm, instead of just esm. browser/esm will only work in a browser, not Node. |
How do I fix that? It happens whenever I use jsdom. Also -- what's the difference between the bundles? |
The main difference between the bundles is that the one is built for Node.js and uses all Node.js features that are not available in a browser, such as http and https modules. In browser/esm, those modules are replaced with XmlHttpRequest, because http and https exist strictly in Node. There are other differences, but this is the main one. Is your app a CommonJs module or ES module? If you could share the package.json and tsconfig.json (if it's in TypeScript), it will help a lot. |
Hi, @AleksandrRogov |
@omnisip , @SerhiiYatsenko can you give me your node version please? The only difference I see between your tsconfig and mine in the PCF controls is that I set "module" to ES6 and "moduleResolution" to "node". Which makes sense because I dropped support for ES5 in v2. I just feel like jest does not understand that DynamicsWebApi is ES6 module and {
"extends": "./node_modules/pcf-scripts/tsconfig_base.json",
"compilerOptions": {
"typeRoots": ["node_modules/@types", "./types/**/*"],
"module": "ES6",
"moduleResolution": "node"
},
"exclude": ["node_modules"]
} Can you try including "module" and "moduleResolution" in your tsconfig? And I haven't used JSDom before, but it looks like that it brings support for browser features to Node, so including browser/esm should be ok, otherwise it would throw an error somewhere else. The main issue is that jest does not recognize "export" keyword. |
Any luck? We're still stuck on this. This is the only dependency with these issues. |
@omnisip as I mentioned before, the issue happens because jest does not "understand" Did some research on jest and it looks like it does not really have a good support for ESM. Can you try one of the suggestions I found for another library that had the same problem with jest? Basically, just add a module resolution to your # jest.config.js
module.exports {
moduleNameMapper: {
// Workaround for Jest having bad ESM support
'dynamics-web-api': require.resolve('dynamics-web-api'), You can find more info here (that's where I found this suggestion): uuidjs/uuid#451 (comment) |
Here are even more details: uuidjs/uuid#616 (comment) |
I think that worked, but created a new issue:
|
@omnisip you will need to mock Xrm Context that Dynamics provides. The library tries to access it so it can get the organization's server url. It will be similar to what I do here: https://github.com/AleksandrRogov/DynamicsWebApi/blob/5c0ec4c590bb456650ba35567c7db2214e3edb10/tests/stubs.js#L6C8-L6C8 |
@omnisip Just to clarify: only that getClientUrl needs to be mocked. No need to mock the whole Xrm object. |
Closing this, as I assume it is resolved. If you have any more questions feel free to post in the same issue. Thanks! |
DynamicsWebApi version
2.1.1
We have tried every thing we know how with ts-jest and tsconfig.json including esModuleInterop, among others, and dynamics-web-api is the only import that has the issue. Issue reproduces even in an empty test files and all it does is instantiate the DynamicsWebApi class.
FAIL PriceListItemGeneration/Components/Pricing/PricingPanel.spec.tsx
● Test suite failed to run
The text was updated successfully, but these errors were encountered: