[Test] Express backend

This commit is contained in:
Zalmoxisus 2017-01-02 14:42:44 +02:00
parent bcc1d15b84
commit 46a61dc45e
2 changed files with 52 additions and 2 deletions

View File

@ -13,6 +13,11 @@
"index.js", "index.js",
"defaultDbOptions.json" "defaultDbOptions.json"
], ],
"scripts": {
"test": "NODE_ENV=test mocha --recursive",
"test:watch": "NODE_ENV=test mocha --recursive --watch",
"prepublish": "npm run test"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/zalmoxisus/remotedev-server.git" "url": "https://github.com/zalmoxisus/remotedev-server.git"
@ -49,5 +54,10 @@
"semver": "^5.3.0", "semver": "^5.3.0",
"socketcluster": "^5.0.4", "socketcluster": "^5.0.4",
"sqlite3": "^3.1.8" "sqlite3": "^3.1.8"
},
"devDependencies": {
"expect": "^1.20.2",
"mocha": "^3.2.0",
"supertest": "^2.0.1"
} }
} }

40
test/socket.spec.js Normal file
View File

@ -0,0 +1,40 @@
var childProcess = require('child_process');
var request = require('supertest');
var expect = require('expect');
var scClient = require('socketcluster-client');
var remotedev = require('../');
describe('Server', function() {
var scServer;
this.timeout(5000);
before(function(done) {
scServer = childProcess.fork(__dirname + '/../bin/remotedev.js');
setTimeout(done, 2000);
});
after(function() {
if (scServer) {
scServer.kill();
}
});
describe('Express backend', function() {
it('loads main page', function(done) {
request('http://localhost:8000')
.get('/')
.expect('Content-Type', /text\/html/)
.expect(200)
.expect(function(res) {
expect(res.text).toMatch(/<title>RemoteDev<\/title>/);
})
.end(done);
});
it('resolves an inexistent url', function(done) {
request('http://localhost:8000/jreerfr/123')
.get('/')
.expect('Content-Type', /text\/html/)
.expect(200, done);
});
});
});