Skip to content

Commit

Permalink
test: add repositories.bzl snapshot tests for each lockfile version
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Jan 6, 2025
1 parent 08fe920 commit c1631a8
Show file tree
Hide file tree
Showing 6 changed files with 4,998 additions and 3 deletions.
47 changes: 44 additions & 3 deletions e2e/pnpm_lockfiles/lockfile-test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PNPM_LOCK_VERSIONS = [
"v90",
]

BZL_FILES = {
BZLMOD_FILES = {
# global
"defs.bzl": "@REPO_NAME//:defs.bzl",

Expand All @@ -29,6 +29,10 @@ BZL_FILES = {
"rollup3_package_json.bzl": "@REPO_NAME__rollup__3.29.4//VERSION:package_json.bzl",
}

WKSP_FILES = {
"repositories.bzl": "@REPO_NAME//:repositories.bzl",
}

def lockfile_test(name = None):
"""
Tests for a lockfile and associated targets + files generated by rules_js.
Expand Down Expand Up @@ -195,7 +199,7 @@ def lockfile_test(name = None):
cmd = 'sed "s/{}/<LOCKVERSION>/g" "$<" > "$@"'.format(lock_version),
visibility = ["//visibility:private"],
)
for (out, what) in BZL_FILES.items()
for (out, what) in BZLMOD_FILES.items()
]

write_source_files(
Expand All @@ -206,7 +210,7 @@ def lockfile_test(name = None):
"snapshots/%s" % f,
":extract-%s" % f,
)
for f in BZL_FILES.keys()
for f in BZLMOD_FILES.keys()
],
),
# Target names may be different on workspace vs bzlmod
Expand All @@ -217,3 +221,40 @@ def lockfile_test(name = None):
# Target names may be different on bazel versions
tags = ["skip-on-bazel6"],
)

# buildifier: disable=no-effect
[
native.genrule(
name = "extract-%s" % out,
srcs = [what.replace("VERSION", lock_version).replace("REPO_NAME", lock_repo)],
outs = ["snapshot-extracted-%s" % out],
cmd = 'sed "s/{}/<LOCKVERSION>/g" "$<" | sed "s/system_tar = \\".*\\"/system_tar = \\"<TAR>\\"/" > "$@"'.format(lock_version),
visibility = ["//visibility:private"],
# Target names may be different on workspace vs bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
for (out, what) in WKSP_FILES.items()
]

write_source_files(
name = "wksp-repos",
files = dict(
[
(
"snapshots/%s" % f,
":extract-%s" % f,
)
for f in WKSP_FILES.keys()
],
),
# Target names may be different on workspace vs bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
# Target names may be different on bazel versions
tags = ["skip-on-bazel6"],
)
5 changes: 5 additions & 0 deletions e2e/pnpm_lockfiles/update-snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ bazel run @@//v54:repos
bazel run @@//v60:repos
bazel run @@//v61:repos
bazel run @@//v90:repos

bazel run --enable_bzlmod=false @@//v54:wksp-repos
bazel run --enable_bzlmod=false @@//v60:wksp-repos
bazel run --enable_bzlmod=false @@//v61:wksp-repos
bazel run --enable_bzlmod=false @@//v90:wksp-repos
Loading

0 comments on commit c1631a8

Please sign in to comment.