次の手順では、Jest テスト フレームワーク
この手順には、次の前提条件が必要です。
-
既存の CodeBuild プロジェクトがある。
-
そのプロジェクトは、Jest テストフレームワークを使用するようにセットアップされた Node.js プロジェクトである。
jest-junit
devDependencies
セクションの package.json
ファイルに追加します。CodeBuild では、このパッケージを使用して、レポートを JunitXml
の形式で生成します。
npm install --save-dev jest-junit
まだ存在しない場合は、test
スクリプトをプロジェクトの package.json
ファイルに追加します。test
スクリプトは、npm test が実行されたときに Jest が確実に呼び出されるようにします。
{
"scripts": {
"test": "jest"
}
}
Jest の設定ファイルに以下を追加して、JunitXml
レポーターを使用するよう Jest を設定します。プロジェクトに Jest 設定ファイルがない場合は、プロジェクトのルートに jest.config.js
という名前のファイルを作成し、以下を追加します。テストレポートは、<test report directory>
/<report filename>
で指定されたファイルにエクスポートされます。
module.exports = {
reporters: [
'default',
[ 'jest-junit', {
outputDirectory: <test report directory>
,
outputName: <report filename>
,
} ]
]
};
buildspec.yml
ファイルで、次のセクションを追加/更新します。
version: 0.2
phases:
pre_build:
commands:
- npm install
build:
commands:
- npm build
- npm test
reports:
jest_reports:
files:
- <report filename>
file-format: JUNITXML
base-directory: <test report directory>