diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-02 10:13:53 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-02 10:13:53 +0100 |
commit | 9883e60f307c8161ef694b8fc209b857b196add0 (patch) | |
tree | a2f81ace111b33cdfa5aa37e9f997ef38fe0f9bb | |
parent | f1c861727c1d2f9eacf98821c81f0f8cdcb57317 (diff) | |
download | PeerTube-9883e60f307c8161ef694b8fc209b857b196add0.tar.gz PeerTube-9883e60f307c8161ef694b8fc209b857b196add0.tar.zst PeerTube-9883e60f307c8161ef694b8fc209b857b196add0.zip |
Improve tests documentation
-rw-r--r-- | .github/CONTRIBUTING.md | 37 | ||||
-rw-r--r-- | support/doc/development/tests.md | 41 |
2 files changed, 31 insertions, 47 deletions
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 | |||
175 | 175 | ||
176 | ### Testing | 176 | ### Testing |
177 | 177 | ||
178 | #### Unit/integration tests | ||
179 | |||
178 | Your code contributions must pass the tests before they can be merged. Tests ensure most of the application behaves | 180 | Your code contributions must pass the tests before they can be merged. Tests ensure most of the application behaves |
179 | 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. | 181 | 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. |
180 | 182 | ||
181 | PeerTube mainly features backend and plugin tests, found in `server/tests`. | 183 | See the [dedicated documentation](/support/doc/development/tests.md) to run tests locally. |
182 | |||
183 | #### Unit tests | ||
184 | |||
185 | Create a PostgreSQL user **with the same name as your username** in order to avoid using the *postgres* user. | ||
186 | |||
187 | Then, we can create the databases (if they don't already exist): | ||
188 | |||
189 | ``` | ||
190 | $ sudo -u postgres createuser you_username --createdb --superuser | ||
191 | $ npm run clean:server:test | ||
192 | ``` | ||
193 | |||
194 | Build the application and run the unit/integration tests: | ||
195 | |||
196 | ``` | ||
197 | $ npm run build -- --light | ||
198 | $ npm test | ||
199 | ``` | ||
200 | |||
201 | If you just want to run 1 test (which is what you want to debug a specific test rapidly): | ||
202 | |||
203 | ``` | ||
204 | $ TS_NODE_FILES=true npm run mocha -- --exit -r ts-node/register -r tsconfig-paths/register --bail server/tests/api/videos/single-server.ts | ||
205 | ``` | ||
206 | |||
207 | While testing, you might want to display a server's logs: | ||
208 | |||
209 | ``` | ||
210 | NODE_APP_INSTANCE=1 NODE_ENV=test npm run parse-log -- --level debug | less +GF | ||
211 | ``` | ||
212 | |||
213 | Instance configurations are in `config/test-{1,2,3,4,5,6}.yaml`. | ||
214 | Note that only instance 2 has transcoding enabled. | ||
215 | 184 | ||
216 | #### Testing the federation of PeerTube servers | 185 | #### Testing the federation of PeerTube servers |
217 | 186 | ||
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 @@ | |||
4 | 4 | ||
5 | Prepare PostgreSQL user so PeerTube can delete/create the test databases: | 5 | Prepare PostgreSQL user so PeerTube can delete/create the test databases: |
6 | 6 | ||
7 | ``` | 7 | ```bash |
8 | $ sudo -u postgres createuser you_username --createdb --superuser | 8 | $ sudo -u postgres createuser you_username --createdb --superuser |
9 | ``` | 9 | ``` |
10 | 10 | ||
11 | Prepare databases: | 11 | Prepare databases: |
12 | 12 | ||
13 | ``` | 13 | ```bash |
14 | $ npm run clean:server:test | 14 | $ npm run clean:server:test |
15 | ``` | 15 | ``` |
16 | 16 | ||
17 | Build PeerTube: | 17 | Build PeerTube: |
18 | 18 | ||
19 | ``` | 19 | ```bash |
20 | $ npm run build | 20 | $ npm run build |
21 | ``` | 21 | ``` |
22 | 22 | ||
@@ -26,7 +26,7 @@ $ npm run build | |||
26 | 26 | ||
27 | Run docker containers needed by some test files: | 27 | Run docker containers needed by some test files: |
28 | 28 | ||
29 | ``` | 29 | ```bash |
30 | $ sudo docker run -p 9444:9000 chocobozzz/s3-ninja | 30 | $ sudo docker run -p 9444:9000 chocobozzz/s3-ninja |
31 | $ sudo docker run -p 10389:10389 chocobozzz/docker-test-openldap | 31 | $ sudo docker run -p 10389:10389 chocobozzz/docker-test-openldap |
32 | ``` | 32 | ``` |
@@ -35,22 +35,37 @@ $ sudo docker run -p 10389:10389 chocobozzz/docker-test-openldap | |||
35 | 35 | ||
36 | To run all test suites: | 36 | To run all test suites: |
37 | 37 | ||
38 | ``` | 38 | ```bash |
39 | $ npm run test # See scripts/test.sh to run a particular suite | 39 | $ npm run test # See scripts/test.sh to run a particular suite |
40 | ``` | 40 | ``` |
41 | 41 | ||
42 | To run a particular test file: | 42 | Most of tests can be runned using: |
43 | 43 | ||
44 | ``` | 44 | ```bash |
45 | 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 | 45 | 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 |
46 | ``` | 46 | ``` |
47 | 47 | ||
48 | `server/tests/api/activitypub` tests will need different options: | ||
49 | |||
50 | ``` | ||
51 | TS_NODE_FILES=true mocha -- --timeout 30000 --exit -r ts-node/register -r tsconfig-paths/register --bail server/tests/api/activitypub/security.ts | ||
52 | ``` | ||
53 | |||
48 | ### Configuration | 54 | ### Configuration |
49 | 55 | ||
50 | Some env variables can be defined to disable/enable some tests: | 56 | Some env variables can be defined to disable/enable some tests: |
51 | 57 | ||
52 | * `DISABLE_HTTP_IMPORT_TESTS`: disable import tests (because of youtube that could rate limit your IP) | 58 | * `DISABLE_HTTP_IMPORT_TESTS=true`: disable import tests (because of youtube that could rate limit your IP) |
53 | * `ENABLE_OBJECT_STORAGE_TESTS=true`: enable object storage tests (needs a docker container first) | 59 | * `ENABLE_OBJECT_STORAGE_TESTS=true`: enable object storage tests (needs `chocobozzz/s3-ninja` container first) |
60 | |||
61 | |||
62 | ### Debug server logs | ||
63 | |||
64 | While testing, you might want to display a server's logs to understand why they failed: | ||
65 | |||
66 | ```bash | ||
67 | NODE_APP_INSTANCE=1 NODE_ENV=test npm run parse-log -- --level debug | less +GF | ||
68 | ``` | ||
54 | 69 | ||
55 | 70 | ||
56 | ## Client E2E tests | 71 | ## Client E2E tests |
@@ -59,7 +74,7 @@ Some env variables can be defined to disable/enable some tests: | |||
59 | 74 | ||
60 | To run tests on local web browsers (comment web browsers you don't have in `client/e2e/wdio.local.conf.ts`): | 75 | To run tests on local web browsers (comment web browsers you don't have in `client/e2e/wdio.local.conf.ts`): |
61 | 76 | ||
62 | ``` | 77 | ```bash |
63 | $ npm run e2e:local | 78 | $ npm run e2e:local |
64 | ``` | 79 | ``` |
65 | 80 | ||
@@ -67,7 +82,7 @@ $ npm run e2e:local | |||
67 | 82 | ||
68 | To run tests on browser stack: | 83 | To run tests on browser stack: |
69 | 84 | ||
70 | ``` | 85 | ```bash |
71 | $ BROWSERSTACK_USER=your_user BROWSERSTACK_KEY=your_key npm run e2e:browserstack | 86 | $ BROWSERSTACK_USER=your_user BROWSERSTACK_KEY=your_key npm run e2e:browserstack |
72 | ``` | 87 | ``` |
73 | 88 | ||
@@ -75,13 +90,13 @@ $ BROWSERSTACK_USER=your_user BROWSERSTACK_KEY=your_key npm run e2e:browserstack | |||
75 | 90 | ||
76 | To add E2E tests and quickly run tests using a local Chrome, first create a test instance: | 91 | To add E2E tests and quickly run tests using a local Chrome, first create a test instance: |
77 | 92 | ||
78 | ``` | 93 | ```bash |
79 | $ npm run clean:server:test && NODE_APP_INSTANCE=1 NODE_ENV=test npm start | 94 | $ npm run clean:server:test && NODE_APP_INSTANCE=1 NODE_ENV=test npm start |
80 | ``` | 95 | ``` |
81 | 96 | ||
82 | Then, just run your suite using: | 97 | Then, just run your suite using: |
83 | 98 | ||
84 | ``` | 99 | ```bash |
85 | $ cd client/e2e | 100 | $ cd client/e2e |
86 | $ ../node_modules/.bin/wdio wdio.local-test.conf.ts # you can also add --mochaOpts.grep to only run tests you want | 101 | $ ../node_modules/.bin/wdio wdio.local-test.conf.ts # you can also add --mochaOpts.grep to only run tests you want |
87 | ``` | 102 | ``` |