ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

自动化测试(五)04-js测试框架AVA——查看ava支持的cli参数之npx ava --help &文件匹配-match &TAP报告&快照功能-snapshots目录 &设置超时-timeout

2022-02-28 23:31:36  阅读:265  来源: 互联网

标签:tap -- npx 测试 output 快照 foo ava


自动化测试(五)04-js测试框架AVA——查看ava支持的cli参数之npx ava --help & 文件匹配-match & TAP报告 & 快照功能-snapshots目录 & 设置超时-timeout

CLI命令

参考指令——https://github.com/sindresorhus/awesome-tap#reporters

使用--help命令去查看ava支持的cli参数

➜ npx ava --help

  Testing can be a drag. AVA helps you get it done.

  Usage
    ava [<file> ...]

  Options
    --watch, -w             Re-run tests when tests and source files change
    --match, -m             Only run tests with matching title (Can be repeated)
    --update-snapshots, -u  Update snapshots
    --fail-fast             Stop after first test failure
    --timeout, -T           Set global timeout (milliseconds or human-readable, e.g. 10s, 2m)
    --serial, -s            Run tests serially
    --concurrency, -c       Max number of test files running at the same time (Default: CPU cores)
    --verbose, -v           Enable verbose output
    --tap, -t               Generate TAP output
    --color                 Force color output
    --no-color              Disable color output
    --reset-cache           Reset AVA's compilation cache and exit
    --config                JavaScript file for AVA to read its config from, instead of using package.json
                            or ava.config.js files

  Examples
    ava
    ava test.js test2.js
    ava test-*.js
    ava test

  The above relies on your shell expanding the glob patterns.
  Without arguments, AVA uses the following patterns:
    **/test.js **/test-*.js **/*.spec.js **/*.test.js **/test/**/*.js **/tests/**/*.js **/__tests__/**/*.js

文件匹配

使用match指令,匹配对应需要测试的文件:

匹配标题以foo:结尾

npx ava --match ='* foo'

匹配标题以foo

npx ava --match ='foo *'

匹配标题包含foo

npx ava --match ='* foo *'

匹配是完全相同 foo

npx ava --match ='foo'

匹配标题不包含foo

npx ava --match ='!* foo *'

匹配以下foo结尾的标题bar

npx ava --match ='foo * bar'

匹配foobar:开头或结尾的标题:

npx ava --match ='foo *' -  match ='* bar'

关于reporter

默认情况下,AVA使用最小的报告:

在这里插入图片描述

使用该--verbose标志启用详细的报告者。除非启用TAP报告,否则始终在CI环境中使用此选项。

在这里插入图片描述

TAP报告(推荐)

AVA支持TAP格式,因此与任何TAP报告器兼容。使用该--tap标志启用TAP输出。

$ npx ava --tap | npx tap-nyan

在这里插入图片描述

这里有一些格式:

快照功能

ava自动进行项目测试快照,如果文件放置在test或者tests目录,则快照会放置在snapshots目录。如果测试放置在__test__目录,则快照放置在__snapshots__目录

ava --update-snapshots

可以指定一个固定位置,以便在AVA的package.json配置中存储快照文件:

package.json:

{
	 "ava":{
		 "snapshotDir":"自定义目录"
	}
}

设置超时

AVA中的超时行为与其他测试框架中的行为不同。AVA在每次测试后重置计时器,如果在指定的超时内没有收到新的测试结果,则强制测试退出。这可用于处理停滞的测试。

没有默认超时。

您可以配置使用超时--timeout 命令行选项,或配置文件中设置。它们可以以人类可读的方式设置:

# 10秒
npx ava --timeout = 10s 

# 2分钟
npx ava --timeout = 2m 

# 100毫秒
npx ava --timeout = 100

还可以为每个测试单独设置超时。每次进行断言时都会重置这些超时。

test('foo', t => {
	t.timeout(100); // 100 milliseconds
	// Write your assertions here
});

标签:tap,--,npx,测试,output,快照,foo,ava
来源: https://blog.csdn.net/weixin_44867717/article/details/123195231

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有