Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

e2e-start-system-under-test:
bash Tests/IntegrationTests/start-system-under-test-docker.sh

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

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ 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 e2e-start-system-under-test` (starts a docker setup with the system under test)
* `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.system-under-test.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: ${DB_IMAGE}
environment:
MYSQL_DATABASE: neos
MYSQL_ROOT_PASSWORD: not_a_real_password

volumes:
composer_cache:
105 changes: 105 additions & 0 deletions Tests/IntegrationTests/start-system-under-test-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env bash

set -e

ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
export DB_IMAGE=arm64v8/mysql:8
elif [ "$ARCH" = "x86_64" ]; then
export DB_IMAGE=mysql:8
else
echo "Unknown architecture"
exit 1
fi

function dc() {
if [ -n "$(docker compose version)" ]; then
# use the docker composer plugin
docker compose -f ./Tests/IntegrationTests/docker-compose.system-under-test.yaml $@
else
# legacy docker compose standalone
docker-compose -f ./Tests/IntegrationTests/docker-compose.system-under-test.yaml $@
fi
}

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: Lets use paths relative to the shellscript?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me, I didn't want to put too much time into it and copy pasted the most stuff.

It's clear, that we could build a better system for all of this but I needed a faster feedback loop fast 😬
I want to build tests for Bugs I fix and wasting 2h just for building the test and another 2 for running them to see if the fix works and we don't mess up something else ist just too much ^^

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 "#############################################################################"
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 Packages/Application/Neos.Neos.Ui
ln -s /usr/src/neos-ui/ /usr/src/app/TestDistribution/Packages/Application/Neos.Neos.Ui
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works in generally, but not in this flow. Later i think due to the composer reinstall neos/test-site this linking will be gone and we have the original composer neos ui... so this step should come later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this setup and it worked for me.

Thanks for fixing the issues on Linux ❤️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is not fixed yet ... and I don't know why it would work on your machine ... I mean the problem is within docker after all


# 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/DistributionPackages/Neos.TestNodeTypes
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

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
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