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

@kooboo/vitest-plugin

v0.0.3

Published

A Vitest plugin for Kooboo.

Readme

@kooboo/vitest-plugin

一个自定义的 Vitest 插件。

安装

npm install vitest @kooboo/vitest-plugin --save-dev

使用方法

1. 项目根目录下添加vitest.config.ts

vitest.config.ts 中添加@kooboo/vitest-plugin的引用以及配置setupFiles:

import { resolve } from "node:path";
import { defineConfig } from "vitest/config";
import koobooPlugin from "@kooboo/vitest-plugin";

export default defineConfig({
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
  test: {
    globals: true,
    environment: "node",
    include: ["tests/**/*.spec.ts"],
    setupFiles: ["tests/kooboo.setup.ts"], // 插件自动生成的setup文件
  },
  plugins: [koobooPlugin()],
});

.gitignore中忽略tests/kooboo.setup.ts文件,防止插件自动生成的setup文件被提交到代码仓库。

kooboo.setup.ts

2. 创建tests文件夹以及tsconfig.json

在项目根目录下创建tests文件夹,并在其中创建tsconfig.json文件,内容如下:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["../src/*"]
    },
    "types": ["../kooboo.d.ts"]
  }
}

3. 在package.json中添加"test": "vitest"

package.json文件的scripts字段中添加"test": "vitest",这样就可以使用npm test命令来运行测试了。

4. 编写测试用例

tests文件夹中编写测试用例,测试用例的文件命名规则为*.spec.ts, 例如tests/service.spec.ts

// `src/code/service.ts`
export function sayHello(name: string) {
  const url = k.site.getHomeUrl()
  return `hello ${name}, from ${url}`;
}
// `tests/service.spec.ts`
import { describe, it, expect, vi } from "vitest";
import { sayHello } from "@/code/service";

describe("service", () => {
  it("sayHello should work correctly", () => {
    // 1. mock kooboo function
    vi.spyOn(k.site, "getHomeUrl").mockReturnValue("https://mock.kooboo.com");

    // 2. call sayHello function
    const result = sayHello("kooboo");

    // 3. assert result
    expect(result).toBe("hello kooboo, from https://mock.kooboo.com");
  });
});

License

MIT