Skip to content

Commit

Permalink
Merge haste configs if they are available (#281)
Browse files Browse the repository at this point in the history
* merge haste configs if they are available

* adds tests for haste merging
  • Loading branch information
colinta authored May 21, 2024
1 parent a6357dd commit 76b65ae
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ By default Jest runs tests concurrently using workers. This conflicts with Bazel

By default Jest uses `jest-haste-map` to optimize and cache fs operations which must be configured to work with Bazel. `rules_jest` will automatically configure `haste` for compatibility with`rules_jest` and `rules_js`. Care must be taken with custom Jest configurations when configuring `haste`.

The settings defined by `rules_jest` are `{ enableSymlinks: true }`, but if you define your own `haste:` settings (in a custom jest config), they will be _merged_ with the rules_jest defaults.

_Note_: If you are importing a preset, and _it_ declares its own `haste` config, those will not be merged. This is an implementation detail of jest. The only workaround is to copy those settings into your local *jest.config.js* file.

## Pre-transpiled sources

Frequently outside the Bazel ecosystem sources such as `*.ts` are transpiled on the fly using tools such as `ts-jest` or `babel-jest`. Such tools are designed for Jest and transpile to a javascript format ideal for Jest but normally not for production use.
Expand Down
2 changes: 1 addition & 1 deletion jest/private/jest_config_template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ config.cacheDirectory ||= path.join(process.env.TEST_TMPDIR, 'jest_cache');

// Needed for Jest to walk the filesystem to find inputs.
// See https://github.com/facebook/jest/pull/9351
config.haste = { enableSymlinks: true };
config.haste = { enableSymlinks: true, ...config.haste };

// https://jestjs.io/docs/cli#--watchman. Whether to use watchman for file crawling. Defaults
// to true. Disable using --no-watchman. Watching is ibazel's job
Expand Down
11 changes: 11 additions & 0 deletions jest/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,14 @@ jest_test(
],
node_modules = "//:node_modules",
)

# Case 14: jest_test merges haste configs
jest_test(
name = "case14",
config = "case14.jest.config.js",
data = [
"case14.test.js",
"case14-lib.foo.js",
],
node_modules = "//:node_modules",
)
1 change: 1 addition & 0 deletions jest/tests/case14-lib.foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.foo = 'foo'
5 changes: 5 additions & 0 deletions jest/tests/case14.jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
haste: { defaultPlatform: 'foo', platforms: ['foo'] },
testEnvironment: "node",
testMatch: ["**/*.test.js"],
}
5 changes: 5 additions & 0 deletions jest/tests/case14.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const {foo} = require('./case14-lib');

test("it should work", () => {
expect(foo).toBe('foo');
});

0 comments on commit 76b65ae

Please sign in to comment.