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

finance-unit-test

v1.0.4

Published

### 使用方式

Downloads

6

Readme

单元测试配置集成

使用方式

step1

    npm install --save-dev finance-unit-test

step2

 在package.json 中添加一条script语句:  "test": "finance-unit-test"。
 
 可以配置cli参数;  
 eg:"test": "finance-unit-test --watchAll"。
 cli 参数文档 https://jestjs.io/docs/zh-Hans/cli
  

step3

在项目src 下创建 __test__ 文件夹,在该文件夹下编写测试用例

tip:建议测试用例写在__test__ 文件夹下,实际上在./src下任何一个地方都可以写测试用例。
./src 目录位置在config.roots字段中可以配置

说明

1.如若修改或添加jest配置, 可以在项目跟目录下config 目录下可以配置jest.config.js文件,内容如下

  module.exports = (defaultConfig) => {
      console.log('defaultConfig', defaultConfig);
      return defaultConfig;
  }

defaultConfig可以查看所有的默认配置,这里可以更改所有的jest配置。
jest 配置文档 https://jestjs.io/docs/en/configuration

2.earth-script项目文件引入会使用webpack中的alias功能,在jest配置文件中也会默认使用config/alias.js中的文件映射,具体配置可以查看defaultConfig.moduleNameMapper

3.引入enzyme中的mount、shallow、render 方法可以直接通过 import { mount, render, shallow } from 'finance-unit-test';方式引用。

例子

```
    1.引入React 
    import React from 'react'
    2.引入需要测试的组件
    import Component from '../path/Component'
    3.引入组件的渲染方式
    import { shallow } from 'finance-unit-test';
    
    4.正式写测试用例
    
    describe('test Component', () => {
         beforeEach(() => {
            // 需要在执行每个case之前作出的处理
            fetch.resetMocks();
         });
         
         beforeAll(() => {
             // 需要在执行所有case之前作出的处理
         })
         
         afterEach(() => {
            
         })
         
         afterAll(() => {1
            
         })
            
        it('组件正常渲染', () => {
            const wrapper = shallow(<Component />);
            expect(wrapper.find('.class')).toHaveBeenLengh(1);
        })
    })
```

项目地址

http://igit.58corp.com/58finance_fed/finance-unit-test

测试用例demo地址

https://github.com/Zuoguangcheng/reactUnitExample

版本记录

V1.0.3

 1.init
 

V1.0.4

 1.增加ts tsx支持
 2.增加webpack中alias在jest中的支持,默认使用config/alias.js中的映射