-
Notifications
You must be signed in to change notification settings - Fork 522
/
Copy pathBUILD.bazel
103 lines (94 loc) · 2.58 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "nodejs_test")
load("@npm//react-scripts:index.bzl", "react_scripts", "react_scripts_test")
# Filename conventions described at
# https://create-react-app.dev/docs/running-tests#filename-conventions
_TESTS = [
"src/**/*.test.js*",
"src/**/*.test.ts*",
"src/**/*.spec.js*",
"src/**/*.test.ts*",
"src/**/__tests__/**/*.js*",
"src/**/__tests__/**/*.ts*",
]
# We don't want to teach react-scripts to include from multiple directories
# So we copy everything it wants to read to the output "bin" directory
copy_to_bin(
name = "copy_static_files",
srcs = glob(
[
"public/*",
"src/**/*",
],
exclude = _TESTS,
) + [
"package.json",
"tsconfig.json",
],
)
# react-scripts can only work if the working directory is the root of the application.
# So we'll need to chdir before it runs.
write_file(
name = "write_chdir_script",
out = "chdir.js",
content = ["process.chdir(__dirname)"],
)
_RUNTIME_DEPS = [
"chdir.js",
"copy_static_files",
"@npm//react",
"@npm//react-dom",
]
react_scripts(
# Note: this must be named "build" since react-scripts hard-codes that as the output dir
name = "build",
args = [
"--node_options=--require=./$(execpath chdir.js)",
"build",
],
data = _RUNTIME_DEPS + [
"@npm//@types",
],
output_dir = True,
)
nodejs_test(
name = "build_smoke_test",
data = ["build"],
entry_point = "build_smoke_test.js",
)
copy_to_bin(
name = "copy_test_files",
srcs = glob(_TESTS),
)
react_scripts_test(
name = "test",
args = [
"--node_options=--require=$(rootpath chdir.js)",
"test",
# ibazel is the watch mode for Bazel when running tests
# Because Bazel is really a CI system that runs locally
"--watchAll=false",
"--no-cache",
"--no-watchman",
"--ci",
],
data = _RUNTIME_DEPS + [
"copy_test_files",
"@npm//@testing-library/dom",
"@npm//@testing-library/jest-dom",
"@npm//@testing-library/react",
"@npm//@testing-library/user-event",
],
# 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
tags = ["no-bazelci-windows"],
)
react_scripts(
name = "start",
args = [
"--node_options=--require=$(rootpath chdir.js)",
"start",
],
data = _RUNTIME_DEPS,
)