Jest 平台
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
你可以按需选择 Jest 的特定功能作为独立包使用。以下是可用的软件包列表:
jest-changed-files
用于识别 git/hg 仓库中修改文件的工具。导出两个函数:
-
getChangedFilesForRoots返回一个 Promise,解析为包含变更文件和仓库的对象 -
findRepos返回一个 Promise,解析为指定路径下包含的仓库集合
示例
const {getChangedFilesForRoots} = require('jest-changed-files');
// print the set of modified files since last commit in the current repo
getChangedFilesForRoots(['./'], {
lastCommit: true,
}).then(result => console.log(result.changedFiles));
你可以在 自述文件 中了解更多关于 jest-changed-files 的信息。
jest-diff
数据变更可视化工具。导出一个函数,可比较任意类型的两个值并返回"美观打印"的字符串,展示两个参数之间的差异
示例
const {diff} = require('jest-diff');
const a = {a: {b: {c: 5}}};
const b = {a: {b: {c: 6}}};
const result = diff(a, b);
// print diff
console.log(result);
jest-docblock
用于提取和解析 JavaScript 文件顶部注释的工具。导出多种函数来操作注释块内的数据
示例
const {parseWithComments} = require('jest-docblock');
const code = `
/**
* This is a sample
*
* @flow
*/
console.log('Hello World!');
`;
const parsed = parseWithComments(code);
// prints an object with two attributes: comments and pragmas.
console.log(parsed);
你可以在 自述文件 中了解更多关于 jest-docblock 的信息。
jest-get-type
识别 JavaScript 值原始类型的模块。导出一个函数,返回传入参数类型的字符串表示
示例
const {getType} = require('@jest/get-type');
const array = [1, 2, 3];
const nullValue = null;
const undefinedValue = undefined;
// prints 'array'
console.log(getType(array));
// prints 'null'
console.log(getType(nullValue));
// prints 'undefined'
console.log(getType(undefinedValue));
jest-validate
用于验证用户提交配置的工具。导出一个接收两个参数的函数:用户配置和包含示例配置的选项对象。返回值是具有两个属性的对象:
-
hasDeprecationWarnings,布尔值,表示提交的配置是否存在弃用警告 -
isValid,布尔值,表示配置是否正确
示例
const {validate} = require('jest-validate');
const configByUser = {
transform: '<rootDir>/node_modules/my-custom-transform',
};
const result = validate(configByUser, {
comment: ' Documentation: http://custom-docs.com',
exampleConfig: {transform: '<rootDir>/node_modules/babel-jest'},
});
console.log(result);
你可以在 自述文件 中了解更多关于 jest-validate 的信息。
jest-worker
用于任务并行化的模块。导出 JestWorker 类,接收 Node.js 模块路径并允许像调用类方法一样调用模块导出方法,返回的 Promise 会在分叉进程中指定方法执行完成时解析