Fix contributing guide concerning unit tests
[oweals/peertube.git] / .github / CONTRIBUTING.md
1 # Welcome to the contributing guide for PeerTube
2
3 Interesting in contributing? Awesome!
4
5 **Quick Links:**
6
7   * [Give your feedback](#give-your-feedback)
8   * [Write documentation](#write-documentation)
9   * [Develop](#develop)
10
11
12 ## Give your feedback
13
14 You don't need to know how to code to start contributing to PeerTube! Other
15 contributions are very valuable too, among which: you can test the software and
16 report bugs, you can give feedback on potential bugs, features that you are
17 interested in, user interface, design, decentralized architecture...
18
19
20 ## Write documentation
21
22 You can help to write the documentation of the REST API, code, architecture,
23 demonstrations.
24
25 For the REST API you can see the documentation in [/support/doc/api](/support/doc/api) directory.
26 Then, you can just open the `openapi.yaml` file in a special editor like [http://editor.swagger.io/](http://editor.swagger.io/) to easily see and edit the documentation.
27
28 Some hints:
29  * Routes are defined in [/server/controllers/](/server/controllers/) directory
30  * Parameters validators are defined in [/server/middlewares/validators](/server/middlewares/validators) directory
31  * Models sent/received by the controllers are defined in [/shared/models](/shared/models) directory
32
33
34 ## Develop
35
36 Don't hesitate to talk about features you want to develop by creating/commenting an issue
37 before you start working on them :).
38
39 ### Prerequisites
40
41 First, make sure that you have followed 
42 [the steps](/support/doc/dependencies.md) 
43 to install the dependencies.
44
45 Then clone the sources and install node modules:
46
47 ```
48 $ git clone https://github.com/Chocobozzz/PeerTube
49 $ cd PeerTube
50 $ yarn install --pure-lockfile
51 ```
52
53 Then, create a postgres database and user with the values set in the
54 `config/default.yaml` file. For instance, if you do not change the values
55 there, the following commands would create a new database called `peertube_dev`
56 and a postgres user called `peertube` with password `peertube`:
57
58 ```
59 # sudo -u postgres createuser -P peertube
60 Enter password for new role: peertube
61 # sudo -u postgres createdb -O peertube peertube_dev
62 ```
63
64 In dev mode, administrator username is **root** and password is **test**.
65
66 ### Server side
67
68 You can find a documentation of the server code/architecture [here](/support/doc/development/server/code.md).
69
70 To develop on the server-side:
71
72 ```
73 $ npm run dev:server
74 ```
75
76 Then, the server will listen on `localhost:9000`. When server source files
77 change, these are automatically recompiled and the server will automatically
78 restart.
79
80 ### Client side
81
82 You can find a documentation of the server code/architecture
83 [here](/support/doc/development/client/code.md).
84
85
86 To develop on the client side:
87
88 ```
89 $ npm run dev:client
90 ```
91
92 The API will listen on `localhost:9000` and the frontend on `localhost:3000`.
93 Client files are automatically compiled on change, and the web browser will
94 reload them automatically thanks to hot module replacement.
95
96 ### Client and server side
97
98 The API will listen on `localhost:9000` and the frontend on `localhost:3000`.
99 File changes are automatically recompiled, injected in the web browser (no need to refresh manually)
100 and the web server is automatically restarted.
101
102 ```
103 $ npm run dev
104 ```
105
106 ### Federation
107
108 Create a PostgreSQL user **with the same name as your username** in order to avoid using the *postgres* user.
109 Then, we can create the databases (if they don't already exist):
110
111 ```
112 $ sudo -u postgres createuser you_username --createdb
113 $ createdb -O peertube peertube_test{1,2,3}
114 ```
115
116 Build the application and flush the old tests data:
117
118 ```
119 $ npm run build
120 $ npm run clean:server:test
121 ```
122
123 This will run 3 nodes:
124
125 ```
126 $ npm run play
127 ```
128
129 Then you will get access to the three nodes at `http://localhost:900{1,2,3}`
130 with the `root` as username and `test{1,2,3}` for the password.
131
132
133 ### Unit tests
134
135 Create a PostgreSQL user **with the same name as your username** in order to avoid using the *postgres* user.
136 Then, we can create the databases (if they don't already exist):
137
138 ```
139 $ sudo -u postgres createuser you_username --createdb --superuser
140 $ createdb -O peertube peertube_test{1,2,3,4,5,6}
141 ```
142
143 Build the application and run the unit/integration tests:
144
145 ```
146 $ npm run build
147 $ npm test
148 ```
149
150 If you just want to run 1 test:
151
152 ```
153 $ npm run mocha -- --exit --require ts-node/register/type-check --bail server/tests/api/index.ts
154 ```