Conversation
nberlette
commented
Nov 19, 2025
- chore: rename build.ts -> scripts/build.ts
- chore: rename test.ts -> mod.test.ts
- deps(test): add explicit assertion imports
- chore(test): add unit tests for all comrak options
- chore: fmt
- chore: add .coverage to gitignore
- fix: typo in LICENSE
- config: pin rust toolchain channel to 1.86.0
- perf: add benchmarks
- fix: missing rule in publish config causing failing builds
- chore: add author field to deno.json
- config: update tasks in deno.json
- chore: update rustfmt config
- config: add wasm-opt patch scripts
- chore: ensure build script is executable
- config: update rust-toolchain.toml to stable channel
- tests: update mod.test.ts
- perf: improve and expand benchmarks in mod.bench.ts
- config: update deno.json
- chore: update and fmt deno.json again
Signed-off-by: Nicholas Berlette <nick@berlette.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive test coverage and benchmarks for the comrak WASM package, along with tooling improvements and configuration updates. The main focus is on adding unit tests for all comrak options and improving the development workflow.
Key Changes
- Added comprehensive unit tests for all extension, parse, and render options in
mod.test.ts - Added performance benchmarks comparing different versions of the package
- Introduced custom WASM optimization scripts to enhance build process control
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| test.ts | Deleted original simple test file (moved to mod.test.ts) |
| mod.test.ts | New comprehensive test suite covering all comrak options with 282 lines of tests |
| mod.bench.ts | New benchmark file comparing performance across package versions |
| scripts/build.ts | Added shebang for direct execution |
| scripts/wasm_opt.sh | New wrapper script for customizing wasm-opt behavior (has critical bugs) |
| scripts/patch_wasm_opt.sh | New script to patch wasm-opt binary with custom wrapper (has bugs) |
| deno.json | Extensive updates to tasks, publish config, and metadata |
| rust-toolchain.toml | Changed from nightly to stable channel, added cargo component |
| .rustfmt.toml | Updated formatting rules with additional options |
| .gitignore | Added .coverage directory for test coverage output |
| LICENSE | Fixed typo in copyright notice |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
scripts/patch_wasm_opt.sh
Outdated
| echo -e $' \e[2;3;4moriginal:\e[0m '"${WASM_OPT_BINARY}"$' \e[2m('"$(stat --printf=%s "${WASM_OPT_BINARY}")"$' B)\e[0m' >&2 | ||
| echo -e $' \e[2;3;4mwrapper:\e[0m '"${WASM_OPT_WRAPPER}"$' \e[2m('"$(stat --printf=%s "${WASM_OPT_WRAPPER}")"$' B)\e[0m' >&2 |
There was a problem hiding this comment.
The stat --printf=%s command uses GNU stat syntax, which is not portable to macOS/BSD systems. On macOS, this should be stat -f %z. Consider using a portable alternative like wc -c < "$file" or detecting the OS and using the appropriate stat syntax.
| echo -e $' \e[2;3;4moriginal:\e[0m '"${WASM_OPT_BINARY}"$' \e[2m('"$(stat --printf=%s "${WASM_OPT_BINARY}")"$' B)\e[0m' >&2 | |
| echo -e $' \e[2;3;4mwrapper:\e[0m '"${WASM_OPT_WRAPPER}"$' \e[2m('"$(stat --printf=%s "${WASM_OPT_WRAPPER}")"$' B)\e[0m' >&2 | |
| echo -e $' \e[2;3;4moriginal:\e[0m '"${WASM_OPT_BINARY}"$' \e[2m('"$(wc -c < "${WASM_OPT_BINARY}" | xargs)"$' B)\e[0m' >&2 | |
| echo -e $' \e[2;3;4mwrapper:\e[0m '"${WASM_OPT_WRAPPER}"$' \e[2m('"$(wc -c < "${WASM_OPT_WRAPPER}" | xargs)"$' B)\e[0m' >&2 |
scripts/wasm_opt.sh
Outdated
| while (( ${#args[@]} < idx + 2 )); do | ||
| args+=("${args[idx + ${#args[@]} - idx]}") | ||
| done |
There was a problem hiding this comment.
This loop will cause an infinite loop or array index out of bounds error. When ${#args[@]} < idx + 2, the expression ${args[idx + ${#args[@]} - idx]} simplifies to ${args[${#args[@]}]}, which accesses an index beyond the array bounds (arrays are 0-indexed, so max valid index is ${#args[@]} - 1). This will result in an empty string being added repeatedly, never satisfying the loop condition.
| while (( ${#args[@]} < idx + 2 )); do | |
| args+=("${args[idx + ${#args[@]} - idx]}") | |
| done | |
| # Save the last two original arguments before deduplication | |
| orig_last_arg1="${args[idx]}" | |
| orig_last_arg2="${args[idx+1]}" | |
| if (( ${#args[@]} < idx + 2 )); then | |
| args+=("$orig_last_arg1" "$orig_last_arg2") | |
| fi |
| "scripts", | ||
| "!lib" |
There was a problem hiding this comment.
[nitpick] The negation pattern "!lib" appears unnecessary since none of the preceding exclude patterns would match the lib directory. The include list already has **/*.js and **/*.wasm which will include files from lib. Consider removing this line for clarity, or if it's meant as a safeguard, add a comment explaining its purpose.
| "scripts", | |
| "!lib" | |
| "scripts" |
| baseline, | ||
| async fn() { | ||
| const pkg = await target.package() as ( | ||
| [typeof target.package] extends [() => infer U] ? Awaited<U> : never | ||
| ); | ||
| if ("init" in pkg && typeof pkg.init === "function") { | ||
| await pkg.init(); | ||
| } |
There was a problem hiding this comment.
The benchmark is importing and potentially initializing the package on every iteration of the benchmark function. This will skew the benchmark results significantly since the dynamic import and initialization overhead will be included in each timing measurement. The import and initialization should be done once before the benchmark runs, outside the fn callback. Consider moving lines 132-137 to a setup phase or using beforeEach if available.
- brotli compression is now only applied if the uncompressed WASM binary
exceeds 750 KB, or if explicitly requested via `WASM_COMPRESS_FORCE=1`
- removed top-level await from the generated JS file for improved compat
- enables `require()`-ing the output ESM module in newer Node versions
- instead of using a dynamic import to load the decompressor, we just
import it statically at the top of the file from the brotli module
bundled alongside the other files
- added support for `WASMBUILD_VERSION` env var to use a custom version
of `@deno/wasmbuild` when building the WASM binary. if unspecified,
the default remains `0.19.1`.
- add support for configurable brotli quality via the `WASM_COMPRESS`
variable (default: `11`). set to `0` to disable brotli compression.
- rename constants to screaming snake case for consistency and clarity
- updated dependencies
- improved comments and code structure in `scripts/build.ts`