-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest.js
More file actions
56 lines (47 loc) · 1.23 KB
/
test.js
File metadata and controls
56 lines (47 loc) · 1.23 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
// Copyright IBM Corp. 2015. All Rights Reserved.
// Node module: express-example-app
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var app = require('./')();
var format = require('url').format;
var request = require('request');
var tap = require('tap');
var server;
function url(path) {
return format({
protocol: 'http',
hostname: 'localhost',
port: server.address().port,
pathname: path,
});
}
tap.test('start', function(t) {
t.plan(1);
server = app.listen(0, function() {
t.assert(server, 'listening');
});
});
tap.test('test /', function(t) {
t.plan(2);
request(url(), function(err, rsp, body) {
t.ifError(err);
t.similar(body, /Hello, World! Request served from .*:\d+/, body);
});
});
tap.test('test /api', function(t) {
request({url: url('/api'), json: true}, function(err, rsp, body) {
t.ifError(err);
t.equal(body.message, 'Hello, World!', body);
t.equal(body.pid, process.pid);
t.similar(body.address, /127.0.0.1/);
t.equal(body.port, server.address().port);
t.end();
});
});
tap.test('stop', function(t) {
t.plan(1);
server.close(function() {
t.assert(true, 'closed');
});
});