Skip to content

Commit

Permalink
test: use write_source_files where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Mar 2, 2023
1 parent d893b1e commit bb8898c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 30 deletions.
26 changes: 11 additions & 15 deletions examples/out_dir/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@aspect_rules_swc//swc:defs.bzl", "swc")
load("@aspect_bazel_lib//lib:testing.bzl", "assert_outputs")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")

swc(
name = "compile",
Expand All @@ -11,17 +11,13 @@ swc(
source_maps = True,
)

# Since the srcs were in a filegroup, the swc macro cannot pre-declare the outputs.
# So there is no label ":a.js" that we can reference from the build file.
# However, a.js is still produced as one of the default outputs of the compile rule.
# We can verify this in an action that depends on the ":compile" rule and reads the files.
assert_outputs(
name = "check_outputs",
actual = "compile",
expected = [
"examples/out_dir/out/a.js",
"examples/out_dir/out/a.js.map",
"examples/out_dir/out/b.js",
"examples/out_dir/out/b.js.map",
],
)
# Assert that the output of "compile" rule matches the expected file.
write_source_files(
name = "test",
files = {
"expected/a.js": ":out/a.js",
"expected/a.js.map": ":out/a.js.map",
"expected/b.js": ":out/b.js",
"expected/b.js.map": ":out/b.js.map",
},
)
3 changes: 3 additions & 0 deletions examples/out_dir/expected/a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/out_dir/expected/a.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/out_dir/expected/b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/out_dir/expected/b.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 11 additions & 15 deletions examples/root_dir/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@aspect_rules_swc//swc:defs.bzl", "swc")
load("@aspect_bazel_lib//lib:testing.bzl", "assert_outputs")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")

swc(
name = "compile",
Expand All @@ -12,17 +12,13 @@ swc(
source_maps = True,
)

# Since the srcs were in a filegroup, the swc macro cannot pre-declare the outputs.
# So there is no label ":a.js" that we can reference from the build file.
# However, a.js is still produced as one of the default outputs of the compile rule.
# We can verify this in an action that depends on the ":compile" rule and reads the files.
assert_outputs(
name = "check_outputs",
actual = "compile",
expected = [
"examples/root_dir/out/a.js",
"examples/root_dir/out/a.js.map",
"examples/root_dir/out/b.js",
"examples/root_dir/out/b.js.map",
],
)
# Assert that the output of "compile" rule matches the expected file.
write_source_files(
name = "test",
files = {
"expected/a.js": ":out/a.js",
"expected/a.js.map": ":out/a.js.map",
"expected/b.js": ":out/b.js",
"expected/b.js.map": ":out/b.js.map",
},
)
3 changes: 3 additions & 0 deletions examples/root_dir/expected/a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/root_dir/expected/a.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/root_dir/expected/b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/root_dir/expected/b.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb8898c

Please sign in to comment.