2022-09-14 21:32:42 +00:00
|
|
|
load("//tools:defaults.bzl", "nodejs_test")
|
2022-09-01 21:08:08 +00:00
|
|
|
|
2022-09-22 02:12:35 +00:00
|
|
|
def local_server_test(name, entry_point, serve_target, data = [], args = [], **kwargs):
|
2022-09-01 21:08:08 +00:00
|
|
|
"""Run a test script alongside a locally running http server.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
name: Name of the test target
|
|
|
|
|
entry_point: The test script to run
|
|
|
|
|
serve_target: The contents to serve
|
|
|
|
|
data: Additional data required by the test script
|
|
|
|
|
args: Args to pass to the test script. Note: The special argument LOCALHOST_URL
|
|
|
|
|
will be substituted with the url pointing to the served contents.
|
2022-09-22 02:12:35 +00:00
|
|
|
**kwargs: remaining args to pass to test
|
2022-09-01 21:08:08 +00:00
|
|
|
"""
|
|
|
|
|
nodejs_test(
|
|
|
|
|
name = name,
|
|
|
|
|
testonly = True,
|
|
|
|
|
args = [
|
|
|
|
|
"$(rootpath @aio_npm//light-server/bin:light-server)",
|
|
|
|
|
"$(rootpath %s)" % serve_target,
|
|
|
|
|
"$(rootpath %s)" % entry_point,
|
|
|
|
|
] + args,
|
|
|
|
|
data = [
|
|
|
|
|
"//aio/scripts:run-with-local-server.mjs",
|
|
|
|
|
"@aio_npm//get-port",
|
|
|
|
|
"@aio_npm//shelljs",
|
|
|
|
|
"@aio_npm//tree-kill",
|
2022-12-16 20:04:01 +00:00
|
|
|
"@aio_npm//light-server/bin:light-server",
|
|
|
|
|
serve_target,
|
|
|
|
|
entry_point,
|
2022-09-01 21:08:08 +00:00
|
|
|
] + data,
|
|
|
|
|
entry_point = "//aio/scripts:run-with-local-server.mjs",
|
2022-09-22 02:12:35 +00:00
|
|
|
**kwargs
|
2022-09-01 21:08:08 +00:00
|
|
|
)
|