Skip to content

Commit 5a05b5e

Browse files
committed
refactor socket tests to use super test
1 parent 8332f4f commit 5a05b5e

File tree

3 files changed

+59
-31
lines changed

3 files changed

+59
-31
lines changed

package-lock.json

+47-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"mocha": "^5.2.0",
7777
"mocha-sinon": "^2.0.0",
7878
"nyc": "^12.0.2",
79-
"request": "^2.88.0",
8079
"rimraf": "^2.6.2",
8180
"should": "^13.2.0",
8281
"sinon": "^6.1.5",

test/Socket.test.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
'use strict';
22

33
const assert = require('assert');
4-
const request = require('request');
4+
const request = require('supertest');
55
const config = require('./fixtures/simple-config/webpack.config');
66
const helper = require('./helper');
77

8-
const requestSucceeds = done => (err, res) => {
9-
if (err) {
10-
done(err);
11-
}
12-
13-
assert.equal(res.statusCode, 200);
14-
done();
15-
};
16-
178
describe('socket options', () => {
189
let server;
10+
let req;
1911

20-
afterEach(helper.close);
12+
afterEach((done) => {
13+
helper.close(done)
14+
req = null;
15+
server = null;
16+
});
2117
describe('default behavior', () => {
2218
beforeEach((done) => {
2319
server = helper.start(config, {}, done);
20+
req = request('http://localhost:8080');
2421
});
2522

2623
it('defaults to a path', () => {
2724
assert.ok(server.sockPath.match(/\/[a-z0-9\-/]+[^/]$/));
2825
});
2926

3027
it('responds with a 200', (done) => {
31-
request('http://localhost:8080/sockjs-node', requestSucceeds(done));
28+
req.get('/sockjs-node').expect(200, done);
3229
});
3330
});
3431

@@ -38,14 +35,16 @@ describe('socket options', () => {
3835
server = helper.start(config, {
3936
sockPath: '/foo/test/bar/'
4037
}, done);
38+
req = request('http://localhost:8080');
4139
});
4240

4341
it('sets the sock path correctly and strips leading and trailing /s', () => {
4442
assert.equal(server.sockPath, path);
4543
});
4644

45+
4746
it('responds with a 200 second', (done) => {
48-
request(`http://localhost:8080${path}`, requestSucceeds(done));
47+
req.get(path).expect(200, done);
4948
});
5049
});
5150
});

0 commit comments

Comments
 (0)