如何在 Github 中显示我的测试通过/失败?

我在 github 上有一个项目,它有大量的单元测试(使用 mocha for node.js)。

我想通过在每一页上展示那些通过/不及格的测试来炫耀一下。我注意到 Github 上的其他项目也在这么做。

enter image description here

我找不到任何关于如何显示测试状态的文档。

  • 如何让 Github 显示单元测试输出?
  • Github 是运行测试还是需要连接一个外部 Web 应用程序?
  • 有没有免费的网络服务可以做到这一点(我的应用程序是开源的) ?
31933 次浏览

Take a look at Travis CI. You can use it with GitHub.

They have docs on using NodeJS

Those badges you see are called "status images" and Travis provides MarkDown that you can insert into your project's README.md file.

Note that since April 26th 2013, you can see the build status on your GitHub repo branch page:

build status on GitHub repo branches

The Commit Status API allows you to use that elsewhere: see " Repo Statuses API".

Starting April 30th, 2013, the API endpoint for commit statuses has been extended to allow branch and tag names, as well as commit SHAs.

CircleCI the status badges are also simply images that you can drop into your README.md file with the markdown. For example:

![Build Status](https://circleci.com/gh/<your github name>/<repo name>.png?circle-token=:circle-token)

or

![Build Status](https://circleci.com/gh/<your github name>/<repo name>.svg?style=shield&circle-token=:circle-token)

GitHub also has workflow status badges for GitHub Actions.

The image is usually embedded into the README.md file using Markdown like this:

![example workflow](https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/<WORKFLOW>.yml/badge.svg)