-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
105 lines (92 loc) · 2.47 KB
/
index.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
var _ = require('underscore')
var newman = require('newman')
var uuid = require('uuid')
var util = require('./lib/util.js')
var testModuleChildren
var collectionId = uuid.v4()
var requests = []
var folders = []
var folderOrder = []
var foldersOrder = []
var folderId
var defaultNewmanOptions = {
responseHandler: 'TestResponseHandler',
stopOnError: false,
summary: true,
timeout: 24 * 60 * 60 * 1000
}
function createRequest (testModule) {
try {
folderId = uuid.v4()
folderOrder = []
testModule.run()
foldersOrder.push(folderId)
folders.push(util.deepCopy({
id: folderId,
name: util.getModuleFilename(testModule, testModuleChildren),
order: util.deepCopy(folderOrder)
}))
} catch(err) {
if (testModuleChildren !== undefined) {
console.log('Exception thrown for module: ' + util.getModulePath(testModule, testModuleChildren))
} else {
console.log('Exception thrown for a module. Call `jetman.setModuleObject(module)` before the tests to find the faulty module.')
}
throw (err)
}
}
exports.setModuleObject = function (module) {
testModuleChildren = module.children
}
exports.send = function (request, testFunction) {
var requestId = uuid.v4()
folderOrder.push(requestId)
request['id'] = requestId
if (request['name'] === undefined) {
request['name'] = ''
}
if (request['headers'] === undefined) {
request['headers'] = ''
}
if (testFunction === undefined) {
request['tests'] = ''
} else {
request['tests'] = util.functionBody(testFunction)
}
requests.push(util.deepCopy(request))
}
exports.createCollection = function (testModules, name) {
if (name === undefined) {
name = 'Jetman Collection'
}
requests = []
_.each(testModules, createRequest)
if (testModuleChildren === undefined) {
return {
'id': collectionId,
'name': name,
'order': [],
'foldersOrder': foldersOrder,
'requests': requests
}
} else {
return {
'id': collectionId,
'name': name,
'order': [],
'foldersOrder': foldersOrder,
'folders': folders,
'requests': requests
}
}
}
exports.execute = function (testModules, newmanOptions, callback) {
var pjson = require('./package.json')
console.log('Jetman version ' + pjson.version)
var collection = this.createCollection(testModules)
var options = _.extend({collection: collection, reporters: 'cli'}, defaultNewmanOptions, newmanOptions)
newman.run(
options,
callback
)
}