Created
July 28, 2017 14:49
-
-
Save papandreou/cef2d8e051feb7864322d416f39ad6c1 to your computer and use it in GitHub Desktop.
Spin up a test server on a random port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('my server', function () { | |
let serverUrl; | |
beforeEach(function () => { | |
const server = http.createServer((req, res) => { | |
// ... | |
}).listen(0); | |
const serverAddress = server.address(); | |
const serverHostname = serverAddress.address === '::' ? 'localhost' : serverAddress.address; | |
serverUrl = 'http://' + serverHostname + ':' + serverAddress.port + '/'; | |
}); | |
it('should foo', function () { | |
// Make request to `serverUrl` and make assertions about the response | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment