Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hello World Unit Test
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Node.js v0.10.26 Core Modules" level="application" />
<orderEntry type="library" name="should-DefinitelyTyped" level="application" />
<orderEntry type="library" name="mocha-DefinitelyTyped" level="application" />
<orderEntry type="library" name="node-DefinitelyTyped" level="application" />
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="PROJECT" libraries="{Node.js v0.10.26 Core Modules, mocha-DefinitelyTyped, node-DefinitelyTyped, should-DefinitelyTyped}" />
<includedPredefinedLibrary name="Node.js Globals" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/HelloWorld_UnitTest.iml" filepath="$PROJECT_DIR$/.idea/HelloWorld_UnitTest.iml" />
</modules>
</component>
</project>
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>
var http = require('http');
var server = http.createServer(function (req, res) {
console.log('Received request');
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('Hello World!\n');
res.end()
});
var listen = function (port) {
server.listen(port, function() {
console.log('Listening on port: ' + port);
});
};
var close = function () {
server.close(function(){
console.log('Closing connection!');
});
};
module.exports.listen = listen;
module.exports.close = close;
var server = require('../src/server.js');
var http = require('http');
var assert = require('assert');
before(function () {
server.listen(8888);
});
after(function () {
server.close();
});
it('should return 200', function (done) {
http.get('http://localhost:8888', function (res) {
assert.equal(res.statusCode, '200');
done();
});
});
it('should say Hello World\n', function (done) {
http.get('http://localhost:8888', function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
assert.equal(data, "Hello World!\n");
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment