diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 1b2e7f8..de683c3 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -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. diff --git a/jest/private/jest_config_template.mjs b/jest/private/jest_config_template.mjs index b8e2058..ac61a24 100644 --- a/jest/private/jest_config_template.mjs +++ b/jest/private/jest_config_template.mjs @@ -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 diff --git a/jest/tests/BUILD.bazel b/jest/tests/BUILD.bazel index 9e4cee9..e0a2cb9 100644 --- a/jest/tests/BUILD.bazel +++ b/jest/tests/BUILD.bazel @@ -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", +) diff --git a/jest/tests/case14-lib.foo.js b/jest/tests/case14-lib.foo.js new file mode 100644 index 0000000..b6069e0 --- /dev/null +++ b/jest/tests/case14-lib.foo.js @@ -0,0 +1 @@ +module.exports.foo = 'foo' diff --git a/jest/tests/case14.jest.config.js b/jest/tests/case14.jest.config.js new file mode 100644 index 0000000..6655f09 --- /dev/null +++ b/jest/tests/case14.jest.config.js @@ -0,0 +1,5 @@ +module.exports = { + haste: { defaultPlatform: 'foo', platforms: ['foo'] }, + testEnvironment: "node", + testMatch: ["**/*.test.js"], +} diff --git a/jest/tests/case14.test.js b/jest/tests/case14.test.js new file mode 100644 index 0000000..3d64328 --- /dev/null +++ b/jest/tests/case14.test.js @@ -0,0 +1,5 @@ +const {foo} = require('./case14-lib'); + +test("it should work", () => { + expect(foo).toBe('foo'); +});