Closed theinterned closed 3 years ago
As mentioned in the documentation, a browser must be able to execute the injected module. CommonJS
modules cannot be executed without additional tools (e.g. RequireJS
). We don't mind your PR to update the README
file.
Yes thank you @Dmitry-Ostashev i realize the issue is documented elsewhere. My comment is that this example is broken as it is currently implemented.
Are you suggesting the solution should be to use require.js
To load the mockdate
Module? How would that look?
Thank you.
@theinterned
The mockdate
module version ^2.0.5
is specified in the package.json
file, and the example works correctly. You can check this if you clone the repository and run this test. The problem is only related to mockdate@3.x. The mockdate version 2.x. works correctly. So, you can use the mockdate@2.x version or wait until this issue is fixed: https://github.com/boblauer/MockDate/issues/51.
Hey! Great news @boblauer restored the mockdate
UMD build in v3.0.3 🎉 So this recipe will continue to work without any changes.
I checked it on my side and found that script injection still doesn't work correctly:
TypeError: Cannot read property 'set' of undefined
.
Could you please check if mockdate
is working as a UMD module and let us know if it works without TestCafe?
@Dmitry-Ostashev you are right! I did some digging and it turns out Typescript's UMD build does not fallback to creating a global the way WebPack and Rollup's UMD builds do 😢 microsoft/TypeScript#8436
I've updated the issue over here https://github.com/boblauer/MockDate/issues/51#issuecomment-802037305 but for now, I suppose we can stick with the v2x version of mockdate.
@Dmitry-Ostashev I created a PR to update the README https://github.com/DevExpress/testcafe-examples/pull/50
Thank you 🙏
@theinterned Thank you for the clarification and PR. We'll review it soon.
Thanks you for the great recipe for mocking dates https://github.com/DevExpress/testcafe-examples/tree/master/examples/mock-date
I was able to get it to work using
mockdate@v2.0.5
. But the subsequentmockdate@v3x
breaks.mockdate@v3x
moves the package to typescript and it looks like the build target has changed from UMD to CJS.Attempting to load this CJS module via
clientScripts({ module: 'mockdate' })
(as in the example) results in an error:If there is a way to wrap this CJS module so that the mock-date example continues to work please let me know and I'd be happy to open a PR to update the example.
Otherwise, I would be happy to open a PR to update the
README
to specify usingmockdate@v2
.