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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@darcytech/jest-preset-darcytech

v2.3.0

Published

jest 基础可共享配置

Downloads

95

Readme

@darcytech/jest-preset-darcytech

简介

jest 的基础、可共享配置。

安装

npm i --save-dev @darcytech/jest-preset-darcytech jest

用法

//jest-config.js
module.exports = {
  preset: '@darcytech/jest-preset-darcytech',
};

个别配置介绍

  • collectCoverageFrom:指定了统计覆盖率信息时,应该从哪些文件收集信息。该配置将在项目目录下的 src 文件夹中收集测试覆盖率。
  • moduleFileExtensions:指定了一组模块文件的扩展名。如果你 require 模块的时候,没有指定文件扩展名,jest 会从左往右匹配文件。注意:如果你项目中使用的是 js,jsx,那么最好覆盖这个配置,将 js,jsx 放到数组的开头。
  • moduleNameMapper:这里指定了一些静态资源的 mock。
  • testMatch:这里指定tests为所有测试文件的根目录。
  • timers:这里指定 @sinonjs/fake-timers 作为 fake timers 的 实现
  • transform:指定 node_modules 文件中的所有代码不会被转换

常见问题

1.配置 jest 时,你觉得配置没问题,但是测试就是失败。

可能是缓存的问题。运行测试可以加上 --no-cache 。配置好 jest 后,记得将 --no-cache 去掉,因为这会影响测试性能。如果想要删除缓存,可以参考--clearCache

2. Mocking not working

内部使用了 @swc/jest ,mock api 时,需要将 mock 的代码写到另一个文件,并在测试文件顶部引入。

// mock.ts
import { jest } from '@jest/globals';

jest.mock('apis/taskAutoAssignApi');
jest.mock('apis/taskTemplateApi');
// a.test.ts
import 'mock';
// 其他代码