Skip to content

Commit

Permalink
refactored test and installation
Browse files Browse the repository at this point in the history
- using Typescript in tests
- moved helper methods into testHelper.ts
- using wait-on instead of sleep (added NPM wait-on)
- having all script output starting with "***"
- adding build option to scripts/compose.sh
- fixing some typos and improving some READMEs
  • Loading branch information
muhme committed Dec 20, 2023
1 parent f245a28 commit cdded00
Show file tree
Hide file tree
Showing 16 changed files with 458 additions and 172 deletions.
200 changes: 200 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"license": "MIT",
"dependencies": {
"joomla-cypress": "github:muhme/joomla-cypress#issue-9-fix-functions"
},
"devDependencies": {
"wait-on": "^7.2.0"
}
}
6 changes: 3 additions & 3 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The scripts are used on the Mac command line, but should also work on Linux and

| Script | Description | Additional Info |
| --- | --- | --- |
| `scripts/compose.sh` | Delete the six Docker containers and build them new | |
| `scripts/compose.sh` | Delete the six Docker containers and build them new | - with optional argument `build` an docker compose build --no-cache is executed in advance |
| `scripts/exec.sh` | Get access to the Joomla Docker container and **linking** the module source | - Linking maps the local host folder into the Joomla Docker container to test code changes immediately |
| `scripts/cypress.sh` | Open Cypress in GUI mode on local host for desired Joomla version | Needs Cypress installed on host. |
| `scripts/install.sh` | Install Joomla and module `mod_zitat_service_de` | - Using Cypress in headless mode<br>- With argument 3, 4, or 5 install this Joomla version; without argument install all three<br>- With environment variable `CYPRESS_OPTIONS`, e.g., `CYPRESS_OPTIONS="video=true" scripts/install.sh 5` |
Expand All @@ -16,8 +16,8 @@ The scripts are used on the Mac command line, but should also work on Linux and

And now you are ready for ... triple speed :smiley: with the creation of six Docker containers, the installation of Joomla and the modules three times and testing the module in all three Joomla versions with only one command line.
```
$ scripts/compose.sh && sleep 5 && scripts/install.sh && scripts/test.sh
$ scripts/compose.sh && scripts/install.sh && scripts/test.sh
```

> [!WARNING]
> After using `scripts/exec.sh` the module folder inside Docker container is symbolic linked. If you uninstall the module you delete all source files in your host folder! :point_right: Inside container, you have to delete symbolic link before.
> After using `scripts/exec.sh` the module folder inside Docker container is symbolic linked. If you uninstall the module in Joomla, you will delete all source files in your host folder! :point_right: Inside container, you have to delete symbolic link before.
2 changes: 1 addition & 1 deletion scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
#
# clean.sh - delete all quote_joomla_* docker containers

