npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-doctest

v0.1.0

Published

Run doctests embedded in JSDoc-style comments for JS/TS files.

Downloads

100

Readme

node-doctest

node-doctest 是一个轻量级的 Node.js doctest 运行器, 可以直接在jsdoc中写测试用例,直接运行node-doctest后进行测试运行。

它会扫描 JavaScript/TypeScript 源码文件,从带有 @test 的 JSDoc 注释中提取代码块并执行测试。

功能特性

  • 支持 .ts.mts.cts.tsx.js.mjs.cjs.jsx
  • 在源文件作用域内执行 doctest 代码
  • 支持 TS/JS 混合项目的本地导入解析
  • 会读取 .gitignore 并忽略常见目录

安装

从 npm 安装(推荐开发依赖):

npm install --save-dev node-doctest

或全局安装:

npm install -g node-doctest

使用方式

在当前项目运行 doctest:

node-doctest

如果是开发依赖安装,建议使用:

npx node-doctest

对指定路径运行 doctest:

node-doctest tests

可同时传入多个文件或目录:

node-doctest src/index.ts tests/ts

返回结果:

▶ mult suit test
  ✔ strictEqual (0.293375ms)
✔ mult suit test (0.73675ms)
✔ strictEqual (0.063208ms)
PASS tests/js/plus.js:4
PASS tests/jsx/add.jsx:4
PASS tests/ts/math.ts:6
PASS tests/ts/math.ts:16
PASS tests/ts/math.ts:31
PASS tests/ts/mutl.ts:4
PASS tests/tsx/add.tsx:4

Doctest result: ok. 7 passed; 0 failed; 7 total.

Doctest 写法

在 JSDoc 注释中添加 @test,并在 fenced code block 里写可执行测试代码:

/**
 * 两数相加。
 *
 * @test
 * ```
 * assert.equal(1 + 2, 3);
 * ```
 */
export function add(a: number, b: number) {
  return a + b;
}

在 doctest 代码中可直接使用 asserttestit

许可证

MIT