你可以挑選 Jest 的特定功能并將它們用作獨(dú)立包。以下是可用軟件包的列表:
用于識(shí)別 git/hg 存儲(chǔ)庫中已修改文件的工具。導(dǎo)出兩個(gè)函數(shù):
getChangedFilesForRoots
?返回一個(gè)承諾,該承諾解析為具有更改文件和存儲(chǔ)庫的對(duì)象。findRepos
?返回解析為指定路徑中包含的一組存儲(chǔ)庫的承諾。
const {getChangedFilesForRoots} = require('jest-changed-files');
// 打印出當(dāng)前目錄最后修改過的一組文件
getChangedFilesForRoots(['./'], {
lastCommit: true,
}).then(result => console.log(result.changedFiles));
可以?在自述文件中閱讀更多相關(guān)jest-changed-files
?信息。
可視化數(shù)據(jù)變化的工具。導(dǎo)出一個(gè)函數(shù),該函數(shù)比較任何類型的兩個(gè)值,并返回一個(gè)“pretty printed”的字符串,說明兩個(gè)參數(shù)之間的差異。
const diff = require('jest-diff').default;
const a = {a: {b: {c: 5}}};
const b = {a: {b: {c: 6}}};
const result = diff(a, b);
// print diff
console.log(result);
用于提取和解析 JavaScript 文件頂部注釋的工具。導(dǎo)出各種函數(shù)來操作注釋塊內(nèi)的數(shù)據(jù)。
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);
可以?在自述文件中閱讀更多相關(guān)jest-docblock
?信息。
標(biāo)識(shí)任何 JavaScript 值的原始類型的模塊。導(dǎo)出一個(gè)函數(shù),該函數(shù)返回一個(gè)字符串,該字符串具有作為參數(shù)傳遞的值的類型。
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));
用于驗(yàn)證用戶提交的配置的工具。 導(dǎo)出具有兩個(gè)參數(shù)的函數(shù):用戶配置和包含示例配置和其他選項(xiàng)的對(duì)象。返回值是具有兩個(gè)屬性的對(duì)象:
hasDeprecationWarnings
?,一個(gè)布爾值,指示提交的配置是否有棄用警告,isValid
?, 一個(gè)布爾值, 指示配置是否正確。
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);
可以?在自述文件中閱讀更多相關(guān)jest-validate
?信息。
用于任務(wù)并行化的模塊。出口類?JestWorker
?是需要的Node.js模塊的路徑,并允許你調(diào)用模塊的導(dǎo)出的方法,好像他們是類方法,返回一個(gè) Promise,消除了在所指定的方法完成它的執(zhí)行在分叉過程。
// heavy-task.js
module.exports = {
myHeavyTask: args => {
// long running CPU intensive task.
},
};
// main.js
async function main() {
const worker = new Worker(require.resolve('./heavy-task.js'));
// run 2 tasks in parallel with different arguments
const results = await Promise.all([
worker.myHeavyTask({foo: 'bar'}),
worker.myHeavyTask({bar: 'foo'}),
]);
console.log(results);
}
main();
可以在自述文件中閱讀更多相關(guān)?jest-worker
?信息。
導(dǎo)出并將任何 JavaScript 值轉(zhuǎn)換為人類可讀字符串的函數(shù)。開箱即用地支持所有內(nèi)置 JavaScript 類型,并允許通過用戶定義的插件擴(kuò)展特定于應(yīng)用程序的類型。
const prettyFormat = require('pretty-format');
const val = {object: {}};
val.circularReference = val;
val[Symbol('foo')] = 'foo';
val.map = new Map([['prop', 'value']]);
val.array = [-0, Infinity, NaN];
console.log(prettyFormat(val));
可以?在自述文件中閱讀更多pretty-format
?相關(guān)信息。
更多建議: