Jest プラットフォーム
Jest の特定の機能だけをいいとこ取りして、スタンドアロンのパッケージとして使用することもできます。 以下に、利用できるパッケージのリストを挙げます。
jest-changed-files
git/hg リポジトリのファイルの変更を検出するツールです。 以下の2つの関数をエクスポートしています。
getChangedFilesForRootsreturns a promise that resolves to an object with the changed files and repos.findReposreturns a promise that resolves to a set of repositories contained in the specified path.
例
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));
You can read more about jest-changed-files in the readme file.
jest-diff
データの変更点を可視化するツールです。 任意の型の2つの値を比較し、2つの値の相違点を表す "pretty-print" された文字列を返す関数をエクスポートしています。
例
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);
You can read more about jest-docblock in the readme file.
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
ユーザーが提出した設定のバリデーションを行うツールです。 ユーザーの設定と、設定例およびその他のオプションを含むオブジェクトの2つの引数を取る関数をエクスポートしています。 返り値は、次の二つの属性を持つオブジェクトです。
hasDeprecationWarnings, a boolean indicating whether the submitted configuration has deprecation warnings,isValid, a boolean indicating whether the configuration is correct or not.
例
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);
You can read more about jest-validate in the readme file.
jest-worker
タスクの並列化に使われるモジュール このモジュールは JestWorker クラスをエクスポートしています。 Exports a class JestWorker that takes the path of Node.js module and lets you call the module's exported methods as if they were class methods, returning a promise that resolves when the specified method finishes its execution in a forked process.