Ava
约 2 分钟阅读
- avajs/avaGitHubavajs/avaavajs/ava · 小、快、简单 · process.env.NODEENV=test · nodemodules/.cache/ava · React Recipe · 配合 enzyme 测试 react · pnpm 下 ava 为 shell, 实际脚本为笔记:Ava
- 小、快、简单
- process.env.NODE_ENV=test
- node_modules/.cache/ava
- React RecipeGitHub Fileavajs/ava/docs/recipes/react.md
- 配合 enzyme 测试 react
- pnpm 下 ava 为 shell, 实际脚本为
node_modules/ava/entrypoints/cli.mjs- 如果使用了 WebStorm 插件可以修改 ava 路径
- 将 ava 安装到 root 可避免
- 无 Suite/Group 概念 #222GitHub Issueavajs/ava#222
- 文件纬度划分
- Mystery Guest
{
"devDependencies": {
"ava": "*",
"tsx": "*"
},
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": ["--conditions=typescript", "--loader=tsx"]
}
}import test from 'ava';
test('foo', (t) => {
t.pass();
});
test('bar', async (t) => {
const bar = Promise.resolve('bar');
t.is(await bar, 'bar');
});
// 串行执行
test.serial('passes serially', (t) => {
t.pass();
});
test.only('will be run', (t) => {
t.pass();
});
test.skip('will not be run', (t) => {
t.fail();
});
test.todo('later');
test.serial.todo('later');
// 标记失败测试
test.failing('demonstrate some bug', (t) => {
t.fail(); // Test will count as passed
});
// 增加输出内容
import util from 'util';
util.inspect.defaultOptions.depth = 5;- test.{before,after,beforeEach,afterEach}
- test.after.always
- test.afterEach.always
- t.context - 测试上下文
- test.meta.file - 元信息
npx @ava/init
npx ava
npx ava src/hello.test.ts
# match by title
npx ava src/hello.test.ts -m "db"
npx ava --watch
DEBUG=ava:watcher npx ava --watch
# tap report
npx ava --tap | npx tap-nyan- Ava ConfigurationGitHub Fileavajs/ava/docs/06-configuration.md
- 使用 watson/is-ciGitHubwatson/is-ci 检测 CI
- ci-info sourceGitHub Filewatson/ci-info/index.js
测试文件匹配逻辑
- 以
_开头的目录和文件会忽略
默认测试文件匹配逻辑
test.js
src/test.js
source/test.js
**/test-*.js
**/*.spec.js
**/*.test.js
**/test/**/*.js
**/tests/**/*.js
**/__tests__/**/*.js排除逻辑
**/__tests__/**/__helper__/**/*
**/__tests__/**/__helpers__/**/*
**/__tests__/**/__fixture__/**/*
**/__tests__/**/__fixtures__/**/*
**/test/**/helper/**/*
**/test/**/helpers/**/*
**/test/**/fixture/**/*
**/test/**/fixtures/**/*
**/tests/**/helper/**/*
**/tests/**/helpers/**/*
**/tests/**/fixture/**/*
**/tests/**/fixtures/**/*配置
{
"ava": {
"files": ["test/**/*", "!test/exclude-files-in-this-directory", "!**/exclude-files-with-this-name.*"],
"ignoredByWatcher": "",
// --match
// "match": ["*oo", "!foo"],
// node_modules/.cache/ava
"cache": true,
// nproc
"concurrency": 5,
"workerThreads": true,
"failFast": true,
// 没有 assert 是否认为失败
"failWithoutAssertions": false,
"environmentVariables": {
"MY_ENVIRONMENT_VARIABLE": "some value"
},
"tap": false,
"verbose": true,
// "snapshotDir":"",
"extensions": ["cjs", "mjs", "js"],
"require": ["./my-helper-module.js"],
"timeout": 0,
"nodeArguments": ["--trace-deprecation", "--napi-modules"],
// ava.config.* 使用,定义函数
// sortTestFiles:"",
"utilizeParallelBuilds": true
}
}关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- Web Dev FAQ笔记 · Ava
| abbr. | stand for | · | iife | Immediately Invoked Function Expression | · 在开发时 assert 错误 · invariant · 早期来自 React, flux
References
GitHub6 条
- avajs/avagithub.com/avajs/ava
- avajs/ava/docs/06-configuration.mdgithub.com/avajs/ava/blob/main/docs/06-configuration.md
- avajs/ava/docs/recipes/react.mdgithub.com/avajs/ava/blob/main/docs/recipes/react.md
- avajs/ava#222github.com/avajs/ava/issues/222
- watson/ci-info/index.jsgithub.com/watson/ci-info/blob/master/index.js
- watson/is-cigithub.com/watson/is-ci
其他外链1 条
- thoughtbot.com/blog/mystery-guestthoughtbot.com/blog/mystery-guest