PeerTube/support/doc/development/tests.md

130 lines
3.2 KiB
Markdown
Raw Normal View History

2021-09-02 08:57:59 +02:00
# Tests
## Preparation
Prepare PostgreSQL user so PeerTube can delete/create the test databases:
2021-11-02 10:13:53 +01:00
```bash
sudo -u postgres createuser you_username --createdb --superuser
2021-09-02 08:57:59 +02:00
```
Prepare the databases:
2021-09-02 08:57:59 +02:00
2021-11-02 10:13:53 +01:00
```bash
npm run clean:server:test
2021-09-02 08:57:59 +02:00
```
Build PeerTube:
2021-11-02 10:13:53 +01:00
```bash
npm run build
2021-09-02 08:57:59 +02:00
```
## Server tests
### Dependencies
Run docker containers needed by some test files:
2021-11-02 10:13:53 +01:00
```bash
sudo docker run -p 9444:9000 chocobozzz/s3-ninja
sudo docker run -p 10389:10389 chocobozzz/docker-test-openldap
2021-09-02 08:57:59 +02:00
```
Ensure you also have these commands:
```bash
exiftool --help
parallel --help
2024-06-13 09:23:12 +02:00
# For transcription tests
whisper --help
whisper-ctranslate2 --help
jiwer --help
```
Otherwise, install the packages. On Debian-based systems (like Debian, Ubuntu or Mint):
```bash
sudo apt-get install parallel libimage-exiftool-perl
2024-06-13 09:23:12 +02:00
sudo pip install -r packages/tests/requirements.txt -r packages/transcription-devtools/requirements.txt
```
2021-09-02 08:57:59 +02:00
### Test
To run all test suites (can be long!):
2021-09-02 08:57:59 +02:00
2021-11-02 10:13:53 +01:00
```bash
npm run test # See scripts/test.sh to run a particular suite
2021-09-02 08:57:59 +02:00
```
To run a specific test:
2021-09-02 08:57:59 +02:00
2021-11-02 10:13:53 +01:00
```bash
npm run mocha -- --exit --bail packages/tests/src/your-test.ts
2021-11-02 10:13:53 +01:00
# For example
npm run mocha -- --exit --bail packages/tests/src/api/videos/single-server.ts
2021-11-02 10:13:53 +01:00
```
2021-09-02 08:57:59 +02:00
### Configuration
Some env variables can be defined to disable/enable some tests:
2021-11-02 10:13:53 +01:00
* `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)
2023-05-26 09:52:50 +02:00
* `AKISMET_KEY`: specify an Akismet key to test akismet external PeerTube plugin
* `OBJECT_STORAGE_SCALEWAY_KEY_ID` and `OBJECT_STORAGE_SCALEWAY_ACCESS_KEY`: specify Scaleway API keys to test object storage ACL (not supported by our `chocobozzz/s3-ninja` container)
2023-06-06 11:14:13 +02:00
* `ENABLE_FFMPEG_THUMBNAIL_PIXEL_COMPARISON_TESTS=true`: enable pixel comparison on images generated by ffmpeg. Disabled by default because a custom ffmpeg version may fails the tests
* `YOUTUBE_DL_DOWNLOAD_BEARER_TOKEN`: Bearer token to download youtube-dl binary
* `YOUTUBE_DL_PROXY`: Custom proxy URL for youtube-dl HTTP video import
2021-11-02 10:13:53 +01:00
### 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
```
2021-09-02 08:57:59 +02:00
You can also:
- checkout only the latest logs (PeerTube >= 5.0):
```bash
tail -n 100 test1/logs/peertube.log | npm run parse-log -- --level debug --files -
```
- continuously print the latests logs (PeerTube >= 5.0):
```bash
tail -f test1/logs/peertube.log | npm run parse-log -- --level debug --files -
```
2021-09-02 08:57:59 +02:00
## Client E2E tests
### Local tests
To run tests on local web browsers (comment web browsers you don't have in `client/e2e/wdio.local.conf.ts`):
2021-11-02 10:13:53 +01:00
```bash
PEERTUBE2_E2E_PASSWORD=password npm run e2e:local
2021-09-02 08:57:59 +02:00
```
### Browserstack tests
To run tests on browser stack:
2021-11-02 10:13:53 +01:00
```bash
BROWSERSTACK_USER=your_user BROWSERSTACK_KEY=your_key npm run e2e:browserstack
2021-09-02 08:57:59 +02:00
```
2021-09-03 10:27:04 +02:00
### Add E2E tests
To add E2E tests and quickly run tests using a local Chrome:
2021-09-03 10:27:04 +02:00
2021-11-02 10:13:53 +01:00
```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
2021-09-03 10:27:04 +02:00
```