From ed0e49d16efcf99009a79f03176e62688bccc2f7 Mon Sep 17 00:00:00 2001 From: Lukas Hass Date: Fri, 18 Feb 2022 16:11:26 +0100 Subject: [PATCH] update docs and remove references to testcafe --- CONTRIBUTING.md | 34 ++----------- .../Variables/Cache/variables_cache_1.json | 4 +- .../Variables/Cache/variables_cache_2.json | 4 +- tests/Dockerfile | 5 -- tests/README.md | 50 +++++++++++++++---- tests/package.json | 2 +- tests/tests/utils/containers.ts | 13 +---- 7 files changed, 51 insertions(+), 61 deletions(-) delete mode 100644 tests/Dockerfile diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2d3f5d0b..b700e5c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,46 +67,20 @@ $ docker-compose exec back yarn run pretty WorkAdventure is based on a video game engine (Phaser), and video games are not the easiest programs to unit test. -Nevertheless, if your code can be unit tested, please provide a unit test (we use Jasmine), or an end-to-end test (we use Testcafe). +Nevertheless, if your code can be unit tested, please provide a unit test (we use Jasmine), or an end-to-end test (we use Playwright). If you are providing a new feature, you should setup a test map in the `maps/tests` directory. The test map should contain some description text describing how to test the feature. * if the features is meant to be manually tested, you should modify the `maps/tests/index.html` file to add a reference to your newly created test map -* if the features can be automatically tested, please provide a testcafe test +* if the features can be automatically tested, please provide an end-to-end test -#### Running testcafe tests +#### Running end-to-end tests End-to-end tests are available in the "/tests" directory. -To run these tests locally: - -```console -$ LIVE_RELOAD=0 docker-compose up -d -$ cd tests -$ npm install -$ npm run test -``` - -Note: If your tests fail on a Javascript error in "sockjs", this is due to the -Webpack live reload. The Webpack live reload feature is conflicting with testcafe. This is why we recommend starting -WorkAdventure with the `LIVE_RELOAD=0` environment variable. - -End-to-end tests can take a while to run. To run only one test, use: - -```console -$ npm run test -- tests/[name of the test file].ts -``` - -You can also run the tests inside a container (but you will not have visual feedbacks on your test, so we recommend using -the local tests). - -```console -$ LIVE_RELOAD=0 docker-compose up -d -# Wait 2-3 minutes for the environment to start, then: -$ PROJECT_DIR=$(pwd) docker-compose -f docker-compose.testcafe.yml up -``` +More information on running end-to-end tests can be found in the [`/tests/README`](/tests/README.md). ### A bad wording or a missing language diff --git a/maps/tests/Variables/Cache/variables_cache_1.json b/maps/tests/Variables/Cache/variables_cache_1.json index f48e9c18..5166f56d 100644 --- a/maps/tests/Variables/Cache/variables_cache_1.json +++ b/maps/tests/Variables/Cache/variables_cache_1.json @@ -40,7 +40,7 @@ { "fontfamily":"Sans Serif", "pixelsize":11, - "text":"Test:\nThis test is to be run automatically using testcafe", + "text":"Test:\nThis test is to be run automatically using playwright", "wrap":true }, "type":"", @@ -79,4 +79,4 @@ "type":"map", "version":1.5, "width":10 -} \ No newline at end of file +} diff --git a/maps/tests/Variables/Cache/variables_cache_2.json b/maps/tests/Variables/Cache/variables_cache_2.json index 068063eb..598d2322 100644 --- a/maps/tests/Variables/Cache/variables_cache_2.json +++ b/maps/tests/Variables/Cache/variables_cache_2.json @@ -40,7 +40,7 @@ { "fontfamily":"Sans Serif", "pixelsize":11, - "text":"Test:\nThis test is to be run automatically using testcafe\n\n(2nd file)", + "text":"Test:\nThis test is to be run automatically using playwright\n\n(2nd file)", "wrap":true }, "type":"", @@ -123,4 +123,4 @@ "type":"map", "version":1.5, "width":10 -} \ No newline at end of file +} diff --git a/tests/Dockerfile b/tests/Dockerfile deleted file mode 100644 index c039434f..00000000 --- a/tests/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM testcafe/testcafe:1.18.2 - -USER root -RUN apk add docker-compose -USER user diff --git a/tests/README.md b/tests/README.md index 3aeb046d..99ac2fa0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,20 +1,52 @@ -End-to-end tests +# End-to-end tests This directory contains automated end to end tests. -To run them locally: +## Installation -```console -$ npm install -$ ADMIN_API_TOKEN=123 npm test +```bash +npm install +npx playwright install --with-deps +``` + +## Run on development environment + +Start WorkAdventure with: + +```bash +docker-compose up -d +``` + +Wait 2-3 minutes for the environment to start, then: + +Start the tests with: + +```bash +ADMIN_API_TOKEN=123 npm run test ``` You'll need to adapt the `ADMIN_API_TOKEN` to the value you use in your `.env` file. -Alternatively, you can use docker-compose to run the tests: +## Run on production like environment -```console -$ PROJECT_DIR=$(pwd) docker-compose -f docker-compose.testcafe.yml up --exit-code-from testcafe +Start WorkAdventure with: + +```bash +docker-compose -f docker-compose.yaml -f docker-compose.e2e.yml up -d --build ``` -Note: by default, tests are running in Chrome locally and in Chromium in the Docker image. +Start the tests with: + +```bash +ADMIN_API_TOKEN=123 npm run test-prod-like +``` + +You'll need to adapt the `ADMIN_API_TOKEN` to the value you use in your `.env` file. + +## Run selected tests + +End-to-end tests can take a while to run. To run only one test in one browser, use: + +```bash +ADMIN_API_TOKEN=123 npm run test -- [name of the test file] --project=[chromium|firefox|webkit] +``` diff --git a/tests/package.json b/tests/package.json index e1bb9a50..27fe2671 100644 --- a/tests/package.json +++ b/tests/package.json @@ -6,7 +6,7 @@ "dockerode": "^3.3.1" }, "scripts": { - "test": "ADMIN_API_TOKEN=123 playwright test", + "test": "playwright test", "test-prod-like": "OVERRIDE_DOCKER_COMPOSE=docker-compose.e2e.yml npm run test" } } diff --git a/tests/tests/utils/containers.ts b/tests/tests/utils/containers.ts index 920fbbc5..81d52530 100644 --- a/tests/tests/utils/containers.ts +++ b/tests/tests/utils/containers.ts @@ -8,23 +8,12 @@ const path = require("path"); const fs = require('fs'); /** - * Execute Docker compose, passing the correct host directory (in case this is run from the TestCafe container) + * Execute Docker compose, passing the correct host directory */ export function dockerCompose(command: string): void { let param = ''; - const projectDir = process.env.PROJECT_DIR; const overrideDockerCompose = process.env.OVERRIDE_DOCKER_COMPOSE; - if (!projectDir && fs.existsSync('/project')) { - // We are probably in the docker-image AND we did not pass PROJECT_DIR env variable - throw new Error('Incorrect docker-compose command used to fire testcafe tests. You need to add a PROJECT_DIR environment variable. Please refer to the CONTRIBUTING.md guide'); - } - - if (projectDir) { - const dirName = path.basename(projectDir); - param = '--project-name '+dirName+' --project-directory '+projectDir; - } - if (overrideDockerCompose) { param += ' -f docker-compose.yaml -f '+overrideDockerCompose; }