Repository navigation
Expand file tree
/
Copy pathsuite.js
More file actions
56 lines (51 loc) · 1.51 KB
/
Copy pathsuite.js
File metadata and controls
56 lines (51 loc) · 1.51 KB
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
/**
* Module dependencies
*/
var should = require('should');
var conf = global['hypertest-' + __filename];
var hyperagent = require('hyperagent')(conf.host);
if (conf.headers) hyperagent.set(conf.headers);
describe(conf.host, function() {
conf.tests.forEach(function(test) {
describe(test.path, function() {
before(function(done) {
var self = this;
hyperagent(test.path, function(err, value, res) {
if (err) return done(err);
self.val = value;
self.res = res;
done();
});
});
test.assertions.forEach(function(assert) {
it(assert.name, function(done) {
var aliases = {
val: this.val,
value: this.val,
res: this.res,
path: test.path,
key: test.path,
should: should,
hyperagent: hyperagent,
hyper: hyperagent,
done: done,
fn: done,
cb: done,
require: require
};
var args = getArgs(assert.fn);
var vals = args.map(function(arg) {
if (!~['val', 'value'].indexOf(arg) && typeof aliases[arg] === 'undefined') throw new Error('invalid argument ' + arg);
return aliases[arg];
});
assert.fn.apply(this, vals);
if (!~args.indexOf('done')) done();
});
});
});
});
});
function getArgs(fn) {
var str = fn.toString();
return str.slice(str.indexOf('(') + 1, str.indexOf(')')).match(/([^\s,]+)/g);
}