Преглед на файлове

:sparkles: added testing via ava with coverage via nyc

master
TOJ преди 5 години
родител
ревизия
87d1f40ad9
променени са 9 файла, в които са добавени 5883 реда и са изтрити 122 реда
  1. 2
    1
      .gitignore
  2. 6
    0
      backend/.nycrc
  3. 2
    2
      backend/lib/index.js
  4. 10
    0
      backend/lib/plugins/example.js
  5. 0
    20
      backend/lib/plugins/test.js
  6. 13
    0
      backend/lib/routes/example/base.js
  7. 5827
    97
      backend/package-lock.json
  8. 4
    2
      backend/package.json
  9. 19
    0
      backend/tests/example.test.js

+ 2
- 1
.gitignore Целия файл

@@ -3,4 +3,5 @@ node_modules
3 3
 dist
4 4
 dist-ssr
5 5
 *.local
6
-**/.env
6
+**/.env
7
+.nyc_output

+ 6
- 0
backend/.nycrc Целия файл

@@ -0,0 +1,6 @@
1
+{
2
+    "all":true,
3
+    "include": [
4
+        "lib/**/*.js"
5
+    ]
6
+}

+ 2
- 2
backend/lib/index.js Целия файл

@@ -1,13 +1,13 @@
1 1
 const UserPlugin = require('./plugins/user');
2 2
 const MembershipPlugin = require('./plugins/membership');
3
-const TestPlugin = require('./plugins/test');
3
+const TestPlugin = require('./plugins/example');
4 4
 
5 5
 exports.plugin = {
6 6
     name: 'main-app-plugin',
7 7
     register: async (server, options) => {
8 8
 
9 9
         await server.register(TestPlugin, {
10
-            routes: { prefix: `/test` }
10
+            routes: { prefix: `/example` }
11 11
         })
12 12
 
13 13
         await server.register(UserPlugin, {

+ 10
- 0
backend/lib/plugins/example.js Целия файл

@@ -0,0 +1,10 @@
1
+const example = require('../routes/example/base')
2
+
3
+module.exports = {
4
+    name: 'myPlugin',
5
+    version: '1.0.0',
6
+    register: async (server, options) => {
7
+        // Create a route for example
8
+        server.route(example)
9
+    }
10
+}

+ 0
- 20
backend/lib/plugins/test.js Целия файл

@@ -1,20 +0,0 @@
1
-module.exports = {
2
-    name: 'myPlugin',
3
-    version: '1.0.0',
4
-    register: async (server, options) => {
5
-        // Create a route for example
6
-        server.route({
7
-            method: 'GET',
8
-            path: '/test',
9
-            handler: async function (request, h) {
10
-                return { test: 'hello, world' }
11
-            },
12
-            options: {
13
-                description: 'Test',
14
-                notes: 'This is a test route',
15
-                tags: ['api'],
16
-                auth: false
17
-            }
18
-        })
19
-    }
20
-}

+ 13
- 0
backend/lib/routes/example/base.js Целия файл

@@ -0,0 +1,13 @@
1
+module.exports = {
2
+    method: 'GET',
3
+    path: '/',
4
+    handler: async function (request, h) {
5
+        return { test: 'hello, world' }
6
+    },
7
+    options: {
8
+        description: 'Test',
9
+        notes: 'This is an example route',
10
+        tags: ['api'],
11
+        auth: false
12
+    }
13
+}

+ 5827
- 97
backend/package-lock.json
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 4
- 2
backend/package.json Целия файл

@@ -8,7 +8,7 @@
8 8
     "migrate": "knex migrate:latest",
9 9
     "unmigrate": "knex migrate:down",
10 10
     "seed": "knex seed:run",
11
-    "test": "echo \"Error: no test specified\" && exit 1"
11
+    "test": "nyc ava"
12 12
   },
13 13
   "author": "TOJ",
14 14
   "license": "UNLICENSED",
@@ -31,6 +31,8 @@
31 31
     "secure-password": "^4.0.0"
32 32
   },
33 33
   "devDependencies": {
34
-    "nodemon": "^2.0.7"
34
+    "ava": "^3.15.0",
35
+    "nodemon": "^2.0.7",
36
+    "nyc": "^15.1.0"
35 37
   }
36 38
 }

+ 19
- 0
backend/tests/example.test.js Целия файл

@@ -0,0 +1,19 @@
1
+'use strict'
2
+
3
+const test = require('ava')
4
+const Hapi = require('@hapi/hapi')
5
+
6
+const routeBase = '../lib/routes'
7
+
8
+const route = require(routeBase + '/example/base')
9
+
10
+test('path / should return ok on GET', async t => {
11
+  const server = Hapi.server()
12
+
13
+  server.route(route)
14
+
15
+  const { statusCode, payload } = await server.inject(route.path)
16
+
17
+  t.is(payload, '{"test":"hello, world"}')
18
+  t.is(statusCode, 200)
19
+})

Loading…
Отказ
Запис