Skip to content

Commit 5ef109d

Browse files
authored
fix: add e2e/smoke to tar so bcr presubmit can run (#20)
### TL;DR Add a smoke test for rules_formatjs and include it in release artifacts. ### What changed? - Created a new smoke test in `e2e/smoke/` directory with a minimal setup to verify FormatJS CLI functionality - Updated BCR presubmit configuration to use the new smoke test instead of the previous example - Enhanced the release preparation script to include the smoke test in release artifacts - Added testing instructions to the release notes ### How to test? Run the smoke test with: ```bash cd e2e/smoke bazel build //:extract ``` This will extract messages from a simple React component and verify that the FormatJS CLI toolchain is working correctly. ### Why make this change? This change provides users with a simple way to verify that rules_formatjs works in their environment without needing to set up a complex example. Including the smoke test in the release artifact makes it easier for users to test the rules immediately after installation, improving the user experience and reducing potential setup issues.
1 parent c925b8c commit 5ef109d

9 files changed

Lines changed: 395 additions & 2 deletions

File tree

.bcr/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
bcr_test_module:
2-
module_path: "examples/simple"
2+
module_path: "e2e/smoke"
33
matrix:
44
platform: ["debian10", "macos", "ubuntu2004"]
55
bazel: ["8.x"]

.github/workflows/release_prep.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ PREFIX="rules_formatjs-${TAG:1}"
1212
ARCHIVE="rules_formatjs-$TAG.tar.gz"
1313

1414
# NB: configuration for 'git archive' is in /.gitattributes
15-
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
15+
# Create the main archive
16+
git archive --format=tar --prefix=${PREFIX}/ ${TAG} > "${ARCHIVE%.gz}"
17+
18+
# Add e2e/smoke test to the archive (examples are excluded by .gitattributes but we want smoke test included)
19+
# Create a temporary directory with the smoke test in the right structure
20+
TMPDIR=$(mktemp -d)
21+
mkdir -p "${TMPDIR}/${PREFIX}/e2e"
22+
# Copy smoke test but exclude bazel output directories and lock files
23+
rsync -a --exclude='bazel-*' --exclude='MODULE.bazel.lock' e2e/smoke/ "${TMPDIR}/${PREFIX}/e2e/smoke/"
24+
tar -rf "${ARCHIVE%.gz}" -C "${TMPDIR}" .
25+
rm -rf "${TMPDIR}"
26+
27+
# Compress the archive
28+
gzip "${ARCHIVE%.gz}"
29+
1630
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
1731

1832
# Add generated API docs to the release, see https://github.com/bazelbuild/bazel-central-registry/issues/5593
@@ -34,4 +48,15 @@ bazel_dep(name = "rules_formatjs", version = "${TAG:1}")
3448
\`\`\`
3549
3650
That's it! The toolchains are automatically registered.
51+
52+
## Testing the Installation
53+
54+
A smoke test is included in the release at \`e2e/smoke/\`. To verify the rules work in your environment:
55+
56+
\`\`\`bash
57+
cd e2e/smoke
58+
bazel build //:extract
59+
\`\`\`
60+
61+
This will extract messages from a simple React component and verify that the FormatJS CLI toolchain is working correctly.
3762
EOF

e2e/smoke/.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Minimal bazelrc for smoke test
2+
common --enable_bzlmod

e2e/smoke/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@rules_formatjs//formatjs:defs.bzl", "formatjs_extract")
2+
3+
# Extract messages from source files
4+
formatjs_extract(
5+
name = "extract",
6+
srcs = ["src/Hello.tsx"],
7+
out = "messages.json",
8+
)

e2e/smoke/MODULE.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Smoke test for rules_formatjs - minimal test to verify basic functionality"""
2+
3+
module(
4+
name = "smoke_test",
5+
version = "0.0.0",
6+
)
7+
8+
bazel_dep(name = "rules_formatjs", version = "0.0.0")
9+
local_path_override(
10+
module_name = "rules_formatjs",
11+
path = "../..",
12+
)

e2e/smoke/MODULE.bazel.lock

Lines changed: 295 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/smoke/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Smoke Test
2+
3+
This is a minimal end-to-end test that verifies basic functionality of `rules_formatjs`.
4+
5+
## Purpose
6+
7+
This smoke test is included in the release artifact to allow users to quickly verify that the rules work in their environment without needing to set up a complex example.
8+
9+
## What it tests
10+
11+
- Basic message extraction from a React component using `formatjs_extract`
12+
- FormatJS CLI toolchain selection and execution
13+
- Module extension setup and toolchain registration
14+
15+
## Running the test
16+
17+
From this directory:
18+
19+
```bash
20+
bazel build //:extract
21+
```
22+
23+
This should successfully extract messages from `src/Hello.tsx` and produce a `messages.json` file with the extracted internationalization messages.
24+
25+
## Expected output
26+
27+
The build should succeed and produce `bazel-bin/messages.json` containing:
28+
29+
```json
30+
{
31+
"hello.world": {
32+
"id": "hello.world",
33+
"defaultMessage": "Hello, World!",
34+
"description": "Simple greeting message"
35+
}
36+
}
37+
```

e2e/smoke/REPO.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Marker file for Bazel workspace

e2e/smoke/src/Hello.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FormattedMessage } from "react-intl";
2+
3+
export function Hello() {
4+
return (
5+
<div>
6+
<FormattedMessage
7+
id="hello.world"
8+
defaultMessage="Hello, World!"
9+
description="Simple greeting message"
10+
/>
11+
</div>
12+
);
13+
}

0 commit comments

Comments
 (0)