This file provides development guidelines for contributors and guidance to Claude Code, Qwen Coder and similar tools when working with code in this repository.
This is a CLI tool that measures internet connection speed and latency using Cloudflare's speed test infrastructure at speed.cloudflare.com. The tool is written in Node.js and can be compiled to a standalone binary using Deno.
node cli.js- Run the speed test with colorized outputnode cli.js --json- Run the speed test and output results as JSONnpx speed-cloudflare-cli- Run via npm (when installed globally)make clean integration-test ARG=--jsonwill rebuild the binary and then execute it with json output
makeormake all- Compile the CLI to a standalone binary using Denomake clean- Remove the compiled binary- The compiled binary is named
cloudflare-speedtest
make testornpm test- Run the complete test suite with Jestmake integration-test- Run integration tests with the compiled binary- Tests include comprehensive mocking of network functions and cover:
- Network request functions (get, fetchServerLocationData, fetchCfCdnCgiTrace)
- Speed measurement functions (measureLatency, measureDownload, measureUpload)
- Statistical calculations (stats.js functions)
- Logging and formatting functions
- Command-line argument parsing
npx eslint .- Run ESLint for code lintingnpx prettier --check .- Check code formattingnpx prettier --write .- Auto-format code- All files must follow
.editorconfigconventions:- End with final newline (
insert_final_newline = true) - No trailing whitespace (
trim_trailing_whitespace = true) - 2-space indentation for most files, tabs for Makefile
- Use
git ls-files -z | xargs -0 grep -Pzlv '\x0a$'to find files missing final newlines - Use
git ls-files -z | xargs -0 grep -l '[[:space:]]$'to find files with trailing whitespace
- End with final newline (
cli.js- Main entry point that imports and runs speedTest from lib.jslib.js- Core library containing all speed test logic and functions (exported for testing)stats.js- Statistical utilities (average, median, quartile, jitter calculations)chalk.js- Custom color formatting utilities for terminal outputtest/- Jest test suite with comprehensive mocks for network functions
speedTest()- Main orchestrator function that runs the complete speed testmeasureLatency()- Performs 20 ping tests to measure network latencymeasureDownload(bytes, iterations)- Tests download speed with various file sizesmeasureUpload(bytes, iterations)- Tests upload speed with various file sizesrequest(options, data)- Low-level HTTPS request function with performance timing
- Fetches server location data and client IP information from Cloudflare
- Measures latency with 20 small requests (1KB each)
- Tests download speeds with progressively larger files: 100kB, 1MB, 10MB, 25MB, 100MB
- Tests upload speeds with: 10kB, 100kB, 1MB
- Calculates statistics using median for individual tests and 90th percentile for overall speeds
- Default: Colorized terminal output showing server location, IP, latency stats, and speed results
--json: Structured JSON output suitable for programmatic consumption
- No runtime dependencies (uses only Node.js built-ins)
- Dev dependencies: ESLint, Prettier for code quality, Jest for testing, TypeScript for language server support
- Compilation: Requires Deno for creating standalone binaries
- Creates new HTTPS agents for each request to avoid connection reuse affecting measurements
- Uses performance timing hooks to measure different phases of HTTP requests (DNS, TCP, SSL, TTFB)
- Implements custom statistical functions rather than using external libraries to minimize dependencies