Skip to content

Commit

Permalink
refactor socket tests to use super test
Browse files Browse the repository at this point in the history
  • Loading branch information
trescenzi committed Dec 5, 2018
1 parent 8332f4f commit 5a05b5e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 31 deletions.
64 changes: 47 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"mocha": "^5.2.0",
"mocha-sinon": "^2.0.0",
"nyc": "^12.0.2",
"request": "^2.88.0",
"rimraf": "^2.6.2",
"should": "^13.2.0",
"sinon": "^6.1.5",
Expand Down
25 changes: 12 additions & 13 deletions test/Socket.test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
'use strict';

const assert = require('assert');
const request = require('request');
const request = require('supertest');
const config = require('./fixtures/simple-config/webpack.config');
const helper = require('./helper');

const requestSucceeds = done => (err, res) => {
if (err) {
done(err);
}

assert.equal(res.statusCode, 200);
done();
};

describe('socket options', () => {
let server;
let req;

afterEach(helper.close);
afterEach((done) => {
helper.close(done)
req = null;
server = null;
});
describe('default behavior', () => {
beforeEach((done) => {
server = helper.start(config, {}, done);
req = request('http://localhost:8080');
});

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

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

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

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


it('responds with a 200 second', (done) => {
request(`http://localhost:8080${path}`, requestSucceeds(done));
req.get(path).expect(200, done);
});
});
});

0 comments on commit 5a05b5e

Please sign in to comment.