diff --git a/examples/jest/.bazelrc b/examples/jest/.bazelrc index 3431057af6..dd47141064 100644 --- a/examples/jest/.bazelrc +++ b/examples/jest/.bazelrc @@ -1 +1,7 @@ import %workspace%/../../common.bazelrc + +# jest relies on the runfiles generation to find the correct files. +# To work on windows we have to specify this flags. +build --enable_runfiles +run --enable_runfiles +test --enable_runfiles \ No newline at end of file diff --git a/examples/jest/BUILD.bazel b/examples/jest/BUILD.bazel index 5b08c594f4..4192246a18 100644 --- a/examples/jest/BUILD.bazel +++ b/examples/jest/BUILD.bazel @@ -19,10 +19,6 @@ jest_test( ] + glob(["__snapshots__/*.snap"]), jest_config = ":jest.config.js", tags = [ - # Need to set the pwd to avoid jest needing a runfiles helper - # Windows users with permissions can use --enable_runfiles - # to make this test work - "no-bazelci-windows", # TODO: why does this fail almost all the time, but pass on local Mac? "no-bazelci-mac", ], diff --git a/examples/jest/README.md b/examples/jest/README.md index 7bb26d1b9c..f35106b108 100644 --- a/examples/jest/README.md +++ b/examples/jest/README.md @@ -4,6 +4,17 @@ This example shows how you might use the Jest testing framework It has a utility macro in `jest.bzl` which makes a more ergonomic API for calling the `jest_test` rule in `@npm//jest-cli:index.bzl`. We suggest copying that to your repo. +## Running on Windows + +To make the tests running on windows as well you have to add the `--enable_runfiles` flag to your `.bazelrc`. +This requires running under elevated privileges (Admin rights), Windows 10 Creators Update (1703) or later system version, and enabling developer mode. + +``` +build --enable_runfiles +run --enable_runfiles +test --enable_runfiles +``` + # Jest typescript example Under `ts/` there's an example of using jest with typescript directly with generated rule from `@npm//jest-cli:index.bzl` \ No newline at end of file diff --git a/internal/common/windows_utils.bzl b/internal/common/windows_utils.bzl index 1ae88c2021..e984ddd256 100644 --- a/internal/common/windows_utils.bzl +++ b/internal/common/windows_utils.bzl @@ -35,6 +35,9 @@ if "%RUNFILES_MANIFEST_ONLY%" neq "1" ( set %~2=%~1 exit /b 0 ) +if exist "%RUNFILES_DIR%" ( + set RUNFILES_MANIFEST_FILE=%RUNFILES_DIR%_manifest +) if "%RUNFILES_MANIFEST_FILE%" equ "" ( set RUNFILES_MANIFEST_FILE=%~f0.runfiles\MANIFEST ) diff --git a/internal/node/launcher.sh b/internal/node/launcher.sh index a4eceb77a1..10efb6c4e6 100644 --- a/internal/node/launcher.sh +++ b/internal/node/launcher.sh @@ -149,14 +149,18 @@ fi # Export the location of the runfiles helpers script export BAZEL_NODE_RUNFILES_HELPER=$(rlocation "TEMPLATED_runfiles_helper_script") -if [[ "${BAZEL_NODE_RUNFILES_HELPER}" != /* ]] && [[ ! "${BAZEL_NODE_RUNFILES_HELPER}" =~ ^[A-Z]:[\\/] ]]; then +# Paths can be with lower and upper case on windows because of the msys64 package in the powershell +# https://regex101.com/r/c0Gjn8/1/ +if [[ "${BAZEL_NODE_RUNFILES_HELPER}" != /* ]] && [[ ! "${BAZEL_NODE_RUNFILES_HELPER}" =~ ^[A-Za-z]:[\/\\] ]]; then export BAZEL_NODE_RUNFILES_HELPER=$(pwd)/${BAZEL_NODE_RUNFILES_HELPER} fi # Export the location of the require patch script as it can be used to bootstrap # node require patch if needed export BAZEL_NODE_PATCH_REQUIRE=$(rlocation "TEMPLATED_require_patch_script") -if [[ "${BAZEL_NODE_PATCH_REQUIRE}" != /* ]] && [[ ! "${BAZEL_NODE_PATCH_REQUIRE}" =~ ^[A-Z]:[\\/] ]]; then +# Paths can be with lower and upper case on windows because of the msys64 package in the powershell +# https://regex101.com/r/c0Gjn8/1/ +if [[ "${BAZEL_NODE_PATCH_REQUIRE}" != /* ]] && [[ ! "${BAZEL_NODE_PATCH_REQUIRE}" =~ ^[A-Za-z]:[\/\\] ]]; then export BAZEL_NODE_PATCH_REQUIRE=$(pwd)/${BAZEL_NODE_PATCH_REQUIRE} fi