Skip to content
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

Merge haste configs if they are available #281

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
Loading