echo 'Removing all docker containers quote_joomla_*'
echo '*** Removing all docker containers quote_joomla_*'
docker ps -a --format '{{.Names}}' | grep '^quote_joomla_' | xargs docker rm -f
4 changes: 2 additions & 2 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ all_versions=(3 4 5)
#
checkVersion() {
if [ "$#" -gt 1 ] || ([ "$#" -eq 1 ] && ! containsElement "$1" "${all_versions[@]}"); then
echo "Error: no argument (for all) or Joomla version from: ${all_versions[@]}"
echo "*** Error: no argument (for all) or Joomla version from: ${all_versions[@]}"
exit 1
fi

Expand All @@ -50,7 +50,7 @@ checkVersion() {
#
checkOneVersion() {
if [ "$#" -ne 1 ] || ! containsElement "$1" "${all_versions[@]}"; then
echo "Error: needs Joomla version as one and only argument from: ${all_versions[@]}"
echo "*** Error: needs Joomla version as one and only argument from: ${all_versions[@]}"
exit 1
fi
}
11 changes: 8 additions & 3 deletions scripts/compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
# This software is licensed under the MIT License.
# For the full license text, see the LICENSE file in the project root or visit https://opensource.org/licenses/MIT
#
# build.sh - delete the six docker containers and build them new
# compose.sh - delete the six docker containers and build them new

echo 'Removing all docker containers quote_joomla_*'
echo '*** Removing all docker containers quote_joomla_*'
docker ps -a --format '{{.Names}}' | grep '^quote_joomla_' | xargs docker rm -f

echo 'Creating docker containers new'
if [ $# -eq 1 ] && [ "$1" = "build" ] ; then
echo '*** Docker compose build --no-cache'
docker compose build --no-cache
fi

echo '*** Docker compose up'
docker compose up -d
2 changes: 1 addition & 1 deletion scripts/cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
source scripts/common.sh
checkOneVersion $*

echo "open Cypress for Joomla $1"
echo "*** Open Cypress for Joomla $1"
cd test && export "JOOMLA_VERSION=$1" && npx cypress open
2 changes: 1 addition & 1 deletion scripts/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
source scripts/common.sh
checkOneVersion $*

echo "open Joomla $1 container and sym linking modules/mod_zitat_service_de"
echo "*** Open Joomla $1 container and sym linking modules/mod_zitat_service_de"
docker exec -it "quote_joomla_$1" /bin/bash -c "cd /var/www/html/modules && rm -rf mod_zitat_service_de && ln -s /quote_joomla/src mod_zitat_service_de && ls -l mod_zitat_service_de && bash"
3 changes: 2 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ source scripts/common.sh
checkVersion $*

for version in ${versions[@]}; do
echo "installing Joomla $version and module mod_zitat_service_de"
echo "*** Installing Joomla $version and module mod_zitat_service_de"
node_modules/wait-on/bin/wait-on -l -t "60s" "http://localhost:200${version}"
docker exec -it quote_joomla_cypress sh -c "JOOMLA_VERSION=$version cypress run --spec cypress/e2e/install.cy.js $config_cypress_options"
done
6 changes: 3 additions & 3 deletions scripts/pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ calculate_hash() {
shasum -a 512 "$FILE" | awk '{print $1}'
# If neither command is found, print an error message
else
echo "Error: Command sha512sum or shasum not found." >&2
echo "*** Error: Command sha512sum or shasum not found." >&2
return 1
fi
}
Expand All @@ -46,7 +46,7 @@ ZIP="dist/mod_zitat_service_de_${VERSION}.zip" # module extension packed as ZIP
UPDATE="dist/update.xml"

if [ ! -f "$MANIFEST" ]; then
echo "Error: Missing file \"$MANIFEST\" – are you in project root directory?"
echo "*** Error: Missing file \"$MANIFEST\" – are you in project root directory?"
exit 1
fi

Expand All @@ -62,4 +62,4 @@ sed "s|\(.*<sha512>\).*</sha512>|\1${HASH}</sha512>|; \
s|\(.*\)/download/.*/mod_zitat_service_de_.*\.zip\(.*\)|\1/download/${VERSION}/mod_zitat_service_de_${VERSION}.zip\2|" $UPDATE > $TMP && cp $TMP $UPDATE

# work is done
echo "version $VERSION packed as $ZIP and $UPDATE updated"
echo "*** Version $VERSION packed as $ZIP and $UPDATE updated"
4 changes: 2 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ source scripts/common.sh
checkVersion $*

for version in ${versions[@]}; do
echo "testing module mod_zitat_service_de in Joomla $version"
docker exec -it quote_joomla_cypress sh -c "JOOMLA_VERSION=$version cypress run --spec cypress/e2e/test.cy.js $options"
echo "*** Testing module mod_zitat_service_de in Joomla $version"
docker exec -it quote_joomla_cypress sh -c "JOOMLA_VERSION=$version cypress run --spec cypress/e2e/test.cy.ts $options"
done
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ host$ scripts/install.sh 5
Running: install.cy.js (1 of 1)
Install Joomla 4 and module zitat-service
*** Install Joomla 5 and module zitat-service
✓ Install Joomla and module zitat-service (40084ms)
(Run Finished)
Expand Down
Loading

0 comments on commit cdded00

Please sign in to comment.