From 87a7acd92a19fadb8f0e6d5bfde230c3c3d975f7 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Thu, 2 Mar 2023 15:26:39 -0800 Subject: [PATCH] test: use write_source_files where possible --- examples/out_dir/BUILD.bazel | 26 +++++++++++--------------- examples/out_dir/expected/a.js | 3 +++ examples/out_dir/expected/a.js.map | 1 + examples/out_dir/expected/b.js | 3 +++ examples/out_dir/expected/b.js.map | 1 + examples/root_dir/BUILD.bazel | 26 +++++++++++--------------- examples/root_dir/expected/a.js | 3 +++ examples/root_dir/expected/a.js.map | 1 + examples/root_dir/expected/b.js | 3 +++ examples/root_dir/expected/b.js.map | 1 + 10 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 examples/out_dir/expected/a.js create mode 100644 examples/out_dir/expected/a.js.map create mode 100644 examples/out_dir/expected/b.js create mode 100644 examples/out_dir/expected/b.js.map create mode 100644 examples/root_dir/expected/a.js create mode 100644 examples/root_dir/expected/a.js.map create mode 100644 examples/root_dir/expected/b.js create mode 100644 examples/root_dir/expected/b.js.map diff --git a/examples/out_dir/BUILD.bazel b/examples/out_dir/BUILD.bazel index 7a24ef0..75a99fd 100644 --- a/examples/out_dir/BUILD.bazel +++ b/examples/out_dir/BUILD.bazel @@ -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", @@ -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", + }, +) \ No newline at end of file diff --git a/examples/out_dir/expected/a.js b/examples/out_dir/expected/a.js new file mode 100644 index 0000000..5fe36cc --- /dev/null +++ b/examples/out_dir/expected/a.js @@ -0,0 +1,3 @@ +export var a = "a"; + +//# sourceMappingURL=a.js.map \ No newline at end of file diff --git a/examples/out_dir/expected/a.js.map b/examples/out_dir/expected/a.js.map new file mode 100644 index 0000000..1bd605c --- /dev/null +++ b/examples/out_dir/expected/a.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["a.ts"],"sourceRoot":"examples/out_dir","sourcesContent":["export const a: string = \"a\";\n"],"names":["a"],"mappings":"AAAA,OAAO,IAAMA,IAAY,IAAI"} \ No newline at end of file diff --git a/examples/out_dir/expected/b.js b/examples/out_dir/expected/b.js new file mode 100644 index 0000000..8a3a9ec --- /dev/null +++ b/examples/out_dir/expected/b.js @@ -0,0 +1,3 @@ +export var b = "b"; + +//# sourceMappingURL=b.js.map \ No newline at end of file diff --git a/examples/out_dir/expected/b.js.map b/examples/out_dir/expected/b.js.map new file mode 100644 index 0000000..d968a53 --- /dev/null +++ b/examples/out_dir/expected/b.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["b.ts"],"sourceRoot":"examples/out_dir","sourcesContent":["export const b: string = \"b\";\n"],"names":["b"],"mappings":"AAAA,OAAO,IAAMA,IAAY,IAAI"} \ No newline at end of file diff --git a/examples/root_dir/BUILD.bazel b/examples/root_dir/BUILD.bazel index 7759272..a94eeba 100644 --- a/examples/root_dir/BUILD.bazel +++ b/examples/root_dir/BUILD.bazel @@ -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", @@ -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", + }, +) \ No newline at end of file diff --git a/examples/root_dir/expected/a.js b/examples/root_dir/expected/a.js new file mode 100644 index 0000000..5fe36cc --- /dev/null +++ b/examples/root_dir/expected/a.js @@ -0,0 +1,3 @@ +export var a = "a"; + +//# sourceMappingURL=a.js.map \ No newline at end of file diff --git a/examples/root_dir/expected/a.js.map b/examples/root_dir/expected/a.js.map new file mode 100644 index 0000000..a17a581 --- /dev/null +++ b/examples/root_dir/expected/a.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["a.ts"],"sourceRoot":"examples/root_dir/src","sourcesContent":["export const a: string = \"a\";\n"],"names":["a"],"mappings":"AAAA,OAAO,IAAMA,IAAY,IAAI"} \ No newline at end of file diff --git a/examples/root_dir/expected/b.js b/examples/root_dir/expected/b.js new file mode 100644 index 0000000..8a3a9ec --- /dev/null +++ b/examples/root_dir/expected/b.js @@ -0,0 +1,3 @@ +export var b = "b"; + +//# sourceMappingURL=b.js.map \ No newline at end of file diff --git a/examples/root_dir/expected/b.js.map b/examples/root_dir/expected/b.js.map new file mode 100644 index 0000000..c66e9c8 --- /dev/null +++ b/examples/root_dir/expected/b.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["b.ts"],"sourceRoot":"examples/root_dir/src","sourcesContent":["export const b: string = \"b\";\n"],"names":["b"],"mappings":"AAAA,OAAO,IAAMA,IAAY,IAAI"} \ No newline at end of file