Jest 测试框架配置 jest-stare
简述安装步骤:
默认你已经配置好jest了, 如果没有可以看我往期的笔记
- 安装 jest-stare 依赖
npm install jest-stare --dev
- 配置 package.json 文件
{"name": "jest-stare","version": "1.0.0","scripts": {"test-rep": "jest --reporters default jest-stare"},"keywords": [],"author": "","license": "ISC","dependencies": {"jest-stare": "^@2.3.0" // 注意:版本号要与安装 jest-stare 时一致},"reporters": ["default", "jest-stare"],"testResultsProcessor": "./node_modules/jest-stare"
}
- 配置 jest.config.js 文件
module.exports = {// Indicates whether the coverage information should be collected while executing the test// collectCoverage: true, // 这个可以依据个人需求选择是否输出测试覆盖率// Use this configuration option to add custom reporters to Jest// reporters: undefined,// jest.config.js 文件中 reporters 可以忽略,可以在 package.json 中添加 jest-stare"reporters": ["default",["jest-stare",{"resultDir": "results/jest-stare","reportTitle": "jest-stare!","additionalResultsProcessors": ["jest-junit"],"coverageLink": "../../coverage/lcov-report/index.html","jestStareConfigJson": "jest-stare.json","jestGlobalConfigJson": "globalStuff.json"}]]
};
- 创建测试文件 demo.test.ts
// demo.test.ts
describe("suit 1", () => {test('第一个测试', () => {console.log(1);});test('第二个测试', () => {expect(1).toBe(1);});test.skip('第三个测试', () => {expect(3).toBe(3);});test('第四个测试', () => {expect(4).toBe(5);});});describe("suit 2", () => {test('第五个测试', () => {expect(5).toBe(5);});
});
- 运行
npm run test-rep
- 运行效果
参考:https://www.npmjs.com/package/jest-stare
配置说明
jest-stare 字段使用举例
如果想使用 使用 jest-stare 下的字段配置测试报告格式需要在 package.json 文件中添加 jest-stare 字段 举例:
"jest-stare": {"resultDir": "results/jest-stare", // 配置输出报告的路径"reportTitle": "jest-stare!", // 设置输出报告的 title"additionalResultsProcessors": ["jest-junit"],"coverageLink": "../../coverage/lcov-report/index.html","jestStareConfigJson": "jest-stare.json","jestGlobalConfigJson": "globalStuff.json"}
jest-stare 字段列表
字段 | 环境变量 | 默认值 | 描述 | 举例 |
---|---|---|---|---|
resultDir
|
JEST_STARE_RESULT_DIR
|
jest-stare
|
set the results directory |
“resultDir”: “results/jest-stare”
|
resultJson
|
JEST_STARE_RESULT_JSON
|
jest-results.json
|
indicate the raw JSON results file name |
“resultJson”: “data.json”
|
resultHtml
|
JEST_STARE_RESULT_HTML
|
index.html
|
indicate the main html file name |
“resultHtml”: “main.html”
|
log
|
JEST_STARE_LOG
|
true
|
specify whether or not jest-stare should log to the console |
“log”: false
|
jestStareConfigJson
|
JEST_STARE_CONFIG_JSON
|
undefined
|
request to save jest-stare config raw JSON results in the file name |
“jestStareConfigJson”: “jest-stare-config.json”
|
jestGlobalConfigJson
|
JEST_STARE_GLOBAL_CONFIG_JSON
|
undefined
|
request to save global config results in the file name |
“jestGlobalConfigJson”: “global-config.json”
|
report
|
JEST_STARE_REPORT
|
undefined
|
boolean, set to false to suppress creating a HTML report (JSON only retained) |
“report”: false
|
reportTitle
|
JEST_STARE_REPORT_TITLE
|
jest-stare!
|
string, indicate the title of the report |
“reportTitle”: “my title”
|
reportHeadline
|
JEST_STARE_REPORT_HEADLINE
|
jest-stare
|
string, indicate the headline of the report |
“reportHeadline”: “my headline”
|
reportSummary
|
JEST_STARE_REPORT_SUMMARY
|
undefined
|
boolean, shows the report summary |
“reportSummary”: true
|
additionalResultsProcessors
|
JEST_STARE_ADDITIONAL_RESULTS_PROCESSORS
|
undefined
|
add additional test result processors to produce multiple report |
“additionalResultsProcessors”: [“jest-junit”]
|
coverageLink
|
JEST_STARE_COVERAGE_LINK
|
undefined
|
link to coverage report if available |
“coverageLink”: “…/…/coverage/lcov-report/index.html”
|
disableCharts
|
JEST_STARE_DISABLE_CHARTS
|
undefined
|
hide the doughnut charts in the HTML report |
“disableCharts”: true
|
hidePassing
|
JEST_STARE_HIDE_PASSING
|
undefined
|
hide passing tests in the report on page load |
“hidePassing”: true
|
hideFailing
|
JEST_STARE_HIDE_FAILING
|
undefined
|
hide failing tests in the report on page load |
“hideFailing”: true
|
hidePending
|
JEST_STARE_HIDE_PENDING
|
undefined
|
hide pending tests in the report on page load |
“hidePending”: true
|
Jest 测试框架配置 jest-stare相关推荐
- Jest测试框架学习(一)
前言 jest是针对JavaScript的测试框架.如果遵循TDD原则,在任何功能开发之前都需要先写测试.而测试分为单元测试,集成测试和系统测试. 单元测试 单元测试可以理解为对于单个函数(单一功能) ...
- Jest 测试框架使用的学习笔记
Jest Tutorial for Beginners: Getting Started With JavaScript Testing Jest 是一个 JavaScript 测试运行器,即用于创建 ...
- Jest测试框架入门之Mock
说到mock,大家第一个想到的肯定是项目里经常用来模拟接口返回值的 mockjs库 ,Jest里的mock有所不同,下面会举一些例子来分别讲一讲 jest.fn().jest.mock().jest. ...
- Jest 测试框架 expect 和 匹配器 matcher 的设计原理解析
副标题:SAP Spartacus SSR 优化的单元测试分析之二 - 调用参数检测 源代码: it(`should pass parameters to the original engine in ...
- Jest 测试框架 beforeEach 的设计原理解析
副标题:SAP Spartacus SSR 优化的单元测试分析之一 : beforeEach 文档 SAP Spartacus 里这段代码: originalEngine = jasmine.crea ...
- Jest测试框架入门之匹配器与测试异步代码
一.匹配器 1.对于一般的数字与字符串类型使用 toBe test('adds 1 + 2 to equal 3', () => {expect(1 + 2).toBe(3); });test( ...
- 顶级测试框架Jest指南:跑通一个完美的程序,就是教出一群像样的学生
facebook三大项目:yarn jest metro,有横扫宇宙之势. 而jest项目的宗旨为:减少测试一个项目所花费的时间成本和认知成本. --其实,它在让你当一个好老师. jest文档非常简略 ...
- 前端测试框架—jest基本使用
前端测试框架-jest基本使用 前言 jest 常见匹配器 基本类型 boolean Number String Array,Set 异常 取反 命令行工具使用 异步代码测试方法 钩子函数 分组(钩子 ...
- 万字详文:彻底搞懂 Jest 单元测试框架
点击上方 前端瓶子君,关注公众号 回复算法,加入前端编程面试算法每日一题群 什么是Jest 测试意味着什么 我怎么知道要测试什么 测试块,断言和匹配器 如何实现测试块 如何实现断言和匹配器 CLI 和 ...
最新文章
- 中国移动与苹果联姻 三星在华霸主地位或遭取代
- 【alibaba-cloud】nacos详解
- [svc]ext4文件删除访问原理
- python 调用c++
- pthon3精要(12)-扩展序列解包
- Github 1.3万星,迅猛发展的JAX对比TensorFlow、PyTorch
- 如何做到免驱打印_证卡打印机云打印方案
- scrapy 爬虫利器初体验(1)
- python 检查域名是否可以访问_糖尿病人是否都要做喝糖水的检查?结果可以说明胰岛功能水平吗?...
- 火山PC加载DLL窗口案例教程
- 一份完整的数据分析师成长书单
- 什么是URL?URL是什么意思?
- js关系图库:aworkflow
- HoloLens2开发常见问题汇总
- 教你如何将小视频转发到自己的朋友圈
- jemter使用beanshell的几种方法
- 非常棒的开源协同办公OA项目,收藏了!
- 牛客网华为云服务器,把通过牛客网注册的华为云服务器用起来!
- OpenOfficeException:not obtain service: com.sun.star.ucb.FileContentProvider 解决
- 风险投资与经营者 分成利润
热门文章
- 中兴CT220终端机资料
- Problem B: 七龙珠II
- 【前端做项目常用】相关插件的官网 总结
- 听见丨摩拜单车入驻联合国内罗毕总部 法拉第未来“到了生命最后一刻”
- 【Oracle实战经验一】:OracleSpatial自定义空间参考
- 拉伯证券|A股涨势趋缓,个股分化,北向资金继续“买买买”
- 网络安全行业“专业术语”!
- Qlik VS Power BI:Qlik告诉你世界上没有真正的免费
- 东方财富EMC智能交易终端安装talib
- spc统计过程控制系统架构模型