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

feat: default cacheDirectory to TEST_TMPDIR #231

Merged
merged 2 commits into from
Jan 26, 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
25 changes: 25 additions & 0 deletions e2e/case13.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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

# Locate the cache folder under TEST_TMPDIR
JEST_CACHE_NAME="jest_cache"
JEST_CACHE_DIR=$(find "$TEST_TMPDIR" -type d -name "$JEST_CACHE_NAME" -print -quit)

# Check that the cache folder exists
if [ -z "$JEST_CACHE_DIR" ]; then
echo "Error: '$JEST_CACHE_NAME' folder not found below '$TEST_TMPDIR'"
exit 1
fi

# Check that the folder was used for the cache
if [ -z "$(ls -A "$JEST_CACHE_DIR")" ]; then
echo "Error: '$JEST_CACHE_NAME' folder at '$JEST_CACHE_DIR' is empty"
exit 1
fi
4 changes: 4 additions & 0 deletions jest/private/jest_config_template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ if (userConfigShortPath) {
}
}

// Default to using an isolated tmpdir
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 };
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);
});
Loading