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

@agds/jest-config-node

v1.0.5

Published

agds系统的node平台jest预设

Readme

@agds/jest-config-node

版本 :1.0.5

agds系统的node平台jest预设

快速开始

安装

npm i -D @agds/jest-config-node

引入

// jest.config.js

const { PresetUtils } = require('@agds/node-utils');
// 强化jest的presets功能
module.exports = PresetUtils.getDeepPresetMergeAndModify({
    presets: [
        require('@agds/jest-config-node')({
            entry: 'src/index.js',
        }),
    ],
});

此配置规定了默认的测试用例文件路径

root/test/__test__

推荐的项目目录设置

root                       # 项目根目录
├── test                   # jest测试用例目录
│   ├── __mock__           # mock内容目录
│   │   └── index.js       # mock模块
│   └── __test__           # 测试用例目录
│       └── index.js       # 测试用例
└── package.json

添加test脚本

package.jsonscripts下添加test命令;

{
    "scripts":{
        "test": "jest"
    }
}

添加npm或者git生命周期钩子运行test

例如:在package.jsonscripts下添加prebuild命令;

{
    "scripts":{
        "prebuild": "npm run test"
    }
}

添加测试用例

root/test/__test__目录下

// 引入`@jest/globals`获得更好的编写体验
const { expect, test } = require('@jest/globals');
// 配置支持使用包名作为模块入口的别名,仅支持main声明的路径
const src = require('<pkg.name>');
test('test1', async () => {
    const res = await src();
    expect(typeof res === 'string').toBe(true);
});

配置源码

const { FastPath, FastFs } = require('@agds/node-utils');
const pkgPath = FastPath.getCwdPath('package.json');
const path = require('path');
let pkg = {};
if (FastFs.getPathStatSync(pkgPath)) {
    pkg = require(pkgPath);
}
module.exports = ({ entry = 'src/index.js' } = {}) => ({
    collectCoverage: true,
    testEnvironment: 'node',
    roots: [
        '<rootDir>/test',
    ],
    moduleNameMapper: {
        [`^${pkg.name}$`]: path.join('<rootDir>', entry),
    },
    coverageThreshold: {
        global: {
            statements: 100,
            branches: 100,
            functions: 100,
            lines: 100,
        },
    },
    testRegex: 'test/__test__/(.+)\\.(jsx?)$',
    moduleFileExtensions: ['js', 'jsx', 'json', 'node'],
    collectCoverageFrom: [
        'src/**/*.{js,jsx}',
        '!**/node_modules/**',
        '!**/test/**',
    ],
});

许可证

MIT License Copyright (c) 2021 锦阳

请维护者喝杯咖啡

加入钉钉群讨论或加入开发