-
Notifications
You must be signed in to change notification settings - Fork 203
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
Jest vs Bazel: Something is broken #5367
Conversation
Running the test in the new project via `yarn test` works just fine. However, running the same tests via ``` bazel test //language-support/ts/jest_vs_bazel:test ``` doesn't work. The test fails because it thinks the `ws.server` object is not an instance of class `Server`. This clearly contradicts the implementation of the `WS` class at https://github.com/romgain/jest-websocket-mock/blob/eb8324ff0d4fd1a09effd994cba142f240fb8f7a/src/websocket.ts#L48 My suspicion is that bazel somehow brings multiple versions of the `Server` class from `mock-socket` into scope. If you drill into `node_modules/mock-socket`, you'll see that `package.json` lists `"main": "./dist/mock-socket"` and there are five files in `dist`: - `mock-socket.amd.js` - `mock-socket.cjs.js` - `mock-socket.es.js` - `mock-socket.es.mjs` - `mock-socket.js` The is also `src/index.js` which exports a `Server` class. So, there's plenty of ooportunity for `bazel` to get confused. Despite that, I wonder how `jest` gets it right on its own but `bazel` manages to confuse `jest` to get it wrong under `bazel`'s guidance. CHANGELOG_BEGIN CHANGELOG_END
I've been able to reproduce this issue in isolation https://github.com/aherrmann/mock_class_mismatch using vanilla I've used the following
According to the output we are consistently loading the common-js versions under
while loading mixed versions under Bazel
However, this does not seem to be the cause of the issue. I've patched the According to jestjs/jest#2549 using |
@aherrmann Thanks for the progress report. Great work! This seems to be a very dire problem. 😿 Regarding |
closes #5367 This includes the fixes for the issues in jest that we’ve been seeing. changelog_begin changelog_end
closes #5367 This includes the fixes for the issues in jest that we’ve been seeing. changelog_begin changelog_end
* Upgrade rules_nodejs to version 1.6.0 closes #5367 This includes the fixes for the issues in jest that we’ve been seeing. changelog_begin changelog_end * Fix eslint rules * A bit of progress * Try to add LinkablePackageInfo (doesn’t seem to work yet) * Add rootDirs * revert da_ts_library * da_ts_library: add LinkablePackageInfo info * Remove react hook workaround Since rules_nodejs 1.6.0 this fails with the following error: ``` ● Test suite failed to run Configuration error: Could not locate module react mapped as: /.../execroot/com_github_digital_asset_daml/bazel-out/k8-opt/bin/language-support/ts/daml-react/test.sh.runfiles/com_github_digital_asset_daml/node_modules/react/umd/react.development.js. Please check your configuration for these entries: { "moduleNameMapper": { "/^react$/": "/.../execroot/com_github_digital_asset_daml/bazel-out/k8-opt/bin/language-support/ts/daml-react/test.sh.runfiles/com_github_digital_asset_daml/node_modules/react/umd/react.development.js" }, "resolver": null } 49 | // like a promis without being one. 50 | /* eslint-disable @typescript-eslint/no-floating-promises */ > 51 | var react_1 = __importStar(require("react")); | ^ 52 | var react_hooks_1 = require("@testing-library/react-hooks"); 53 | var index_1 = __importStar(require("./index")); 54 | var events_1 = require("events"); at createNoMappedModuleFoundError (../../../../../../../../../../../node_modules/jest-resolve/build/index.js:501:17) at Object.<anonymous> (index.test.js:51:28) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.88s Ran all test suites within paths "language-support/ts/daml-react/DamlLedger.d.ts", "language-support/ts/daml-react/DamlLedger.js", "language-support/ts/daml-react/context.d.ts", "language-support/ts/daml-react/context.js", "language-support/ts/daml-react/hooks.d.ts", "language-support/ts/daml-react/hooks.js", "language-support/ts/daml-react/index.d.ts", "language-support/ts/daml-react/index.js", "language-support/ts/daml-react/index.test.d.ts", "language-support/ts/daml-react/index.test.js". = ``` * rootDirs is not needed for tsc This is only required for ts_project * Update yarn Bazel packages * docs/theme add missing dependencies * Remove unused attribute module_root Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
Running the test in the new project via
yarn test
works just fine.However, running the same tests via
doesn't work. The test fails because it thinks the
ws.server
objectis not an instance of class
Server
. This clearly contradicts theimplementation of the
WS
class athttps://github.com/romgain/jest-websocket-mock/blob/eb8324ff0d4fd1a09effd994cba142f240fb8f7a/src/websocket.ts#L48
My suspicion is that bazel somehow brings multiple versions of the
Server
class frommock-socket
into scope. If you drill intonode_modules/mock-socket
, you'll see thatpackage.json
lists"main": "./dist/mock-socket"
and there are five files indist
:mock-socket.amd.js
mock-socket.cjs.js
mock-socket.es.js
mock-socket.es.mjs
mock-socket.js
The is also
src/index.js
which exports aServer
class. So, there'splenty of ooportunity for
bazel
to get confused.Despite that, I wonder how
jest
gets it right on its own butbazel
manages to confuse
jest
to get it wrong underbazel
's guidance.CHANGELOG_BEGIN
CHANGELOG_END
Pull Request Checklist
CHANGELOG_BEGIN
andCHANGELOG_END
tagsNOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with
/AzurePipelines run
totrigger the build.
This change is