From: Chocobozzz Date: Tue, 2 Nov 2021 09:13:53 +0000 (+0100) Subject: Improve tests documentation X-Git-Tag: v4.0.0-rc.1~179 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=9883e60f307c8161ef694b8fc209b857b196add0;p=github%2FChocobozzz%2FPeerTube.git Improve tests documentation --- diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 47129ea74..74d20aa78 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -175,43 +175,12 @@ $ npm run dev -- --ar-locale ### Testing +#### Unit/integration tests + Your code contributions must pass the tests before they can be merged. Tests ensure most of the application behaves as expected and respect the syntax conventions. They will run upon PR submission as part of our CI, but running them beforehand yourself will get you faster feedback and save CI runner time for others. -PeerTube mainly features backend and plugin tests, found in `server/tests`. - -#### Unit tests - -Create a PostgreSQL user **with the same name as your username** in order to avoid using the *postgres* user. - -Then, we can create the databases (if they don't already exist): - -``` -$ sudo -u postgres createuser you_username --createdb --superuser -$ npm run clean:server:test -``` - -Build the application and run the unit/integration tests: - -``` -$ npm run build -- --light -$ npm test -``` - -If you just want to run 1 test (which is what you want to debug a specific test rapidly): - -``` -$ TS_NODE_FILES=true npm run mocha -- --exit -r ts-node/register -r tsconfig-paths/register --bail server/tests/api/videos/single-server.ts -``` - -While testing, you might want to display a server's logs: - -``` -NODE_APP_INSTANCE=1 NODE_ENV=test npm run parse-log -- --level debug | less +GF -``` - -Instance configurations are in `config/test-{1,2,3,4,5,6}.yaml`. -Note that only instance 2 has transcoding enabled. +See the [dedicated documentation](/support/doc/development/tests.md) to run tests locally. #### Testing the federation of PeerTube servers diff --git a/support/doc/development/tests.md b/support/doc/development/tests.md index fb3a05326..d0e88a5eb 100644 --- a/support/doc/development/tests.md +++ b/support/doc/development/tests.md @@ -4,19 +4,19 @@ Prepare PostgreSQL user so PeerTube can delete/create the test databases: -``` +```bash $ sudo -u postgres createuser you_username --createdb --superuser ``` Prepare databases: -``` +```bash $ npm run clean:server:test ``` Build PeerTube: -``` +```bash $ npm run build ``` @@ -26,7 +26,7 @@ $ npm run build Run docker containers needed by some test files: -``` +```bash $ sudo docker run -p 9444:9000 chocobozzz/s3-ninja $ sudo docker run -p 10389:10389 chocobozzz/docker-test-openldap ``` @@ -35,22 +35,37 @@ $ sudo docker run -p 10389:10389 chocobozzz/docker-test-openldap To run all test suites: -``` +```bash $ npm run test # See scripts/test.sh to run a particular suite ``` -To run a particular test file: +Most of tests can be runned using: -``` +```bash TS_NODE_TRANSPILE_ONLY=true mocha -- --timeout 30000 --exit -r ts-node/register -r tsconfig-paths/register --bail server/tests/api/videos/video-transcoder.ts ``` +`server/tests/api/activitypub` tests will need different options: + +``` +TS_NODE_FILES=true mocha -- --timeout 30000 --exit -r ts-node/register -r tsconfig-paths/register --bail server/tests/api/activitypub/security.ts +``` + ### Configuration Some env variables can be defined to disable/enable some tests: - * `DISABLE_HTTP_IMPORT_TESTS`: disable import tests (because of youtube that could rate limit your IP) - * `ENABLE_OBJECT_STORAGE_TESTS=true`: enable object storage tests (needs a docker container first) + * `DISABLE_HTTP_IMPORT_TESTS=true`: disable import tests (because of youtube that could rate limit your IP) + * `ENABLE_OBJECT_STORAGE_TESTS=true`: enable object storage tests (needs `chocobozzz/s3-ninja` container first) + + +### Debug server logs + +While testing, you might want to display a server's logs to understand why they failed: + +```bash +NODE_APP_INSTANCE=1 NODE_ENV=test npm run parse-log -- --level debug | less +GF +``` ## Client E2E tests @@ -59,7 +74,7 @@ Some env variables can be defined to disable/enable some tests: To run tests on local web browsers (comment web browsers you don't have in `client/e2e/wdio.local.conf.ts`): -``` +```bash $ npm run e2e:local ``` @@ -67,7 +82,7 @@ $ npm run e2e:local To run tests on browser stack: -``` +```bash $ BROWSERSTACK_USER=your_user BROWSERSTACK_KEY=your_key npm run e2e:browserstack ``` @@ -75,13 +90,13 @@ $ BROWSERSTACK_USER=your_user BROWSERSTACK_KEY=your_key npm run e2e:browserstack To add E2E tests and quickly run tests using a local Chrome, first create a test instance: -``` +```bash $ npm run clean:server:test && NODE_APP_INSTANCE=1 NODE_ENV=test npm start ``` Then, just run your suite using: -``` +```bash $ cd client/e2e $ ../node_modules/.bin/wdio wdio.local-test.conf.ts # you can also add --mochaOpts.grep to only run tests you want ```