Skip to content

Comments

add tests to doc comments and README.md#20

Merged
nberlette merged 28 commits intomainfrom
patch/add-tests
Nov 24, 2025
Merged

add tests to doc comments and README.md#20
nberlette merged 28 commits intomainfrom
patch/add-tests

Conversation

@nberlette
Copy link
Owner

  • 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

Copilot AI review requested due to automatic review settings November 19, 2025 18:11
@nberlette nberlette added docs Improvements or additions to documentation tests Issues and pull requests involving unit tests or testdata. labels Nov 19, 2025
@nberlette nberlette self-assigned this Nov 19, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 128 to 129
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
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines 115 to 117
while (( ${#args[@]} < idx + 2 )); do
args+=("${args[idx + ${#args[@]} - idx]}")
done
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines 99 to 100
"scripts",
"!lib"
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
"scripts",
"!lib"
"scripts"

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +138
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();
}
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
- 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`
@nberlette nberlette merged commit a172a71 into main Nov 24, 2025
1 of 2 checks passed
@nberlette nberlette deleted the patch/add-tests branch November 24, 2025 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation tests Issues and pull requests involving unit tests or testdata.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant