Skip to content

Commit

Permalink
feat(examples): convert create-react-app example to bazel test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eagle authored and alexeagle committed Jul 14, 2020
1 parent 52455e0 commit 146e522
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 10 deletions.
1 change: 1 addition & 0 deletions examples/create-react-app/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions examples/create-react-app/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test --test_output=errors
54 changes: 49 additions & 5 deletions examples/create-react-app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("@npm//react-scripts:index.bzl", "react_scripts")
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/*",
]) + [
srcs = glob(
[
"public/*",
"src/**/*",
],
exclude = _TESTS,
) + [
"package.json",
"tsconfig.json",
],
)

copy_to_bin(
name = "copy_test_files",
srcs = glob(_TESTS),
)

# 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(
Expand All @@ -39,3 +58,28 @@ react_scripts(
],
output_dir = True,
)

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 = [
"chdir.js",
"copy_static_files",
"copy_test_files",
"@npm//@testing-library/dom",
"@npm//@testing-library/jest-dom",
"@npm//@testing-library/react",
"@npm//@testing-library/user-event",
"@npm//react",
"@npm//react-dom",
],
)
8 changes: 5 additions & 3 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
"typescript": "~3.7.2"
},
"devDependencies": {
"@bazel/bazelisk": "^1.5.0"
"@bazel/bazelisk": "^1.5.0",
"@bazel/ibazel": "^0.13.1",
"patch-package": "^6.2.2"
},
"scripts": {
"start": "react-scripts start",
"start": "ibazel run //:start",
"build": "bazel build //:build",
"test": "react-scripts test"
"test": "ibazel test //:test"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
17 changes: 17 additions & 0 deletions examples/create-react-app/patches/jest-haste-map+24.9.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/node_modules/jest-haste-map/build/crawlers/node.js b/node_modules/jest-haste-map/build/crawlers/node.js
index 23985ae..182c7e8 100644
--- a/node_modules/jest-haste-map/build/crawlers/node.js
+++ b/node_modules/jest-haste-map/build/crawlers/node.js
@@ -166,7 +166,12 @@ function find(roots, extensions, ignore, callback) {

function findNative(roots, extensions, ignore, callback) {
const args = Array.from(roots);
+ args.push('(');
args.push('-type', 'f');
+ args.push('-o');
+ args.push('-type', 'l');
+ args.push(')');
+

if (extensions.length) {
args.push('(');
47 changes: 45 additions & 2 deletions examples/create-react-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,11 @@
resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.5.0.tgz#61f583ed93be138b47be7180403938ea4057f54b"
integrity sha512-qhOGN1WmfZYNJXGrRL/0byii9hX5FBomMv3WWI2OEL2+Bxm4t/bR3zMxN3xwQX1C8meSSrAfKGSzxVOZfpJsOg==

"@bazel/ibazel@^0.13.1":
version "0.13.1"
resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.13.1.tgz#23788f67a6fbe83d96f2d055691df4917c10ac8d"
integrity sha512-FO1hBKpzpeBL0adnFYF2Dwl/7gox6ccKM6bb+x26AXrQpLbinXPuTi4zeXRL/MW4383mF6i4RovLCmwUU/YW0w==

"@cnakazawa/watch@^1.0.3":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.4.tgz#f864ae85004d0fcab6f50be9141c4da368d1656a"
Expand Down Expand Up @@ -1850,6 +1855,11 @@
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

"@yarnpkg/lockfile@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31"
integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==

abab@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.3.tgz#623e2075e02eb2d3f2475e49f99c91846467907a"
Expand Down Expand Up @@ -4578,6 +4588,14 @@ find-up@^3.0.0:
dependencies:
locate-path "^3.0.0"

find-yarn-workspace-root@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db"
integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q==
dependencies:
fs-extra "^4.0.3"
micromatch "^3.1.4"

flat-cache@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0"
Expand Down Expand Up @@ -4682,7 +4700,7 @@ from2@^2.1.0:
inherits "^2.0.1"
readable-stream "^2.0.0"

fs-extra@^4.0.2:
fs-extra@^4.0.2, fs-extra@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==
Expand All @@ -4691,7 +4709,7 @@ fs-extra@^4.0.2:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^7.0.0:
fs-extra@^7.0.0, fs-extra@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
Expand Down Expand Up @@ -6365,6 +6383,13 @@ kind-of@^6.0.0, kind-of@^6.0.2:
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==

klaw-sync@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c"
integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==
dependencies:
graceful-fs "^4.1.11"

kleur@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
Expand Down Expand Up @@ -7475,6 +7500,24 @@ pascalcase@^0.1.1:
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=

patch-package@^6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.2.2.tgz#71d170d650c65c26556f0d0fbbb48d92b6cc5f39"
integrity sha512-YqScVYkVcClUY0v8fF0kWOjDYopzIM8e3bj/RU1DPeEF14+dCGm6UeOYm4jvCyxqIEQ5/eJzmbWfDWnUleFNMg==
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
chalk "^2.4.2"
cross-spawn "^6.0.5"
find-yarn-workspace-root "^1.2.1"
fs-extra "^7.0.1"
is-ci "^2.0.0"
klaw-sync "^6.0.0"
minimist "^1.2.0"
rimraf "^2.6.3"
semver "^5.6.0"
slash "^2.0.0"
tmp "^0.0.33"

path-browserify@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a"
Expand Down

0 comments on commit 146e522

Please sign in to comment.