メインコンテンツへスキップ
バージョン: 次へ

Jestプラットフォーム

非公式ベータ版翻訳

このページは PageTurner AI で翻訳されました(ベータ版)。プロジェクト公式の承認はありません。 エラーを見つけましたか? 問題を報告 →

Jestの特定の機能を個別に選択し、スタンドアロンパッケージとして使用できます。以下は利用可能なパッケージの一覧です:

jest-changed-files

Git/Hgリポジトリで変更されたファイルを識別するツールです。以下の2つの関数をエクスポートします:

  • 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の詳細についてはreadmeファイルをご覧ください

jest-diff

データの変更を可視化するツールです。任意の型の2つの値を比較し、引数間の差分を示す「整形された」文字列を返す関数をエクスポートします

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の詳細についてはreadmeファイルをご覧ください

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つの引数(ユーザーの設定、サンプル設定とオプションを含むオブジェクト)を受け取り、以下の2つの属性を持つオブジェクトを返す関数をエクスポートします:

  • 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の詳細についてはreadmeファイルをご覧ください

jest-worker

タスクの並列化に使用されるモジュールです。Node.jsモジュールのパスを受け取り、モジュールのエクスポートされたメソッドをクラスメソッドのように呼び出せるJestWorkerクラスをエクスポートします。指定されたメソッドがフォークされたプロセスで実行を完了すると解決されるPromiseを返します

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();

jest-workerの詳細についてはreadmeファイルをご覧ください

pretty-format

JavaScriptの値を人間が読める文字列に変換する関数をエクスポートします。組み込みのJavaScript型をすぐにサポートし、ユーザー定義プラグインによるアプリケーション固有の型の拡張を可能にします

const {format: 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の詳細についてはreadmeファイルをご覧ください