generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: always load JUnit reporter as ESM
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.
- Loading branch information
Showing
11 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ jasmine_test( | |
"lib.test.js", | ||
"package.json", | ||
], | ||
args = ["*.spec.js"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test") | ||
|
||
jasmine_test( | ||
name = "test", | ||
data = [ | ||
"lib.js", | ||
"lib.spec.js", | ||
], | ||
args = ["*.spec.js"], | ||
chdir = package_name(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
say_hi: () => "hi", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { say_hi } = require("./lib.js"); | ||
|
||
describe("lib", () => { | ||
it("should say hi", () => { | ||
expect(say_hi()).toBe("hi"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters