Skip to content

Commit

Permalink
test: copy_to_bin shenanigans for Windows CI
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Apr 29, 2020
1 parent 199acf4 commit 0407d25
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
10 changes: 9 additions & 1 deletion internal/linker/test/issue_1823/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load(":ts_jest_test.bzl", "ts_jest_test")

Expand All @@ -10,12 +11,19 @@ ts_library(
],
)

# Shenanigans for Windows which doesn't have runfiles symlinks
# We need the jest config to be in the output tree where the specs are
copy_to_bin(
name = "jest_config",
srcs = ["jest.config.js"],
)

ts_jest_test(
name = "test",
srcs = [
"lib.test.ts",
],
jest_config = "jest.config.js",
jest_config = ":jest_config",
deps = [
":lib",
],
Expand Down
4 changes: 2 additions & 2 deletions internal/linker/test/issue_1823/ts_jest_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Uses ts_library devmode UMD output"""
"--no-watchman",
"--ci",
]
args.extend(["--config", "$(rootpath %s)" % jest_config])
args.extend(["--config", "$$(rlocation $(rootpath %s))" % jest_config])

_jest_test(
name = name,
data = [jest_config, ":%s_umd" % name] + deps + data,
args = args,
templated_args = args,
**kwargs
)
23 changes: 21 additions & 2 deletions internal/linker/test/issue_1823_use_ts_library_esm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load(":ts_jest_test.bzl", "ts_jest_test")

Expand All @@ -14,15 +15,33 @@ ts_library(
],
)

# Shenanigans for Windows which doesn't have runfiles symlinks
# We need the jest config to be in the output tree where the specs are
copy_to_bin(
name = "jest_config",
srcs = [
"jest.config.js",
],
)

# Same goes for babelrc. We can't add it to the jest_config copy_to_bin
# since must be a file that is passed to jest in the --config arg.
copy_to_bin(
name = "babel_rc",
srcs = [
".babelrc",
],
)

ts_jest_test(
name = "test",
srcs = [
"lib.test.ts",
],
data = [
".babelrc",
":babel_rc",
],
jest_config = "jest.config.js",
jest_config = ":jest_config",
deps = [
":lib",
"@npm//@babel/preset-env",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
const isWindows = process.platform === 'win32';

module.exports = {
testEnvironment: 'node',
transform: {'^.+\\.mjs?$': 'babel-jest'},
testMatch: ['**/?(*.)(spec|test).?(m)js?(x)'],
// More Shenanigans for Windows where jest is running both the original .mjs & the babel
// transformed .js and fails. Not sure what why this is the case or exactly why changing
// testMatch solves it but not a priority to solve:
// ```
// PASS ../../lib.test.js
// FAIL ../../lib.test.mjs
// C:\b\swkzcapm\execroot\build_bazel_rules_nodejs\bazel-out\x64_windows-fastbuild\bin\internal\linker\test\issue_1823_use_ts_library_esm\lib.test.mjs:1
// import { doStuff } from './lib';
// ^^^^^^
// ```
testMatch: [isWindows ? '**/?(*.)(spec|test).js?(x)' : '**/?(*.)(spec|test).?(m)js?(x)'],
moduleFileExtensions: ['js', 'mjs'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Uses ts_library prodmode ems output"""
"--no-watchman",
"--ci",
]
args.extend(["--config", "$(rootpath %s)" % jest_config])
args.extend(["--config", "$$(rlocation $(rootpath %s))" % jest_config])

_jest_test(
name = name,
Expand Down

0 comments on commit 0407d25

Please sign in to comment.