-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: add ESM support to jasmine_test()
#41
Conversation
This fixes aspect-build/rules_jasmine#33 and adds ESM support. I've sent a PR in aspect-build/rules_jasmine#41 to apply the fix upstream, but for now a patch will have to do.
This fixes aspect-build/rules_jasmine#33 and adds ESM support. I've sent a PR in aspect-build/rules_jasmine#41 to apply the fix upstream, but for now a patch will have to do.
This fixes aspect-build/rules_jasmine#33 and adds ESM support. I've sent a PR in aspect-build/rules_jasmine#41 to apply the fix upstream, but for now a patch will have to do.
This fixes aspect-build/rules_jasmine#33 and adds ESM support. I've sent a PR in aspect-build/rules_jasmine#41 to apply the fix upstream, but for now a patch will have to do.
Refs #33. This fixes aspect-build/rules_jasmine#33 and adds ESM support. I've sent a PR in aspect-build/rules_jasmine#41 to apply the fix upstream, but for now a patch will have to do.
Worked for me. Thanks for this! |
Do you have a test that can be added? Something that fails without this... |
de21ccc
to
84e9aad
Compare
Thanks for bringing this up, totally forgot about that. Actually looking at existing test cases, it seems they all already use ESM. I was a bit surprised about that and started digging a bit more into the failure I was seeing. Turns out I was experiencing a bug where
The There are a few potential solutions to this, but I think the best is to actually ship an empty Ironically, //e2e/jasmine_test/... had an exactly correct test case, but wasn't being run on CI and was failing at HEAD. I enabled that test and fixed it up to serve as a regression test. I also noticed that all the existing tests actually use ESM, so I made a CommonJS test leveraging the default behavior to make sure that wasn't broken as well. We could probably migrate I suspect this same bug of having the user's |
Great 👍 |
Looks like the e2e test is failing atm though? |
At runtime, the JUnit reporter exists at `.../execroot/${wksp}/bazel-out/${cfg}/bin/external/jasmine/junit_reporter.js` with no included `package.json`. This means Node walks up that tree looking for a `package.json` file and typically won't find one. However, if users include a `//:package.json` file in their own workspace, it will be visible at `.../execroot/${wksp}/bazel-out/${cfg}/bin/package.json`, meaning it will be picked up as owning `junit_reporter.js`. This means that any user-specified `type: "module"` applies to `junit_reporter.js`, and caused it to be loaded as ESM, even when it was authored in CommonJS. The solution here is to copy over a `package.json` we own to `external/jasmine/package.json`. This way any JavaScript loaded will have a stable `package.json` which uses CommonJS. Ironically, `//e2e/jasmine_test/` actually already exercised this exact test case, but wasn't running on CI. So this commit also re-enables that test and fixes it. Actually all the test cases use ESM, so I also added `//examples/commonjs/...` and left the "default" behavior there to ensure that doesn't break in the future.
Ah didn't realize the CI workflow expected the example to have a |
@gonzojive does this latest change work for you? |
It seems to work for me. $ git clone https://github.com/gonzojive/rules_ts_proto
$ cd rules_ts_proto/e2e/typescript_proto_usage/
$ bazel test //... That might not work for others due to local repositories in the workspace. |
Great, thanks for checking! 👍 |
Fixes #33.
This introduces a new
module
option which chooses between CommonJS and ES modules. Based on this input,jasmine_test()
will choose the correct format of the JUnit reporter. This does not enforce that actual tests are executed as ES modules, those still need to be configured in Jasmine's config file. See: https://jasmine.github.io/setup/nodejs.html#using-es-modules.I tried to keep things simple and just duplicated the reporter with native
import
statements. There's a bit of unnecessary duplication there, but I think the file is simple enough that it doesn't really matter too much. Fortunately the JUnit reporter is the only thing which needs to be changed to be compatible with ESM. As long as you name the test files.mjs
, Jasmine will load them via dynamic import.