updated test instructions

Massimo Melina committed May 22, 2022 at 07:44 UTC 648e6e8d6384ff86951ce47dabb048ab7949d948
3 files changed +21 -4
dev-plugins.md
+10 -2
@@ -32,8 +32,16 @@ All the following properties are essentially optional.
32 - `apiRequired: number | [min:number,max:number]` declare version(s) for which the plugin is designed for. You'll find api version in `src/const.ts`. This must go in `exports`.
33 - `frontend_css: string | string[]` path to one or more css files that you want the frontend to load. These are to be placed in the `public` folder (refer below).
34 - `frontend_js: string | string[]` path to one or more js files that you want the frontend to load. These are to be placed in the `public` folder (refer below).
35 -- `middleware: (Context) => void | true | function` a function that will be used as a middleware: it can interfere with http activity.
36 -
35 +- `middleware: (Context) => void | true | function` a function that will be used as a middleware: use this to interfere with http activity.
36 +
37 + ```js
38 + exports.middleware = ctx => {
39 + ctx.body = "You are in the wrong place"
40 + ctx.status = 404
41 + }
42 + ```
43 + You'll find more examples by studying plugins like `vhosting` or `antibrute`.
44 + This API is based on [Koa](https://koajs.com), because that's what HFS is using.
45 To know what the Context object contains please refer to [Koa's documentation](https://github.com/koajs/koa/blob/master/docs/api/context.md).
46 You don't get the `next` parameter as in standard Koa's middlewares because this is different, but we are now explaining how to achieve the same results.
47 To interrupt other middlewares on this http request, return `true`.
dev.md
+9
@@ -28,6 +28,15 @@ Having this env-s will make the server get all related stuff from the other dev
28 Otherwise, you should be sure that frontend and admin have been built, and its files are ready to be used in `dist` folder.
29 In this latter case, the `DEV=1` you set before will make the server get the files from inside the `dist` folder.
30
31 +## Tests
32 +
33 +To run tests
34 +- `npm run build-all`
35 +- `npm run server-for-test`
36 +- in another shell `npm test`
37 +
38 +Alternatively you can run a development server, just be sure to load config from `tests` folder.
39 +
40 ## File formats
41
42 General configuration is read by default from file `config.yaml`.
package.json
+2 -2
@@ -11,16 +11,16 @@
11 "author": "Massimo Melina <a@rejetto.com>",
12 "workspaces": [ "server", "admin", "frontend", "shared" ],
13 "scripts": {
14 - "watch-server": "nodemon --ignore server/tests/ --watch server/src -e ts,tsx --exec ts-node server/src/index.ts",
14 + "watch-server": "nodemon --ignore tests/ --watch server/src -e ts,tsx --exec ts-node server/src/index.ts",
15 "watch-shared": "cd shared && tsc --watch",
16 "start-frontend": "cd frontend && npm run start",
17 "start-admin": "cd admin && npm run start",
18 - "start": "node dist",
18 "build-all": "npm audit --omit=dev && rm -rf dist && npm install && npm run build-shared && npm run build-server && npm run build-frontend && npm run build-admin && echo COMPLETED",
19 "build-server": "rm -rf dist/src dist/plugins && tsc --target es2018 && cp -v -r package-lock.json server/package.json READ* LICENSE* plugins dist && cd dist && npm ci --production && cd .. && node afterbuild",
20 "build-frontend": "cd frontend && npm run build",
21 "build-admin": "cd admin && npm run build",
22 "build-shared": "cd shared && npx tsc",
23 + "server-for-test": "cross-env HFS_CONFIG=tests node dist/src",
24 "test": "mocha -r ts-node/register 'tests/**/*.ts'",
25 "dist-node": "cd dist && zip hfs-node.zip -r * -x *.zip *.exe hfs-*",
26 "dist-bin": "pkg . -C gzip && cd dist && mv -f hfs-win.exe hfs.exe && zip hfs-windows.zip hfs.exe -r plugins && cp -f hfs-linux hfs && zip hfs-linux.zip hfs -r plugins && cp -f hfs-macos hfs && zip hfs-macos.zip hfs -r plugins && rm hfs",