Skip to content

Commit

Permalink
TASK: Add another way to run tests locally with a system under test i…
Browse files Browse the repository at this point in the history
…n docker (#3369)

* TASK: Add another way to run tests locally with a system under test in docker

* TASK: Also sym link inside TestDistribution to mounted Neos.TestNodeTypes package

* Task: Make `make e2e-start-system-under-test` run on linux 64

* TASK: Fix stuff

---------

Co-authored-by: Robert Baruck <robert.baruck@sandstorm.de>
Co-authored-by: mhsdesign <85400359+mhsdesign@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 20, 2023
1 parent d301f14 commit 0a73f4f
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ test-e2e:
test-e2e-docker:
@bash Tests/IntegrationTests/e2e-docker.sh $(or $(browser),chrome)

start-neos-dev-instance:
bash Tests/IntegrationTests/start-neos-dev-instance.sh

## Executes make lint-js and make lint-editorconfig.
lint: lint-js lint-editorconfig

Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ To setup end-to-end tests locally you have got to do the same things described i
For executing the end to end tests on a Mac with catalina or higher you need to permit screen recording. Open 'System Preferences > Security & Privacy > Privacy > Screen Recording' and check 'TestCafe Browser Tools' in the application list.
#### Local Development with e2e-tests & docker
To speed up the e2e-test workflow/feedback loop you can start the system under test in a docker setup and run the tests against that:
* `make start-neos-dev-instance` (starts a docker setup with the system under test)
* The neos dev instance is available at `localhost:8081`
* To enter the container run `docker compose -f Tests/IntegrationTests/docker-compose.neos-dev-instance.yaml exec php bash`
* `yarn run testcafe <browser> <testFile> <optional flags>`
* for example, this runs all tests in chrome:
`yarn run testcafe chrome Tests/IntegrationTests/Fixtures`
* some helpful optional flags are
* `-T 'sidebars'` - grep tests by pattern and only execute those
* `--selector-timeout=10000` - if you work on async pieces of the UI then this might help to prevent race conditions
* `--assertion-timeout=30000` - see above
* `--debug-on-fail` - you can debug the state of the app at the moment an assertion failed
##### Debugging integration tests
* View the recording via Sauce Labs. You can find the url in the beginning of the test output.
Expand Down
25 changes: 25 additions & 0 deletions Tests/IntegrationTests/docker-compose.neos-dev-instance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.4"
services:

php:
image: thecodingmachine/php:8.0-v4-cli-node16
command: tail -f /dev/null
ports:
- 8081:8081
volumes:
- composer_cache:/home/circleci/.composer/cache
# add Neos Ui root as cached read-only volume that will be later symlinked into TestDistribution/Packages/
- ../../.:/usr/src/neos-ui:cached,ro
environment:
# Enable GD
PHP_EXTENSION_GD: 1
COMPOSER_CACHE_DIR: /home/circleci/.composer/cache

db:
image: mysql:8
environment:
MYSQL_DATABASE: neos
MYSQL_ROOT_PASSWORD: not_a_real_password

volumes:
composer_cache:
89 changes: 89 additions & 0 deletions Tests/IntegrationTests/start-neos-dev-instance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash

set -e

function dc() {
# use the docker composer plugin
docker compose -f ./Tests/IntegrationTests/docker-compose.neos-dev-instance.yaml $@
}

echo "#############################################################################"
echo "# Start docker environment... #"
echo "#############################################################################"
dc down
dc up -d
dc exec -T php bash <<-'BASH'
rm -rf /usr/src/app/*
BASH
docker cp "$(pwd)"/Tests/IntegrationTests/. "$(dc ps -q php)":/usr/src/app
sleep 2

echo ""
echo "#############################################################################"
echo "# Install dependencies... #"
echo "#############################################################################"
dc exec -T php bash <<-'BASH'
cd /usr/src/app
sudo chown -R docker:docker .
sudo chown -R docker:docker /home/circleci/
cd TestDistribution
composer install
BASH

echo "#############################################################################"
echo "# Initialize Neos... #"
echo "#############################################################################"
dc exec -T php bash <<-'BASH'
cd TestDistribution
sed -i 's/host: 127.0.0.1/host: db/g' Configuration/Settings.yaml
./flow flow:cache:flush
./flow flow:cache:warmup
./flow doctrine:migrate
./flow user:create --username=admin --password=password --first-name=John --last-name=Doe --roles=Administrator || true
BASH

echo ""
echo "#############################################################################"
echo "# Start Flow Server... #"
echo "#############################################################################"
dc exec -T php bash <<-'BASH'
cd TestDistribution
./flow server:run --port 8081 --host 0.0.0.0 &
BASH

dc exec -T php bash <<-BASH
mkdir -p ./TestDistribution/DistributionPackages
rm -rf ./TestDistribution/DistributionPackages/Neos.TestSite
ln -s "../../Fixtures/1Dimension/SitePackage" ./TestDistribution/DistributionPackages/Neos.TestSite
# TODO: optimize this
cd TestDistribution
composer reinstall neos/test-site
./flow flow:cache:flush --force
./flow flow:cache:warmup
./flow configuration:show --path Neos.ContentRepository.contentDimensions
if ./flow site:list | grep -q 'Node name'; then
./flow site:prune '*'
fi
./flow site:import --package-key=Neos.TestSite
./flow resource:publish
BASH

echo ""
echo "#############################################################################"
echo "# Create sym links to mounted Docker volumes... #"
echo "#############################################################################"
echo ""
dc exec -T php bash <<-'BASH'
# replace installed Neos Ui with local dev via sym link to mounted volume
# WHY: We want changes of dev to appear in system under test without rebuilding the whole system
rm -rf /usr/src/app/TestDistribution/Packages/Application/Neos.Neos.Ui
ln -s /usr/src/neos-ui /usr/src/app/TestDistribution/Packages/Application/Neos.Neos.Ui
# enable changes of the Neos.TestNodeTypes outside of the container to appear in the container via sym link to mounted volume
rm -rf /usr/src/app/TestDistribution/Packages/Application/Neos.TestNodeTypes
ln -s /usr/src/neos-ui/Tests/IntegrationTests/SharedNodeTypesPackage/ /usr/src/app/TestDistribution/Packages/Application/Neos.TestNodeTypes
BASH
2 changes: 1 addition & 1 deletion Tests/IntegrationTests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function checkPropTypes() {
delete error[0];
}
// Quick fix to be able to use node 16 with testcafe @see https://github.com/DevExpress/testcafe/issues/7097
if (error[0] && error[0].search('hammerhead.js:15:1506') >= 0) {
if (error[0] && error[0].search('hammerhead.js') >= 0) {
delete error[0];
}
if (error[0]) {
Expand Down

0 comments on commit 0a73f4f

Please sign in to comment.