Skip to content

Commit 559b4b1

Browse files
authored
Merge pull request #131 from RAprogramm/130
130
2 parents c3dd58f + c1127f0 commit 559b4b1

File tree

8 files changed

+241
-18
lines changed

8 files changed

+241
-18
lines changed

.github/workflows/reusable-ci.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ jobs:
188188

189189
# 📊 Coverage
190190
coverage:
191-
name: Coverage
191+
name: Coverage (Native)
192192
runs-on: ubuntu-latest
193193
needs: setup
194194
steps:
@@ -224,3 +224,52 @@ jobs:
224224
files: lcov.info
225225
fail_ci_if_error: true
226226
verbose: true
227+
flags: native
228+
229+
# 📊 WASM Coverage
230+
wasm-coverage:
231+
name: Coverage (WASM)
232+
runs-on: ubuntu-latest
233+
needs: setup
234+
steps:
235+
- uses: actions/checkout@v5
236+
237+
- name: Install Rust nightly
238+
uses: dtolnay/rust-toolchain@v1
239+
with:
240+
toolchain: nightly
241+
targets: wasm32-unknown-unknown
242+
components: llvm-tools-preview
243+
244+
- name: Cache cargo
245+
uses: Swatinem/rust-cache@v2
246+
with:
247+
shared-key: "nightly-wasm"
248+
save-if: ${{ github.ref == 'refs/heads/main' }}
249+
250+
- name: Install wasmcov
251+
shell: bash
252+
run: |
253+
set -euo pipefail
254+
cargo +nightly install wasmcov
255+
256+
- name: Run WASM tests with coverage
257+
shell: bash
258+
run: |
259+
set -euo pipefail
260+
cargo +nightly wasmcov test -- --all-features -- --test-threads=1
261+
262+
- name: Generate WASM coverage report
263+
shell: bash
264+
run: |
265+
set -euo pipefail
266+
cargo +nightly wasmcov report -- export --format=lcov > wasm-lcov.info
267+
268+
- name: Upload WASM coverage to Codecov
269+
uses: codecov/codecov-action@v5
270+
with:
271+
token: ${{ secrets.CODECOV_TOKEN }}
272+
files: wasm-lcov.info
273+
fail_ci_if_error: true
274+
verbose: true
275+
flags: wasm

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
/wasmcov

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ members = ["demo"]
8585
[dev-dependencies]
8686
wasm-bindgen-test = "0.3"
8787
wasm-bindgen-futures = "0.4"
88+
wasmcov = "0.2"

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@
2323

2424
`telegram-webapp-sdk` provides a type-safe and ergonomic wrapper around the [Telegram Web Apps](https://core.telegram.org/bots/webapps) JavaScript API.
2525

26-
> [!WARNING]
27-
> **Coverage Limitations**
26+
> [!NOTE]
27+
> **Comprehensive Coverage**
2828
>
29-
> This project is primarily WASM-only code. Current Rust tooling does not support coverage measurement for wasm32 targets:
30-
> - `cargo-llvm-cov` only supports native platforms (x86_64)
31-
> - `wasm-bindgen-test` coverage support is experimental and requires complex setup
32-
> - `cargo-tarpaulin` does not support wasm32
29+
> This project achieves comprehensive test coverage for both native and WASM code:
30+
> - Native code coverage via `cargo-llvm-cov`
31+
> - WASM code coverage via `wasmcov` with nightly toolchain
3332
>
34-
> Coverage reports show only native-testable code. WASM-specific modules (leptos, yew, api/*, webapp, logger) have integration tests but are not included in coverage metrics.
33+
> Coverage reports include all modules (leptos, yew, api, webapp, logger, pages, router) ensuring quality across the entire codebase.
3534
>
36-
> For technical details, see [issue #127](https://github.com/RAprogramm/telegram-webapp-sdk/issues/127).
35+
> For implementation details, see [issue #130](https://github.com/RAprogramm/telegram-webapp-sdk/issues/130).
3736
3837
<details>
3938
<summary>Coverage Graphs</summary>

REUSE.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ path = "demo/dist/**"
5656
precedence = "aggregate"
5757
SPDX-FileCopyrightText = "2025 RAprogramm <andrey.rozanov.vl@gmail.com>"
5858
SPDX-License-Identifier = "CC0-1.0"
59+
60+
[[annotations]]
61+
path = "wasmcov/**"
62+
precedence = "aggregate"
63+
SPDX-FileCopyrightText = "2025 RAprogramm <andrey.rozanov.vl@gmail.com>"
64+
SPDX-License-Identifier = "CC0-1.0"

codecov.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ coverage:
1414
threshold: 2%
1515
informational: false
1616

17+
flags:
18+
native:
19+
paths:
20+
- src/
21+
carryforward: true
22+
wasm:
23+
paths:
24+
- src/
25+
carryforward: true
26+
1727
comment:
1828
layout: "header,diff,flags,components,files,footer"
1929
behavior: default
@@ -24,15 +34,6 @@ ignore:
2434
- "tests/**/*"
2535
- "target/**/*"
2636
- ".github/**/*"
27-
- "src/leptos.rs"
28-
- "src/leptos/**/*"
29-
- "src/yew.rs"
30-
- "src/yew/**/*"
31-
- "src/api/**/*"
32-
- "src/webapp.rs"
33-
- "src/logger.rs"
34-
- "src/pages.rs"
35-
- "src/router.rs"
3637

3738
github_checks:
3839
annotations: true

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,22 @@ pub mod yew;
3131

3232
#[cfg(feature = "leptos")]
3333
pub mod leptos;
34+
35+
/// Captures code coverage data for WASM builds.
36+
///
37+
/// This function is used by wasmcov to collect coverage information during test
38+
/// execution. It should not be called directly in application code.
39+
///
40+
/// # Safety
41+
///
42+
/// This function is marked as unsafe due to FFI requirements.
43+
/// It is only exported for wasm32 targets and called by the wasmcov test
44+
/// harness.
45+
#[cfg(all(target_family = "wasm", test))]
46+
#[no_mangle]
47+
pub unsafe extern "C" fn capture_coverage() {
48+
let mut coverage = Vec::new();
49+
if let Err(e) = wasmcov::minicov::capture_coverage(&mut coverage) {
50+
web_sys::console::error_1(&format!("Coverage capture failed: {}", e).into());
51+
}
52+
}

0 commit comments

Comments
 (0)