actions/test-app/README.md

test-app

RStudio
community

This action tests a Shiny application (or Shiny-based document) using the {shinytest2} package. The ${{ inputs.app-dir}}/tests/testthat/_snaps directory will be uploaded if enabled (default).

Usage

Inputs available:

Typical (single app testing) GHA step usage:

- uses: rstudio/shinytest2/actions/test-app@actions/v1
  with:
    app-dir: |
      dir/to/app

Multiple Apps can be tested by supplying multiple directories to app-dir separated by a newline:

- uses: rstudio/shinytest2/actions/test-app@actions/v1
  with:
    app-dir: |
      dir/to/app1
      dir/to/app2

Example workflows

These workflows are a good building block / starting point for testing your Shiny applications. You may need to alter what is actually executed to fit your needs.

Dependencies in DESCRIPTION file

Install workflow using:

usethis::use_github_action(
  url = "https://github.com/rstudio/shinytest2/raw/main/actions/test-app/example-test-app-descrption.yaml",
  save_as = "test-app-description.yaml"
)

Workflow contents:

# Workflow derived from https://github.com/rstudio/shinytest2/tree/main/actions/test-app/example-test-app-description.yaml
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

name: Test app w/ DESCRIPTION

jobs:
  test-app:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: ubuntu-latest, r: release}

    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
      R_KEEP_PKG_SOURCE: yes

    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/setup-pandoc@v2

      - uses: r-lib/actions/setup-r@v2
        with:
          r-version: ${{ matrix.config.r }}
          http-user-agent: ${{ matrix.config.http-user-agent }}
          use-public-rspm: true

      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages:
            shinytest2

      - uses: rstudio/shinytest2/actions/test-app@actions/v1
        with:
          app-dir: "."

Dependencies managed by {renv}

Install workflow using:

usethis::use_github_action(
  url = "https://github.com/rstudio/shinytest2/raw/main/actions/test-app/example-test-app-renv.yaml",
  save_as = "test-app-renv.yaml"
)

Workflow contents:

# Workflow derived from https://github.com/rstudio/shinytest2/tree/main/actions/test-app/example-test-app-renv.yaml
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

name: Test app w/ {renv}

jobs:
  test-app:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: ubuntu-latest, r: release}

    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
      R_KEEP_PKG_SOURCE: yes

    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/setup-pandoc@v2

      - uses: r-lib/actions/setup-r@v2
        with:
          r-version: ${{ matrix.config.r }}
          http-user-agent: ${{ matrix.config.http-user-agent }}
          use-public-rspm: true

      - uses: r-lib/actions/setup-renv@v2

      - uses: rstudio/shinytest2/actions/test-app@actions/v1
        with:
          app-dir: "."

App within Package structure

If you are using a local package and want to test an application within the same repo, this may be a good option. However, it is recommended to try to execute these tests as a part of your standard {testthat} testting.

Install workflow using:

usethis::use_github_action(
  url = "https://github.com/rstudio/shinytest2/raw/main/actions/test-app/example-test-app-package.yaml",
  save_as = "test-app-package.yaml"
)

Workflow contents:

# Workflow derived from https://github.com/rstudio/shinytest2/tree/main/actions/test-app/example-test-app-package.yaml
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

name: Test package app

jobs:
  test-package-app:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: ubuntu-latest, r: release}

    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
      R_KEEP_PKG_SOURCE: yes

    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/setup-pandoc@v2

      - uses: r-lib/actions/setup-r@v2
        with:
          r-version: ${{ matrix.config.r }}
          http-user-agent: ${{ matrix.config.http-user-agent }}
          use-public-rspm: true

      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages:
            local::.
            shinytest2

      - uses: rstudio/shinytest2/actions/test-app@actions/v1
        with:
          app-dir: "."

Development

The test-app action uses a sliding git tag that follows the pattern actions/vX, e.g. actions/v1. For historical reasons, we also support the v1 tag, but future versions will only be available under the actions/vX tag.

The test-app action release cycle is not dependent on the shinytest2 package cycle. When changes are made to the test-app action, you should force-update the current sliding tag version:

git tag -f v1            # update historical v1 tag
git tag -f actions/v1    # update sliding tag
git push --tags --force  # push tag to github

License

The scripts and documentation in this project are released under the MIT License

Contributions

Contributions are welcome!



rstudio/shinytest2 documentation built on March 29, 2025, 10:58 p.m.