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

react-test-mate

v4.0.1

Published

test react project with no configuration

Downloads

38

Readme

react-test-mate

React项目零配置集成jest单元测试。

使用

Install

yarn add --dev react-test-mate

如果React是15版本的话,还需要添加对应的react-test-renderer:

yarn add --dev enzyme-adapter-react-15 react-test-render@15

package.json中添加命令:

{
  "scripts": {
    "test": "test-mate",
    "cov": "test-mate --coverage"
  }
}

编写单元测试

__tests__/     # <-- 可将单元测试统一放在 __tests__ 目录下
src/
  Hello.js
  Hello.test.js    # <-- 也可以使用这种命令约定编写。

运行

yarn test

然后根据提示使用命令执行,比如使用a,则运行所有单元测式。

运行测试,且输出覆盖率。

yarn cov

其他问题

alias

为了测试方便,可能需要配置模块的alias,此时可添加.babelrc文件。

yarn add --dev babel-plugin-module-resolver
{
  "plugins": [
    ["module-resolver", {
      "alias": {
        "components": "./src/components"
      }
    }]
  ]
}

备注:为了不影响正常文件的编译,可以只针对测试环境下开启

{
  "env": {
    "test": {
      "plugins": [
        ["module-resolver", {
          "alias": {
            "components": "./src/components"
          }
        }]
      ]
    }
  }
}

test url

默认的 testUrl 为 http://localhost,可以使用环境变量TEST_URL自定义。

可以在package.json中配置,也可以在命令行中指定环境变量:

{
  "test": "TEST_URL=http://mytest.com test-mate"
}

fixtures and supports

有时候需要一些测试帮助文件,或fixtures文件,可把这些文件放在

tests/supports 和 tests/fixtures 目录下,jest会忽略这两个目录,否则jest会发出警告,说在文件中找不到测试。

祝编码快乐!!