|
1 | | -load("@aspect_rules_js//js:defs.bzl", "js_test") |
| 1 | +load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer", "js_run_binary", "js_test") |
2 | 2 | load("@bazel_lib//lib:write_source_files.bzl", "write_source_files") |
3 | 3 | load("@bazel_skylib//rules:build_test.bzl", "build_test") |
4 | 4 | load("@npm//:defs.bzl", "npm_link_all_packages") |
@@ -120,3 +120,73 @@ js_test( |
120 | 120 | data = [":node_modules"], |
121 | 121 | entry_point = "versions.js", |
122 | 122 | ) |
| 123 | + |
| 124 | +# A node binary indirectly depending on a platform specific optional npm package |
| 125 | +js_binary( |
| 126 | + name = "esbuild_entry", |
| 127 | + testonly = True, |
| 128 | + data = [":node_modules/esbuild"], |
| 129 | + entry_point = "esbuild.js", |
| 130 | +) |
| 131 | + |
| 132 | +# Use a option-npm-package consuming binary to build a file |
| 133 | +js_run_binary( |
| 134 | + name = "esbuild_build", |
| 135 | + testonly = True, |
| 136 | + srcs = [ |
| 137 | + "versions.js", |
| 138 | + ":node_modules/lodash", |
| 139 | + ":node_modules/lodash-4.17.21", |
| 140 | + ":node_modules/lodash-4.17.21-tar", |
| 141 | + ], |
| 142 | + outs = ["esbuild_test_out.js"], |
| 143 | + args = [ |
| 144 | + "$(location versions.js)", |
| 145 | + package_name() + "/esbuild_test_out.js", |
| 146 | + ], |
| 147 | + tool = ":esbuild_entry", |
| 148 | +) |
| 149 | + |
| 150 | +# A test simply running the compiled bundle |
| 151 | +js_test( |
| 152 | + name = "esbuilt_binary_test", |
| 153 | + entry_point = "esbuild_test_out.js", |
| 154 | +) |
| 155 | + |
| 156 | +# A binary version of the compiled bundle |
| 157 | +js_binary( |
| 158 | + name = "esbuilt_binary", |
| 159 | + testonly = True, |
| 160 | + entry_point = "esbuild_test_out.js", |
| 161 | +) |
| 162 | + |
| 163 | +platform( |
| 164 | + name = "amd64_linux", |
| 165 | + constraint_values = [ |
| 166 | + "@platforms//os:linux", |
| 167 | + "@platforms//cpu:x86_64", |
| 168 | + ], |
| 169 | +) |
| 170 | + |
| 171 | +# The compiled bundle in a container image layer |
| 172 | +js_image_layer( |
| 173 | + name = "esbuilt_binary_image", |
| 174 | + testonly = True, |
| 175 | + binary = ":esbuilt_binary", |
| 176 | + platform = ":amd64_linux", |
| 177 | +) |
| 178 | + |
| 179 | +build_test( |
| 180 | + name = "esbuild_test", |
| 181 | + targets = [ |
| 182 | + # The esbuild npm package including lifecycle hooks to verify platform deps |
| 183 | + ":node_modules/esbuild", |
| 184 | + |
| 185 | + # The bundle target and its output which required running esbuild |
| 186 | + ":esbuild_build", |
| 187 | + "esbuild_test_out.js", |
| 188 | + |
| 189 | + # The image using the bundle which required transitioning |
| 190 | + ":esbuilt_binary_image", |
| 191 | + ], |
| 192 | +) |
0 commit comments