-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.test.js
108 lines (89 loc) · 2.5 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict';
const test = require('ava')
, app = require('./index')
, http = require('http')
, servers = []
, events = require('harken')
, configStore = require('./utils/config');
test.beforeEach(() => {
configStore.reset();
});
test.afterEach(() => {
const shutDownEvents = events.required([ 'complete' ], () => {
// t.end();
});
servers.forEach((server, i) => {
shutDownEvents.add(`server:${i}`);
server.close(() => {
events.emit(`server:${i}`);
});
});
events.emit('complete');
});
test('should be correctly defined', (t) => {
t.is(typeof app.server, 'function');
t.is(typeof app.parser, 'function');
t.is(typeof app.routes, 'object');
t.is(typeof app.events, 'object');
});
test('should have a parser method', (t) => {
t.is(typeof app.parser, 'function');
});
test.cb('should return a server when run', (t) => {
app.server({
routeJSONPath: './test_stubs/routes_stub.json'
, routePath: './test_stubs'
, port: 9999
, log: {
log: () => {}
}
});
app.events.once('server:started', (settings) => {
servers.push(settings.server);
t.true(settings.server instanceof http.Server);
t.end();
});
});
test.cb('should return a server when run and no port passed in', (t) => {
const noPortApp = require('./index');
noPortApp.server({
routeJSONPath: './test_stubs/routes_stub.json'
, routePath: './test_stubs'
, port: 9998
, log: {
log: () => {}
}
});
noPortApp.events.once('server:started', (settings) => {
servers.push(settings.server);
t.true(settings.server instanceof http.Server);
t.end();
});
});
test.cb('should return a server when run and compress passed in', (t) => {
const compressApp = require('./index');
compressApp.server({
routeJSONPath: './test_stubs/routes_stub.json'
, compress: false
, routePath: './test_stubs'
, port: 9997
, log: {
log: () => {}
}
});
compressApp.events.once('server:started', (settings) => {
servers.push(settings.server);
t.true(settings.server instanceof http.Server);
t.end();
});
});
test('should have a createUUID function', (t) => {
t.is(typeof app.createUUID, 'function');
});
test('should return a uuid when called', (t) => {
const regex = /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i;
t.true(regex.test(app.createUUID()));
});
test('should not return the same uuid when called multiple times', (t) => {
t.not(app.createUUID(), app.createUUID());
});