|
| 1 | +# Test data file copying behavior. See |
| 2 | +# |
| 3 | +# https://github.com/aspect-build/rules_ts/issues/411 |
| 4 | +# https://github.com/aspect-build/rules_ts/issues/716 |
| 5 | +# |
| 6 | +# Ideally, the behaviors with and without `transpiler` would align, but that is |
| 7 | +# backwards incompatible. |
| 8 | + |
| 9 | +load("//ts:defs.bzl", "ts_project") |
| 10 | +load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary") |
| 11 | +load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains") |
| 12 | +load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file") |
| 13 | +load("//ts/test:mock_transpiler.bzl", "mock") |
| 14 | + |
| 15 | +copy_file( |
| 16 | + name = "no_transpiler_src", |
| 17 | + src = "check_has_data.ts", |
| 18 | + out = "no_transpiler.ts", |
| 19 | +) |
| 20 | + |
| 21 | +ts_project( |
| 22 | + name = "no_transpiler", |
| 23 | + srcs = ["no_transpiler.ts"], |
| 24 | + data = ["data.txt"], |
| 25 | + tsconfig = {}, |
| 26 | +) |
| 27 | + |
| 28 | +js_binary( |
| 29 | + name = "no_transpiler_bin", |
| 30 | + entry_point = "no_transpiler.ts", |
| 31 | + data = [":no_transpiler"], |
| 32 | +) |
| 33 | + |
| 34 | +js_run_binary( |
| 35 | + name = "no_transpiler_gen", |
| 36 | + tool = ":no_transpiler_bin", |
| 37 | + chdir = package_name(), |
| 38 | + stdout = "no_transpiler_out.txt", |
| 39 | +) |
| 40 | + |
| 41 | +assert_contains( |
| 42 | + name = "no_transpiler_test", |
| 43 | + actual = "no_transpiler_out.txt", |
| 44 | + expected = "false", |
| 45 | +) |
| 46 | + |
| 47 | +copy_file( |
| 48 | + name = "with_transpiler_src", |
| 49 | + src = "check_has_data.ts", |
| 50 | + out = "with_transpiler.ts", |
| 51 | +) |
| 52 | + |
| 53 | +ts_project( |
| 54 | + name = "with_transpiler", |
| 55 | + srcs = ["with_transpiler.ts"], |
| 56 | + transpiler = mock, |
| 57 | + data = ["data.txt"], |
| 58 | + tsconfig = {}, |
| 59 | +) |
| 60 | + |
| 61 | +js_binary( |
| 62 | + name = "with_transpiler_bin", |
| 63 | + entry_point = "with_transpiler.js", |
| 64 | + data = [":with_transpiler"], |
| 65 | +) |
| 66 | + |
| 67 | +js_run_binary( |
| 68 | + name = "with_transpiler_gen", |
| 69 | + tool = ":with_transpiler_bin", |
| 70 | + chdir = package_name(), |
| 71 | + stdout = "with_transpiler_out.txt", |
| 72 | +) |
| 73 | + |
| 74 | +assert_contains( |
| 75 | + name = "with_transpiler_test", |
| 76 | + actual = "with_transpiler_out.txt", |
| 77 | + expected = "true", |
| 78 | +) |
0 commit comments