From 21a260ff7f7722a93a72367da236556d7affca7a Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Mon, 7 Oct 2024 19:52:30 -0300 Subject: [PATCH 01/24] wip: initial tests refactor --- tests/d10.bats | 52 +++++++++++++++++++ tests/no-composer-json.bats | 27 ++++++++++ tests/test.bats | 40 -------------- .../test_drupal_contrib/composer.json | 49 +++++++++++++++++ .../test_drupal_contrib.info.yml | 3 ++ 5 files changed, 131 insertions(+), 40 deletions(-) create mode 100644 tests/d10.bats create mode 100644 tests/no-composer-json.bats delete mode 100644 tests/test.bats create mode 100644 tests/testdata/test_drupal_contrib/composer.json create mode 100644 tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml diff --git a/tests/d10.bats b/tests/d10.bats new file mode 100644 index 0000000..899856b --- /dev/null +++ b/tests/d10.bats @@ -0,0 +1,52 @@ +setup_file() { + export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." + export PROJNAME=test-drupal-contrib + export TESTDIR=~/tmp/${PROJNAME} + mkdir -p $TESTDIR + export DDEV_NON_INTERACTIVE=true + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true + cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} + cd ${TESTDIR} + ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 +} + +teardown_file() { + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 + [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} +} + +@test "install from directory" { + echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev get ${DIR} +} + +@test "ddev start" { + ddev start +} + +@test "ddev poser with composer.json" { + ddev poser + ddev mutagen sync + ls -la +} + +@test "ddev symlink-project" { + ddev symlink-project + ddev mutagen sync + ls -la web/modules/* + ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml +} + +@test "php tools availability" { + ddev phpcs --version + ddev phpstan --version + ddev phpunit --version +} + +@test "node tools availability" { + ddev yarn --cwd web/core install + ddev exec touch web/core/.env + ddev mutagen sync + ddev stylelint --version + ddev eslint --version +} diff --git a/tests/no-composer-json.bats b/tests/no-composer-json.bats new file mode 100644 index 0000000..3c8154d --- /dev/null +++ b/tests/no-composer-json.bats @@ -0,0 +1,27 @@ +setup_file() { + export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." + export PROJNAME=test-drupal-contrib + export TESTDIR=~/tmp/${PROJNAME} + mkdir -p $TESTDIR + export DDEV_NON_INTERACTIVE=true + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true + cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} + cd ${TESTDIR} + ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 +} + +teardown_file() { + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 + [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} +} + +@test "install from directory" { + echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR}/${PROJNAME} ($(pwd))" >&3f + ddev get ${DIR} + ddev start +} + +@test "ddev poser without composer.json" { + rm -f composer.json + ddev poser +} diff --git a/tests/test.bats b/tests/test.bats deleted file mode 100644 index 781ee01..0000000 --- a/tests/test.bats +++ /dev/null @@ -1,40 +0,0 @@ -setup() { - set -eu -o pipefail - export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." - export TESTDIR=~/tmp/test-addon-template - mkdir -p $TESTDIR - export PROJNAME=keycdn - export DDEV_NON_INTERACTIVE=true - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true - cd "${TESTDIR}" - git clone https://git.drupalcode.org/project/keycdn.git -} - -teardown() { - set -eu -o pipefail - cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 - [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} -} - -@test "install from directory" { - set -eu -o pipefail - cd ${TESTDIR}/${PROJNAME} - echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR}/${PROJNAME} ($(pwd))" >&3 - ddev get ${DIR} - ddev config --auto - ddev config --corepack-enable - ddev start - ddev expand-composer-json - ddev composer install - ddev symlink-project - ddev drush st - ddev phpcs --version - ddev phpstan --version - ls -al web/modules/custom/${PROJNAME}/tests - ddev phpunit --version - ddev yarn --cwd web/core install - ddev exec touch web/core/.env - ddev stylelint --version - ddev eslint --version -} diff --git a/tests/testdata/test_drupal_contrib/composer.json b/tests/testdata/test_drupal_contrib/composer.json new file mode 100644 index 0000000..947ac40 --- /dev/null +++ b/tests/testdata/test_drupal_contrib/composer.json @@ -0,0 +1,49 @@ +{ + "name": "drupal/ddev_drupal_contrab", + "type": "drupal-module", + "license": "GPL-2.0+", + "homepage": "https://github.com/ddev/ddev-drupal-contrib", + "minimum-stability": "dev", + "repositories": [ + { + "type": "composer", + "url": "https://packages.drupal.org/8" + } + ], + "require": { + "drupal/devel": "^5.0" + }, + "require-dev": { + "drush/drush": "^11 || ^12 || ^13" + }, + "config": { + "allow-plugins": true + }, + "extra": { + "drupal-scaffold": { + "locations": { + "web-root": "web" + } + }, + "installer-paths": { + "web/core": [ + "type:drupal-core" + ], + "web/libraries/{$name}": [ + "type:drupal-library" + ], + "web/modules/contrib/{$name}": [ + "type:drupal-module" + ], + "web/profiles/contrib/{$name}": [ + "type:drupal-profile" + ], + "web/themes/contrib/{$name}": [ + "type:drupal-theme" + ], + "drush/contrib/{$name}": [ + "type:drupal-drush" + ] + } + } +} diff --git a/tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml b/tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml new file mode 100644 index 0000000..24d8d01 --- /dev/null +++ b/tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml @@ -0,0 +1,3 @@ +name: 'ddev Drupal Contrib dummy module for tests' +type: module +core_version_requirement: ^8.8 || ^9 || ^10 || ^11 From bb6fa5d5c17a1b731e67c47d8927e2bfc37789e3 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Mon, 7 Oct 2024 20:10:04 -0300 Subject: [PATCH 02/24] feat: d10 and d11 tests --- tests/d10.bats | 4 ++-- tests/d11.bats | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/d11.bats diff --git a/tests/d10.bats b/tests/d10.bats index 899856b..580acc1 100644 --- a/tests/d10.bats +++ b/tests/d10.bats @@ -7,7 +7,8 @@ setup_file() { ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} cd ${TESTDIR} - ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 + ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable + echo -e "web_environment:\n - DRUPAL_CORE=^10" > .ddev/config.~overrides.yaml } teardown_file() { @@ -33,7 +34,6 @@ teardown_file() { @test "ddev symlink-project" { ddev symlink-project ddev mutagen sync - ls -la web/modules/* ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml } diff --git a/tests/d11.bats b/tests/d11.bats new file mode 100644 index 0000000..7ca2296 --- /dev/null +++ b/tests/d11.bats @@ -0,0 +1,52 @@ +setup_file() { + export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." + export PROJNAME=test-drupal-contrib + export TESTDIR=~/tmp/${PROJNAME} + mkdir -p $TESTDIR + export DDEV_NON_INTERACTIVE=true + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true + cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} + cd ${TESTDIR} + ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable + echo -e "web_environment:\n - DRUPAL_CORE=^11" > .ddev/config.~overrides.yaml +} + +teardown_file() { + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 + [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} +} + +@test "install from directory" { + echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev get ${DIR} +} + +@test "ddev start" { + ddev start +} + +@test "ddev poser with composer.json" { + ddev poser + ddev mutagen sync + ls -la +} + +@test "ddev symlink-project" { + ddev symlink-project + ddev mutagen sync + ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml +} + +@test "php tools availability" { + ddev phpcs --version + ddev phpstan --version + ddev phpunit --version +} + +@test "node tools availability" { + ddev exec "cd web/core && yarn install" + ddev exec touch web/core/.env + ddev mutagen sync + ddev stylelint --version + ddev eslint --version +} From 607740eb9da44b5d64b9023c30b5fe81f5d172c8 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Mon, 7 Oct 2024 20:29:01 -0300 Subject: [PATCH 03/24] tests: d10 remove corepack and use d11 yarn install approach --- tests/d10.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/d10.bats b/tests/d10.bats index 580acc1..78567a0 100644 --- a/tests/d10.bats +++ b/tests/d10.bats @@ -7,7 +7,7 @@ setup_file() { ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} cd ${TESTDIR} - ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable + ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 echo -e "web_environment:\n - DRUPAL_CORE=^10" > .ddev/config.~overrides.yaml } @@ -44,7 +44,7 @@ teardown_file() { } @test "node tools availability" { - ddev yarn --cwd web/core install + ddev exec "cd web/core && yarn install" ddev exec touch web/core/.env ddev mutagen sync ddev stylelint --version From 257965a6d8a4adfba61eba628bbbffbd0f9ea968 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Mon, 7 Oct 2024 20:39:57 -0300 Subject: [PATCH 04/24] refactor: tests rename --- tests/{no-composer-json.bats => default-no-composer-json.bats} | 0 tests/{d10.bats => full-d10.bats} | 0 tests/{d11.bats => full-d11.bats} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename tests/{no-composer-json.bats => default-no-composer-json.bats} (100%) rename tests/{d10.bats => full-d10.bats} (100%) rename tests/{d11.bats => full-d11.bats} (100%) diff --git a/tests/no-composer-json.bats b/tests/default-no-composer-json.bats similarity index 100% rename from tests/no-composer-json.bats rename to tests/default-no-composer-json.bats diff --git a/tests/d10.bats b/tests/full-d10.bats similarity index 100% rename from tests/d10.bats rename to tests/full-d10.bats diff --git a/tests/d11.bats b/tests/full-d11.bats similarity index 100% rename from tests/d11.bats rename to tests/full-d11.bats From ebe0621005baa4050647b782dd33473ef7257a2c Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Mon, 7 Oct 2024 23:31:21 -0300 Subject: [PATCH 05/24] refactor: moves common code into _common.bash --- tests/_common.bash | 54 +++++++++++++++++++++++++++++ tests/default-no-composer-json.bats | 23 +++++------- tests/full-d10.bats | 51 +++++++++++---------------- tests/full-d11.bats | 46 ++++++++---------------- 4 files changed, 97 insertions(+), 77 deletions(-) create mode 100644 tests/_common.bash diff --git a/tests/_common.bash b/tests/_common.bash new file mode 100644 index 0000000..ea7f0ed --- /dev/null +++ b/tests/_common.bash @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +_common_setup() { + export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." + export PROJNAME=test-drupal-contrib + export TESTDIR=~/tmp/${PROJNAME} + mkdir -p $TESTDIR + export DDEV_NON_INTERACTIVE=true + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true + cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} + cd ${TESTDIR} + ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web +} + +_common_teardown() { + ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 + [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} +} + +_common_test_install() { + echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev get ${DIR} + ddev start +} + +_common_test_poser() { + ddev poser + ddev mutagen sync + ls -la +} + +_common_test_symlink() { + ddev symlink-project + ddev mutagen sync + ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml +} + +_common_test_php() { + ddev phpcs --version + ddev phpstan --version + ddev phpunit --version +} + +_common_test_require_dev() { + ddev drush st +} + +_common_test_node() { + ddev exec "cd web/core && yarn install" + ddev exec touch web/core/.env + ddev mutagen sync + ddev stylelint --version + ddev eslint --version +} diff --git a/tests/default-no-composer-json.bats b/tests/default-no-composer-json.bats index 3c8154d..8120a13 100644 --- a/tests/default-no-composer-json.bats +++ b/tests/default-no-composer-json.bats @@ -1,27 +1,20 @@ setup_file() { - export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." - export PROJNAME=test-drupal-contrib - export TESTDIR=~/tmp/${PROJNAME} - mkdir -p $TESTDIR - export DDEV_NON_INTERACTIVE=true - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true - cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} - cd ${TESTDIR} - ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 + load '_common.bash' + _common_setup } teardown_file() { - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 - [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} + load '_common.bash' + _common_teardown } @test "install from directory" { - echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR}/${PROJNAME} ($(pwd))" >&3f - ddev get ${DIR} - ddev start + load '_common.bash' + _common_test_install } @test "ddev poser without composer.json" { + load '_common.bash' rm -f composer.json - ddev poser + _common_test_poser } diff --git a/tests/full-d10.bats b/tests/full-d10.bats index 78567a0..b967641 100644 --- a/tests/full-d10.bats +++ b/tests/full-d10.bats @@ -1,52 +1,41 @@ setup_file() { - export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." - export PROJNAME=test-drupal-contrib - export TESTDIR=~/tmp/${PROJNAME} - mkdir -p $TESTDIR - export DDEV_NON_INTERACTIVE=true - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true - cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} - cd ${TESTDIR} - ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 + load '_common.bash' + _common_setup + ddev config --php-version=8.2 echo -e "web_environment:\n - DRUPAL_CORE=^10" > .ddev/config.~overrides.yaml } teardown_file() { - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 - [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} + load '_common.bash' + _common_teardown } @test "install from directory" { - echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ${DIR} -} - -@test "ddev start" { - ddev start + load '_common.bash' + _common_test_install } @test "ddev poser with composer.json" { - ddev poser - ddev mutagen sync - ls -la + load '_common.bash' + _common_test_poser } @test "ddev symlink-project" { - ddev symlink-project - ddev mutagen sync - ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml + load '_common.bash' + _common_test_symlink } @test "php tools availability" { - ddev phpcs --version - ddev phpstan --version - ddev phpunit --version + load '_common.bash' + _common_test_php +} + +@test "require-dev availability" { + load '_common.bash' + _common_test_require_dev } @test "node tools availability" { - ddev exec "cd web/core && yarn install" - ddev exec touch web/core/.env - ddev mutagen sync - ddev stylelint --version - ddev eslint --version + load '_common.bash' + _common_test_node } diff --git a/tests/full-d11.bats b/tests/full-d11.bats index 7ca2296..844e401 100644 --- a/tests/full-d11.bats +++ b/tests/full-d11.bats @@ -1,52 +1,36 @@ setup_file() { - export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." - export PROJNAME=test-drupal-contrib - export TESTDIR=~/tmp/${PROJNAME} - mkdir -p $TESTDIR - export DDEV_NON_INTERACTIVE=true - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true - cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} - cd ${TESTDIR} - ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable + load '_common.bash' + _common_setup + ddev config --php-version=8.3 --corepack-enable echo -e "web_environment:\n - DRUPAL_CORE=^11" > .ddev/config.~overrides.yaml } teardown_file() { - ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 - [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} + load '_common.bash' + _common_teardown } @test "install from directory" { - echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ${DIR} -} - -@test "ddev start" { - ddev start + load '_common.bash' + _common_test_install } @test "ddev poser with composer.json" { - ddev poser - ddev mutagen sync - ls -la + load '_common.bash' + _common_test_poser } @test "ddev symlink-project" { - ddev symlink-project - ddev mutagen sync - ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml + load '_common.bash' + _common_test_symlink } @test "php tools availability" { - ddev phpcs --version - ddev phpstan --version - ddev phpunit --version + load '_common.bash' + _common_test_php } @test "node tools availability" { - ddev exec "cd web/core && yarn install" - ddev exec touch web/core/.env - ddev mutagen sync - ddev stylelint --version - ddev eslint --version + load '_common.bash' + _common_test_node } From 215eade4a76dd9e5e050d52b293ecd42aedb0ea6 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Mon, 7 Oct 2024 23:33:23 -0300 Subject: [PATCH 06/24] feat: require-dev on d11 test as well --- tests/full-d11.bats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/full-d11.bats b/tests/full-d11.bats index 844e401..5f64fb8 100644 --- a/tests/full-d11.bats +++ b/tests/full-d11.bats @@ -30,6 +30,11 @@ teardown_file() { _common_test_php } +@test "require-dev availability" { + load '_common.bash' + _common_test_require_dev +} + @test "node tools availability" { load '_common.bash' _common_test_node From 8c03c6e2ce66938c4046ab751b3d451b51d3c474 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Tue, 8 Oct 2024 09:49:29 -0300 Subject: [PATCH 07/24] feat: test drupal version with drush --- tests/_common.bash | 6 ++++-- tests/full-d10.bats | 6 +++--- tests/full-d11.bats | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/_common.bash b/tests/_common.bash index ea7f0ed..852c456 100644 --- a/tests/_common.bash +++ b/tests/_common.bash @@ -10,6 +10,7 @@ _common_setup() { cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} cd ${TESTDIR} ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web + echo -e "web_environment:\n - DRUPAL_CORE=^${TEST_DRUPAL_CORE}" > .ddev/config.~overrides.yaml } _common_teardown() { @@ -41,8 +42,9 @@ _common_test_php() { ddev phpunit --version } -_common_test_require_dev() { - ddev drush st +_common_test_drupal_version() { + run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1' + [ "$output" = "${TEST_DRUPAL_CORE}" ] } _common_test_node() { diff --git a/tests/full-d10.bats b/tests/full-d10.bats index b967641..db9baa6 100644 --- a/tests/full-d10.bats +++ b/tests/full-d10.bats @@ -1,8 +1,8 @@ setup_file() { + export TEST_DRUPAL_CORE=10 load '_common.bash' _common_setup ddev config --php-version=8.2 - echo -e "web_environment:\n - DRUPAL_CORE=^10" > .ddev/config.~overrides.yaml } teardown_file() { @@ -30,9 +30,9 @@ teardown_file() { _common_test_php } -@test "require-dev availability" { +@test "drupal core version" { load '_common.bash' - _common_test_require_dev + _common_test_drupal_version } @test "node tools availability" { diff --git a/tests/full-d11.bats b/tests/full-d11.bats index 5f64fb8..0e42206 100644 --- a/tests/full-d11.bats +++ b/tests/full-d11.bats @@ -1,8 +1,8 @@ setup_file() { + export TEST_DRUPAL_CORE=11 load '_common.bash' _common_setup ddev config --php-version=8.3 --corepack-enable - echo -e "web_environment:\n - DRUPAL_CORE=^11" > .ddev/config.~overrides.yaml } teardown_file() { @@ -30,9 +30,9 @@ teardown_file() { _common_test_php } -@test "require-dev availability" { +@test "drupal core version" { load '_common.bash' - _common_test_require_dev + _common_test_drupal_version } @test "node tools availability" { From 1a643fa551a9fd66bdde20e6ff0e3954e66e329b Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Tue, 8 Oct 2024 10:00:17 -0300 Subject: [PATCH 08/24] feat: add bats_require_minimum_version 1.5.0 --- tests/_common.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/_common.bash b/tests/_common.bash index 852c456..80e970b 100644 --- a/tests/_common.bash +++ b/tests/_common.bash @@ -1,6 +1,7 @@ #!/usr/bin/env bash _common_setup() { + bats_require_minimum_version 1.5.0 export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." export PROJNAME=test-drupal-contrib export TESTDIR=~/tmp/${PROJNAME} From 10dfe9605ef5ff8de4af42013e676a5020f368e4 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Tue, 8 Oct 2024 10:57:00 -0300 Subject: [PATCH 09/24] feat: single full.bats test and GHA matrix strategy --- .github/workflows/tests.yml | 2 ++ tests/default-no-composer-json.bats | 7 +++++ tests/full-d11.bats | 41 ----------------------------- tests/{full-d10.bats => full.bats} | 11 +++++++- 4 files changed, 19 insertions(+), 42 deletions(-) delete mode 100644 tests/full-d11.bats rename tests/{full-d10.bats => full.bats} (62%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 89819c1..3df733c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,6 +28,7 @@ jobs: strategy: matrix: ddev_version: [stable, HEAD] + drupal_version: ["default", "10", "11"] fail-fast: false runs-on: ubuntu-latest @@ -40,3 +41,4 @@ jobs: debug_enabled: ${{ github.event.inputs.debug_enabled }} addon_repository: ${{ env.GITHUB_REPOSITORY }} addon_ref: ${{ env.GITHUB_REF }} + test_command: TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests diff --git a/tests/default-no-composer-json.bats b/tests/default-no-composer-json.bats index 8120a13..c77ec0d 100644 --- a/tests/default-no-composer-json.bats +++ b/tests/default-no-composer-json.bats @@ -1,4 +1,11 @@ setup_file() { + if [ -z "$TEST_DRUPAL_CORE" ]; then + echo "TEST_DRUPAL_CORE is necessary to run tests" >&2 + exit 1 + fi + if [ "$TEST_DRUPAL_CORE" != "default" ]; then + skip "TEST_DRUPAL_CORE=$TEST_DRUPAL_CORE not handled by this test suite" >&2 + fi load '_common.bash' _common_setup } diff --git a/tests/full-d11.bats b/tests/full-d11.bats deleted file mode 100644 index 0e42206..0000000 --- a/tests/full-d11.bats +++ /dev/null @@ -1,41 +0,0 @@ -setup_file() { - export TEST_DRUPAL_CORE=11 - load '_common.bash' - _common_setup - ddev config --php-version=8.3 --corepack-enable -} - -teardown_file() { - load '_common.bash' - _common_teardown -} - -@test "install from directory" { - load '_common.bash' - _common_test_install -} - -@test "ddev poser with composer.json" { - load '_common.bash' - _common_test_poser -} - -@test "ddev symlink-project" { - load '_common.bash' - _common_test_symlink -} - -@test "php tools availability" { - load '_common.bash' - _common_test_php -} - -@test "drupal core version" { - load '_common.bash' - _common_test_drupal_version -} - -@test "node tools availability" { - load '_common.bash' - _common_test_node -} diff --git a/tests/full-d10.bats b/tests/full.bats similarity index 62% rename from tests/full-d10.bats rename to tests/full.bats index db9baa6..bba35bb 100644 --- a/tests/full-d10.bats +++ b/tests/full.bats @@ -1,8 +1,17 @@ setup_file() { - export TEST_DRUPAL_CORE=10 + if [ -z "$TEST_DRUPAL_CORE" ]; then + echo "TEST_DRUPAL_CORE is necessary to run tests" >&2 + exit 1 + fi + if [ "$TEST_DRUPAL_CORE" != "10" ] && [ "$TEST_DRUPAL_CORE" != "11" ]; then + skip "TEST_DRUPAL_CORE=$TEST_DRUPAL_CORE not handled by this test suite" >&2 + fi load '_common.bash' _common_setup ddev config --php-version=8.2 + if [ "$TEST_DRUPAL_CORE" = "11" ]; then + ddev config --php-version=8.3 --corepack-enable + fi } teardown_file() { From 0f7246d8a02f369e94f8dd6b8ceab2811ac49e34 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Tue, 8 Oct 2024 11:03:33 -0300 Subject: [PATCH 10/24] fix: using eval for running bats tests with env vars --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3df733c..b7eebfd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,4 +41,4 @@ jobs: debug_enabled: ${{ github.event.inputs.debug_enabled }} addon_repository: ${{ env.GITHUB_REPOSITORY }} addon_ref: ${{ env.GITHUB_REF }} - test_command: TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests + test_command: eval TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests From 661a83c2fdbcb03af03e1d7dad5d54ee61a7d3cb Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Tue, 8 Oct 2024 11:23:34 -0300 Subject: [PATCH 11/24] refactor: move common code back to its own file --- tests/_common.bash | 32 +---------------------------- tests/default-no-composer-json.bats | 6 +----- tests/full.bats | 27 ++++++++++++------------ 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/tests/_common.bash b/tests/_common.bash index 80e970b..55a6393 100644 --- a/tests/_common.bash +++ b/tests/_common.bash @@ -12,6 +12,7 @@ _common_setup() { cd ${TESTDIR} ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web echo -e "web_environment:\n - DRUPAL_CORE=^${TEST_DRUPAL_CORE}" > .ddev/config.~overrides.yaml + ddev get ${DIR} } _common_teardown() { @@ -19,39 +20,8 @@ _common_teardown() { [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} } -_common_test_install() { - echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ${DIR} - ddev start -} - _common_test_poser() { ddev poser ddev mutagen sync ls -la } - -_common_test_symlink() { - ddev symlink-project - ddev mutagen sync - ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml -} - -_common_test_php() { - ddev phpcs --version - ddev phpstan --version - ddev phpunit --version -} - -_common_test_drupal_version() { - run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1' - [ "$output" = "${TEST_DRUPAL_CORE}" ] -} - -_common_test_node() { - ddev exec "cd web/core && yarn install" - ddev exec touch web/core/.env - ddev mutagen sync - ddev stylelint --version - ddev eslint --version -} diff --git a/tests/default-no-composer-json.bats b/tests/default-no-composer-json.bats index c77ec0d..4fa127f 100644 --- a/tests/default-no-composer-json.bats +++ b/tests/default-no-composer-json.bats @@ -8,6 +8,7 @@ setup_file() { fi load '_common.bash' _common_setup + ddev start } teardown_file() { @@ -15,11 +16,6 @@ teardown_file() { _common_teardown } -@test "install from directory" { - load '_common.bash' - _common_test_install -} - @test "ddev poser without composer.json" { load '_common.bash' rm -f composer.json diff --git a/tests/full.bats b/tests/full.bats index bba35bb..538fa9a 100644 --- a/tests/full.bats +++ b/tests/full.bats @@ -12,6 +12,7 @@ setup_file() { if [ "$TEST_DRUPAL_CORE" = "11" ]; then ddev config --php-version=8.3 --corepack-enable fi + ddev start } teardown_file() { @@ -19,32 +20,32 @@ teardown_file() { _common_teardown } -@test "install from directory" { - load '_common.bash' - _common_test_install -} - @test "ddev poser with composer.json" { load '_common.bash' _common_test_poser } @test "ddev symlink-project" { - load '_common.bash' - _common_test_symlink + ddev symlink-project + ddev mutagen sync + ls -la web/modules/custom/test_drupal_contrib/test_drupal_contrib.info.yml } @test "php tools availability" { - load '_common.bash' - _common_test_php + ddev phpcs --version + ddev phpstan --version + ddev phpunit --version } @test "drupal core version" { - load '_common.bash' - _common_test_drupal_version + run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1' + [ "$output" = "${TEST_DRUPAL_CORE}" ] } @test "node tools availability" { - load '_common.bash' - _common_test_node + ddev exec "cd web/core && yarn install" + ddev exec touch web/core/.env + ddev mutagen sync + ddev stylelint --version + ddev eslint --version } From be1e001e66101c23e0a7e34bb6c0d182a89dcef7 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Thu, 10 Oct 2024 15:40:27 -0300 Subject: [PATCH 12/24] fix: avoid setting DRUPAL_CORE on default tests --- tests/_common.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/_common.bash b/tests/_common.bash index 55a6393..33c66d8 100644 --- a/tests/_common.bash +++ b/tests/_common.bash @@ -11,7 +11,9 @@ _common_setup() { cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} cd ${TESTDIR} ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web - echo -e "web_environment:\n - DRUPAL_CORE=^${TEST_DRUPAL_CORE}" > .ddev/config.~overrides.yaml + if [ "$TEST_DRUPAL_CORE" != "default" ]; then + echo -e "web_environment:\n - DRUPAL_CORE=^${TEST_DRUPAL_CORE}" > .ddev/config.~overrides.yaml + fi ddev get ${DIR} } From 9db9b87fcb4f60b356516545e891ebce613f7051 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Thu, 10 Oct 2024 21:03:13 -0300 Subject: [PATCH 13/24] fix: allow to run tests without TEST_DRUPAL_CORE It will run the default core --- tests/_common.bash | 2 +- tests/default-no-composer-json.bats | 6 +----- tests/full.bats | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/_common.bash b/tests/_common.bash index 33c66d8..b4aa699 100644 --- a/tests/_common.bash +++ b/tests/_common.bash @@ -11,7 +11,7 @@ _common_setup() { cp -R ${DIR}/tests/testdata/test_drupal_contrib/* ${TESTDIR} cd ${TESTDIR} ddev config --project-name=${PROJNAME} --project-type=drupal --docroot=web - if [ "$TEST_DRUPAL_CORE" != "default" ]; then + if [ -n "$TEST_DRUPAL_CORE" ] && [ "$TEST_DRUPAL_CORE" != "default" ]; then echo -e "web_environment:\n - DRUPAL_CORE=^${TEST_DRUPAL_CORE}" > .ddev/config.~overrides.yaml fi ddev get ${DIR} diff --git a/tests/default-no-composer-json.bats b/tests/default-no-composer-json.bats index 4fa127f..4b6cabe 100644 --- a/tests/default-no-composer-json.bats +++ b/tests/default-no-composer-json.bats @@ -1,9 +1,5 @@ setup_file() { - if [ -z "$TEST_DRUPAL_CORE" ]; then - echo "TEST_DRUPAL_CORE is necessary to run tests" >&2 - exit 1 - fi - if [ "$TEST_DRUPAL_CORE" != "default" ]; then + if [ -n "$TEST_DRUPAL_CORE" ] && [ "$TEST_DRUPAL_CORE" != "default" ]; then skip "TEST_DRUPAL_CORE=$TEST_DRUPAL_CORE not handled by this test suite" >&2 fi load '_common.bash' diff --git a/tests/full.bats b/tests/full.bats index 538fa9a..9451bb1 100644 --- a/tests/full.bats +++ b/tests/full.bats @@ -1,9 +1,5 @@ setup_file() { - if [ -z "$TEST_DRUPAL_CORE" ]; then - echo "TEST_DRUPAL_CORE is necessary to run tests" >&2 - exit 1 - fi - if [ "$TEST_DRUPAL_CORE" != "10" ] && [ "$TEST_DRUPAL_CORE" != "11" ]; then + if [ -n "$TEST_DRUPAL_CORE" ] && [ "$TEST_DRUPAL_CORE" != "10" ] && [ "$TEST_DRUPAL_CORE" != "11" ]; then skip "TEST_DRUPAL_CORE=$TEST_DRUPAL_CORE not handled by this test suite" >&2 fi load '_common.bash' From 0badf96f5a387df0022e6b331990a8b531299506 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 13:14:53 -0300 Subject: [PATCH 14/24] feat: test for presence of web/core and vendor --- tests/_common.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/_common.bash b/tests/_common.bash index b4aa699..9c3806c 100644 --- a/tests/_common.bash +++ b/tests/_common.bash @@ -25,5 +25,7 @@ _common_teardown() { _common_test_poser() { ddev poser ddev mutagen sync + ls -la web/core + ls -la vendor/ ls -la } From e6bba3a89ff759ef8760b05f4042fb71cae65b8c Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 13:15:11 -0300 Subject: [PATCH 15/24] fix: allow drupal core version to work without a specified test core --- tests/full.bats | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/full.bats b/tests/full.bats index 9451bb1..01c9321 100644 --- a/tests/full.bats +++ b/tests/full.bats @@ -35,7 +35,12 @@ teardown_file() { @test "drupal core version" { run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1' - [ "$output" = "${TEST_DRUPAL_CORE}" ] + if [ -n "${TEST_DRUPAL_CORE}" ]; then + [ "$output" = "${TEST_DRUPAL_CORE}" ] + else + DDEV_DRUPAL_CORE=$(ddev exec 'echo "${DRUPAL_CORE/^/}"') + [ "$output" = "$DDEV_DRUPAL_CORE" ] + fi } @test "node tools availability" { From ded820f4797c0b91b006000d8f66ab9502a85c14 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 13:15:27 -0300 Subject: [PATCH 16/24] refactor: fix typos and composer.json cleanup --- tests/testdata/test_drupal_contrib/composer.json | 6 ++---- .../test_drupal_contrib/test_drupal_contrib.info.yml | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/testdata/test_drupal_contrib/composer.json b/tests/testdata/test_drupal_contrib/composer.json index 947ac40..e158b86 100644 --- a/tests/testdata/test_drupal_contrib/composer.json +++ b/tests/testdata/test_drupal_contrib/composer.json @@ -1,5 +1,5 @@ { - "name": "drupal/ddev_drupal_contrab", + "name": "drupal/ddev_drupal_contrib", "type": "drupal-module", "license": "GPL-2.0+", "homepage": "https://github.com/ddev/ddev-drupal-contrib", @@ -10,10 +10,8 @@ "url": "https://packages.drupal.org/8" } ], - "require": { - "drupal/devel": "^5.0" - }, "require-dev": { + "drupal/devel": "^5.0", "drush/drush": "^11 || ^12 || ^13" }, "config": { diff --git a/tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml b/tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml index 24d8d01..c1abee0 100644 --- a/tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml +++ b/tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml @@ -1,3 +1,3 @@ -name: 'ddev Drupal Contrib dummy module for tests' +name: 'ddev-drupal-contrib dummy module for tests' type: module core_version_requirement: ^8.8 || ^9 || ^10 || ^11 From f1e92c302af5fe0ddc99c7fc78e647985426b8bc Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 13:16:59 -0300 Subject: [PATCH 17/24] docs: README tweaks about testing --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 442a2ba..afbdb83 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,31 @@ ddev phpcbf -q 3. Mark the file as executable: `chmod +x pre-commit`. +## 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. + +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`. + +Tests are triggered either manually, automatically on every push to the +repository, or periodically each night. The automated tests are agains all of +the supported Drupal core versions. + +Please make sure to attend to test failures when they happen. Others will be +depending on you. + +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 From fb29154fa5c9a8ee67cb00084ec6a1ee08dfffe0 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 13:34:41 -0300 Subject: [PATCH 18/24] feat: using bats-assert --- .github/workflows/tests.yml | 2 +- tests/full.bats | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b7eebfd..d305c26 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,4 +41,4 @@ jobs: debug_enabled: ${{ github.event.inputs.debug_enabled }} addon_repository: ${{ env.GITHUB_REPOSITORY }} addon_ref: ${{ env.GITHUB_REF }} - test_command: eval TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests + test_command: eval BATS_LIB_PATH=/opt/homebrew/lib TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests diff --git a/tests/full.bats b/tests/full.bats index 01c9321..573f2bd 100644 --- a/tests/full.bats +++ b/tests/full.bats @@ -1,3 +1,6 @@ +bats_load_library 'bats-support' +bats_load_library 'bats-assert' + setup_file() { if [ -n "$TEST_DRUPAL_CORE" ] && [ "$TEST_DRUPAL_CORE" != "10" ] && [ "$TEST_DRUPAL_CORE" != "11" ]; then skip "TEST_DRUPAL_CORE=$TEST_DRUPAL_CORE not handled by this test suite" >&2 @@ -36,10 +39,10 @@ teardown_file() { @test "drupal core version" { run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1' if [ -n "${TEST_DRUPAL_CORE}" ]; then - [ "$output" = "${TEST_DRUPAL_CORE}" ] + assert_output "${TEST_DRUPAL_CORE}" else DDEV_DRUPAL_CORE=$(ddev exec 'echo "${DRUPAL_CORE/^/}"') - [ "$output" = "$DDEV_DRUPAL_CORE" ] + assert_output "$DDEV_DRUPAL_CORE" fi } From b2ba34c178e44aef46c8af095a6e933c99ce9ee9 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 13:48:26 -0300 Subject: [PATCH 19/24] fix: use `brew --prefix` for BATS_LIB_PATH --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d305c26..105ba53 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,4 +41,4 @@ jobs: debug_enabled: ${{ github.event.inputs.debug_enabled }} addon_repository: ${{ env.GITHUB_REPOSITORY }} addon_ref: ${{ env.GITHUB_REF }} - test_command: eval BATS_LIB_PATH=/opt/homebrew/lib TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests + test_command: eval BATS_LIB_PATH=$(brew --prefix)/lib TEST_DRUPAL_CORE=${{ matrix.drupal_version }} bats tests From ee13990dfc58ff666738f2a0a87b1c4053da5b92 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 14:06:44 -0300 Subject: [PATCH 20/24] feat: using submodules for bats --- .github/workflows/tests.yml | 7 ++++++- .gitmodules | 9 +++++++++ README.md | 10 ++++++---- tests/bats | 1 + tests/full.bats | 4 ++-- tests/helpers/bats-assert | 1 + tests/helpers/bats-support | 1 + 7 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 .gitmodules create mode 160000 tests/bats create mode 160000 tests/helpers/bats-assert create mode 160000 tests/helpers/bats-support diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 105ba53..5c02118 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} ./tests/bats/bin/bats tests diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c7ef022 --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/README.md b/README.md index afbdb83..47ee33d 100644 --- a/README.md +++ b/README.md @@ -107,14 +107,17 @@ 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 tests locally you need to first install the git submodules with: +`git submodule init`. + +Then you can run `./tests/bats/bin/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/bin/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 @@ -127,7 +130,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 diff --git a/tests/bats b/tests/bats new file mode 160000 index 0000000..89a7fae --- /dev/null +++ b/tests/bats @@ -0,0 +1 @@ +Subproject commit 89a7fae3b651d5c2f42a3874ec32e821014814eb diff --git a/tests/full.bats b/tests/full.bats index 573f2bd..d59ce8b 100644 --- a/tests/full.bats +++ b/tests/full.bats @@ -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 diff --git a/tests/helpers/bats-assert b/tests/helpers/bats-assert new file mode 160000 index 0000000..e2d855b --- /dev/null +++ b/tests/helpers/bats-assert @@ -0,0 +1 @@ +Subproject commit e2d855bc78619ee15b0c702b5c30fb074101159f diff --git a/tests/helpers/bats-support b/tests/helpers/bats-support new file mode 160000 index 0000000..9bf10e8 --- /dev/null +++ b/tests/helpers/bats-support @@ -0,0 +1 @@ +Subproject commit 9bf10e876dd6b624fe44423f0b35e064225f7556 From b66a9206ba7413ed32c0f59175aa420e03bb88dc Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 15:16:25 -0300 Subject: [PATCH 21/24] docs: small tweak --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47ee33d..101af04 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ ddev phpcbf -q Tests are done with Bats. It is a simple testing framework that just uses Bash. -To run tests locally you need to first install the git submodules with: +To run tests locally you need to first install bats' git submodules with: `git submodule init`. Then you can run `./tests/bats/bin/bats ./tests` within the root of this project. From 1e40a4f9a285e69cd70a47e6e1b8baff44291765 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 15:33:46 -0300 Subject: [PATCH 22/24] docs: proper submodule git commands --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 101af04..c56a235 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,11 @@ ddev phpcbf -q Tests are done with Bats. It is a simple testing framework that just uses Bash. To run tests locally you need to first install bats' git submodules with: -`git submodule init`. + +``` +git submodule init +git submodule update +``` Then you can run `./tests/bats/bin/bats ./tests` within the root of this project. From 9cb313bc8f678f9f9c9809f8fb62cbb4dcc5edd8 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Fri, 11 Oct 2024 17:33:58 -0300 Subject: [PATCH 23/24] docs: simplified tests commands --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c56a235..9cc2ad2 100644 --- a/README.md +++ b/README.md @@ -110,12 +110,15 @@ Tests are done with Bats. It is a simple testing framework that just uses Bash. To run tests locally you need to first install bats' git submodules with: +```sh +git submodule update --init ``` -git submodule init -git submodule update -``` -Then you can run `./tests/bats/bin/bats ./tests` within the root of this project. +Then you can run within the root of this project: + +```sh +./tests/bats/bin/bats ./tests +``` 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 From ae2ffbe79fc68d1197ee126dd549461d8e81f08f Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Wed, 16 Oct 2024 08:39:32 -0300 Subject: [PATCH 24/24] docs: apply suggestions from code review Co-authored-by: tyler36 --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9cc2ad2..a169cae 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ ddev phpcbf -q ## Add-on tests -Tests are done with Bats. It is a simple testing framework that just uses Bash. +Tests are done with Bats. It is a testing framework that uses Bash. To run tests locally you need to first install bats' git submodules with: @@ -120,14 +120,13 @@ Then you can run within the root of this project: ./tests/bats/bin/bats ./tests ``` -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 +Tests will be run using the default drupal core of the contrib. To test against a different Drupal core version, update the `TEST_DRUPAL_CORE` environment variable. i.e. `TEST_DRUPAL_CORE=11 ./tests/bats/bin/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 +Tests are triggered automatically on every push to the +repository, and periodically each night. The automated tests are agains all of the supported Drupal core versions. Please make sure to attend to test failures when they happen. Others will be