Skip to content

Commit

Permalink
auto generate dates
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 10, 2024
1 parent b474e8c commit 37c95b4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/workerd/api/wpt/generate-tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("//:build/wd_test.bzl", "wd_test")
# 0 - name of the service
# 1 - es module file path (ex: url-test for url-test.js)
# 2 - external modules required for the test suite to succeed
# 3 - current date in YYYY-MM-DD format
WPT_TEST_TEMPLATE = """
using Workerd = import "/workerd/workerd.capnp";
Expand All @@ -19,8 +20,8 @@ const unitTests :Workerd.Config = (
bindings = [
(name = "wpt", service = "wpt"),
],
compatibilityDate = "2024-07-01",
compatibilityFlags = ["nodejs_compat_v2"],
compatibilityDate = "{}",
compatibilityFlags = ["nodejs_compat_v2", "experimental"],
)
),
(
Expand All @@ -30,9 +31,24 @@ const unitTests :Workerd.Config = (
],
);"""

def _current_date_impl(repository_ctx):
result = repository_ctx.execute(["date", "+%Y-%m-%d"])
if result.return_code != 0:
fail("Failed to get current date")

current_date = result.stdout.strip()

repository_ctx.file("BUILD", "")
repository_ctx.file("date.bzl", "CURRENT_DATE = '%s'" % current_date)

current_date = repository_rule(
implementation = _current_date_impl,
local = True,
)

# Example: generate_wd_test_file("url-test")
def generate_wd_test_file(name, modules = ""):
return WPT_TEST_TEMPLATE.format(name, name, modules)
return WPT_TEST_TEMPLATE.format(name, name, modules, current_date())

def generate_external_modules(directory):
"""
Expand Down

0 comments on commit 37c95b4

Please sign in to comment.