Skip to content

Commit

Permalink
feat: using submodules for bats
Browse files Browse the repository at this point in the history
  • Loading branch information
hanoii committed Oct 11, 2024
1 parent b2ba34c commit 1b8f120
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: ddev/github-action-add-on-test@v2
with:
disable_checkout_action: true
ddev_version: ${{ matrix.ddev_version }}
token: ${{ secrets.GITHUB_TOKEN }}
debug_enabled: ${{ github.event.inputs.debug_enabled }}
addon_repository: ${{ env.GITHUB_REPOSITORY }}
addon_ref: ${{ env.GITHUB_REF }}
test_command: eval BATS_LIB_PATH=$(brew --prefix)/lib TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests
test_command: eval TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "tests/bats"]
path = tests/bats
url = https://github.com/bats-core/bats-core.git
[submodule "tests/helpers/bats-assert"]
path = tests/helpers/bats-assert
url = https://github.com/bats-core/bats-assert.git
[submodule "tests/helpers/bats-support"]
path = tests/helpers/bats-support
url = https://github.com/bats-core/bats-support.git
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,19 @@ ddev phpcbf -q
## Add-on tests

Tests are done with Bats. It is a simple testing framework that just uses Bash.
To run a Bats test locally, you have to [install bats-core][bats-core] first.
Then you can run `bats ./tests` within the root of this project.
To run a Bats test locally.

To run tests locally you need to first install the git submodules with:

`git submodules init`

Then you can run `./tests/bats/bats ./tests` within the root of this project.

Tests will be run using the default drupal core of the contrib. You can test
with a different Drupal core version by providing it in a `TEST_DRUPAL_CORE` environment
variable.

i.e. `TEST_DRUPAL_CORE=11 bats ./tests`.
i.e. `TEST_DRUPAL_CORE=11 ./tests/bats/bats ./tests`.

Tests are triggered either manually, automatically on every push to the
repository, or periodically each night. The automated tests are agains all of
Expand All @@ -127,7 +132,6 @@ Also, consider adding tests to test for bugs or new features on your PR.

To learn more about Bats see the [documentation][bats-docs].

[bats-core]: https://bats-core.readthedocs.io/en/stable/installation.html
[bats-docs]: https://bats-core.readthedocs.io/en/stable/

## Troubleshooting
Expand Down
1 change: 1 addition & 0 deletions tests/bats
Submodule bats added at 89a7fa
4 changes: 2 additions & 2 deletions tests/full.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bats_load_library 'bats-support'
bats_load_library 'bats-assert'
load helpers/bats-support/load.bash
load helpers/bats-assert/load.bash

setup_file() {
if [ -n "$TEST_DRUPAL_CORE" ] && [ "$TEST_DRUPAL_CORE" != "10" ] && [ "$TEST_DRUPAL_CORE" != "11" ]; then
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/bats-assert
Submodule bats-assert added at e2d855
1 change: 1 addition & 0 deletions tests/helpers/bats-support
Submodule bats-support added at 9bf10e

0 comments on commit 1b8f120

Please sign in to comment.