Skip to content

Commit

Permalink
feat: default cacheDirectory to TEST_TMPDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
sallustfire committed Jan 26, 2024
1 parent cb7b5bf commit e2963db
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
15 changes: 15 additions & 0 deletions e2e/case13.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail

# Jest default is os.tmpdir()/jest_<uid>
TEST_TMPDIR=$(mktemp -d)/jest_test_tmpdir

# Case 13: jest_test uses TEST_TMPDIR
rm -rf $TEST_TMPDIR
bazel test //jest/tests:case13 --nocache_test_results --test_tmpdir=$TEST_TMPDIR

# Check if TEST_TMPDIR was utilized by the test action
if [ ! -d "$TEST_TMPDIR" ] || [ -z "$(ls -A "$TEST_TMPDIR")" ]; then
echo "Error: test_tmpdir '$TEST_TMPDIR' does not exist or is empty"
exit 1
fi
3 changes: 3 additions & 0 deletions jest/private/jest_config_template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ if (userConfigShortPath) {
}
}

// Default to using an isolated tmpdir
config.cacheDirectory ||= process.env.TEST_TMPDIR;

// Needed for Jest to walk the filesystem to find inputs.
// See https://github.com/facebook/jest/pull/9351
config.haste = { enableSymlinks: true };
Expand Down
12 changes: 11 additions & 1 deletion jest/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jest_test(
node_modules = "//:node_modules",
)

# Case 11: Coverage reporting (see e2e test)
# Case 12: Coverage reporting (see e2e test)
jest_test(
name = "case12",
data = [
Expand All @@ -174,3 +174,13 @@ jest_test(
],
node_modules = "//:node_modules",
)

# Case 13: jest_test uses TEST_TMPDIR (see e2e test)
jest_test(
name = "case13",
config = "case13.jest.config.js",
data = [
"case13.test.js",
],
node_modules = "//:node_modules",
)
5 changes: 5 additions & 0 deletions jest/tests/case13.jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
reporters: ["default"],
testEnvironment: "node",
testMatch: ["**/*.test.js"],
};
3 changes: 3 additions & 0 deletions jest/tests/case13.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test("it should work", () => {
expect(1).toBe(1);
});

0 comments on commit e2963db

Please sign in to comment.