Prerun Scripts

How to provision the VM and build your app before running TestDriver

Prerun scripts are Bash commands executed on a TestDriver VM before each test within a CI/CD pipeline. Their primary purpose is to establish the state of a machine. This ensure it is consistent before every test execution.

You can configure prerun script to install necessary dependencies, build your application, set specific configurations, and more.

This crucial step helps to speed up the setup of an environment, prepare for a test suite to run, and prevent test failures due to environment inconsistencies and promote reproducible builds, ultimately enhancing the overall test suite's effectiveness.

Example

This is an example of how WaveTerminal uses TestDriver to build their desktop app on every commit to every pull request.

Notice the permissions on line 13 as well as the bash script on line 28

name: TestDriver.ai Regression Testing - Waveterm
on:
    push:
        branches:
            - main
    pull_request:
        branches:
            - main
    schedule:
        - cron: 0 21 * * *
    workflow_dispatch: null

permissions:
    contents: read # To allow the action to read repository contents
    pull-requests: write # To allow the action to create/update pull request comments

jobs:
  test:
    name: "TestDriver"
    runs-on: ubuntu-latest
    steps:
      - uses: dashcamio/testdriver@main
        id: testdriver
        with:
          version: v4.0.0
          key: ${{secrets.TESTDRIVER_API_KEY}}
          prerun: |
            cd ~/actions-runner/_work/testdriver/testdriver/
            brew install go
            brew tap scripthaus-dev/scripthaus
            brew install corepack
            brew install scripthaus
            corepack enable
            yarn install
            scripthaus run build-backend
            echo "Yarn"
            yarn
            echo "Rebuild"
            scripthaus run electron-rebuild
            echo "Webpack"
            scripthaus run webpack-build
            echo "Starting Electron"
            scripthaus run electron 1>/dev/null 2>&1 &
            echo "Electron Done"
            cd /Users/ec2-user/Downloads/td/
            npm rebuild
            exit       
          prompt: |
            1. /run /Users/ec2-user/actions-runner/_work/testdriver/testdriver/.testdriver/wave1.yml

Last updated