generated from ddev/ddev-addon-template
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a more robust set of tests (#85)
* wip: initial tests refactor * feat: d10 and d11 tests * tests: d10 remove corepack and use d11 yarn install approach * refactor: tests rename * refactor: moves common code into _common.bash * feat: require-dev on d11 test as well * feat: test drupal version with drush * feat: add bats_require_minimum_version 1.5.0 * feat: single full.bats test and GHA matrix strategy * fix: using eval for running bats tests with env vars * refactor: move common code back to its own file * fix: avoid setting DRUPAL_CORE on default tests * fix: allow to run tests without TEST_DRUPAL_CORE It will run the default core * feat: test for presence of web/core and vendor * fix: allow drupal core version to work without a specified test core * refactor: fix typos and composer.json cleanup * docs: README tweaks about testing * feat: using bats-assert * fix: use `brew --prefix` for BATS_LIB_PATH * feat: using submodules for bats * docs: small tweak * docs: proper submodule git commands * docs: simplified tests commands * docs: apply suggestions from code review Co-authored-by: tyler36 <[email protected]> --------- Co-authored-by: tyler36 <[email protected]> Co-authored-by: Moshe Weitzman <[email protected]>
- Loading branch information
1 parent
4e0a730
commit 78380b6
Showing
12 changed files
with
207 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/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} | ||
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 | ||
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} | ||
} | ||
|
||
_common_teardown() { | ||
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 | ||
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} | ||
} | ||
|
||
_common_test_poser() { | ||
ddev poser | ||
ddev mutagen sync | ||
ls -la web/core | ||
ls -la vendor/ | ||
ls -la | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
setup_file() { | ||
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' | ||
_common_setup | ||
ddev start | ||
} | ||
|
||
teardown_file() { | ||
load '_common.bash' | ||
_common_teardown | ||
} | ||
|
||
@test "ddev poser without composer.json" { | ||
load '_common.bash' | ||
rm -f composer.json | ||
_common_test_poser | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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 | ||
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 | ||
ddev start | ||
} | ||
|
||
teardown_file() { | ||
load '_common.bash' | ||
_common_teardown | ||
} | ||
|
||
@test "ddev poser with composer.json" { | ||
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 | ||
} | ||
|
||
@test "php tools availability" { | ||
ddev phpcs --version | ||
ddev phpstan --version | ||
ddev phpunit --version | ||
} | ||
|
||
@test "drupal core version" { | ||
run -0 ddev exec 'drush st --fields=drupal-version --format=string | cut -d. -f1' | ||
if [ -n "${TEST_DRUPAL_CORE}" ]; then | ||
assert_output "${TEST_DRUPAL_CORE}" | ||
else | ||
DDEV_DRUPAL_CORE=$(ddev exec 'echo "${DRUPAL_CORE/^/}"') | ||
assert_output "$DDEV_DRUPAL_CORE" | ||
fi | ||
} | ||
|
||
@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 | ||
} |
Submodule bats-assert
added at
e2d855
Submodule bats-support
added at
9bf10e
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "drupal/ddev_drupal_contrib", | ||
"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-dev": { | ||
"drupal/devel": "^5.0", | ||
"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" | ||
] | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/testdata/test_drupal_contrib/test_drupal_contrib.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: 'ddev-drupal-contrib dummy module for tests' | ||
type: module | ||
core_version_requirement: ^8.8 || ^9 || ^10 || ^11 |