Github ActionsでNightwatchテストを実行する
概要
Github Actionsを使用すると、リポジトリから直接、ビルドやテストなどのソフトウェア開発ワークフローを自動化、カスタマイズ、実行するのが簡単になります。
前提条件
- Githubにプッシュされたテスト対象のワーキングプロジェクト
- ローカルシステムで適切に実行されるテスト
セットアップガイド
この例では、nightwatch-examples Githubリポジトリを使用して、Github Actionsを使用してNightwatchテストを実行する方法を学習します。
ステップ1:NodeJSプラグインのインストール
まず、リポジトリのGithub Actionsセクションに移動し、新しいワークフローをクリックしてNodeJSプラグインをセットアップし、ワークフローの検索入力ボックスにnodeと入力し、Node.jsプラグインの構成をクリックします。
ステップ2:.ymlファイルの構成
次に、node.js.yml
ファイル内にテストを実行するためのステップを記述する必要があります。
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Nightwatch Tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://node.dokyumento.jp/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js $undefined
uses: actions/setup-node@v3
with:
node-version: $undefined
cache: 'npm'
- name: npm-install
run: npm ci
- run: sudo apt-get install xvfb
- name: Run Nightwatch tests
run: xvfb-run --auto-servernum npm test -- --env chrome
.ymlファイルのより詳細なバージョンについては、ガイドを参照してください。
ステップ3:.ymlファイルをgithubにプッシュ
コミット新規ファイルフォームに必要事項を記入した後、コミット新規ファイルボタンをクリックします。
上記のステップをスキップして、ローカルから直接.ymlをプッシュすることもできます。ただし、ファイルパスは常に.github/workflow/file_name.yml
である必要があります。
ステップ4:テストの実行方法
Githubに変更をプッシュしてプルリクエストを上げると、パイプラインが開始され、テストが自動的に実行されます。