-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
248f6ef
commit 081948c
Showing
4 changed files
with
146 additions
and
126 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,68 @@ | ||
var feathers = require('feathers'); | ||
var rest = require('feathers-rest'); | ||
var bodyParser = require('body-parser'); | ||
var nocache = require('connect-nocache'); | ||
var socketio = require('feathers-socketio'); | ||
var memory = require('feathers-memory'); | ||
var debug = require('debug')('testee:server'); | ||
|
||
function nocache(req, res, next) { | ||
res.setHeader('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'); | ||
res.setHeader('Pragma', 'No-cache'); | ||
delete req.headers['if-modified-since']; | ||
delete req.headers['if-none-match']; | ||
next(); | ||
} | ||
|
||
var hosting = require('./host'); | ||
var api = exports.api = function() { | ||
debug('initializing Feathers API'); | ||
return feathers() | ||
.use(bodyParser.json()) | ||
.use(bodyParser.urlencoded({extended: true})) | ||
.use(nocache()) | ||
.configure(rest()) | ||
.configure(socketio()) | ||
.use('/runs', memory()) | ||
.use('/suites', memory()) | ||
.use('/tests', memory()) | ||
.use('/coverages', memory()) | ||
.use('/logs', memory()); | ||
var api = exports.api = function () { | ||
debug('initializing Feathers API'); | ||
return feathers() | ||
.use(nocache) | ||
.use(bodyParser.json()) | ||
.use(bodyParser.urlencoded({ extended: true })) | ||
.configure(rest()) | ||
.configure(socketio()) | ||
.use('/runs', memory()) | ||
.use('/suites', memory()) | ||
.use('/tests', memory()) | ||
.use('/coverages', memory()) | ||
.use('/logs', memory()); | ||
}; | ||
|
||
// Returns an Express application that hosts a Testee server with the given options: | ||
// `root`: The root URL or path. URLs will be proxied | ||
// `coverage`: If code coverage should be enabled and its settings | ||
exports.create = function(options) { | ||
// The Feathers API server | ||
var app = api(options); | ||
// The file hosting or proxy server | ||
// Uses the API server as a middleware on the `api/` route | ||
var host = hosting(options).use('/api', app); | ||
var oldListen = host.listen; | ||
var connectionId = 0; | ||
var connections = {}; | ||
exports.create = function (options) { | ||
// The Feathers API server | ||
var app = api(options); | ||
// The file hosting or proxy server | ||
// Uses the API server as a middleware on the `api/` route | ||
var host = hosting(options).use('/api', app); | ||
var oldListen = host.listen; | ||
var connectionId = 0; | ||
var connections = {}; | ||
|
||
host.listen = function() { | ||
var server = oldListen.apply(this, arguments); | ||
server.api = app; | ||
//Track all connections, remove them when the are closed. | ||
server.on('connection', function(conn){ | ||
var key = connectionId++; | ||
connections[key] = conn; | ||
conn.on('close', function(){ | ||
delete connections[key]; | ||
host.listen = function () { | ||
var server = oldListen.apply(this, arguments); | ||
server.api = app; | ||
//Track all connections, remove them when the are closed. | ||
server.on('connection', function (conn) { | ||
var key = connectionId++; | ||
connections[key] = conn; | ||
conn.on('close', function () { | ||
delete connections[key]; | ||
}); | ||
}); | ||
}); | ||
//Any open connection will be destroyed | ||
server.destroy = function(cb){ | ||
server.close(cb || function(){}); | ||
for(var key in connections) { | ||
connections[key].destroy(); | ||
delete connections[key]; | ||
} | ||
//Any open connection will be destroyed | ||
server.destroy = function (cb) { | ||
server.close(cb || function () { }); | ||
for (var key in connections) { | ||
connections[key].destroy(); | ||
delete connections[key]; | ||
} | ||
}; | ||
return server; | ||
}; | ||
return server; | ||
}; | ||
|
||
return host; | ||
return host; | ||
}; |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
var assert = require('assert'); | ||
var path = require('path'); | ||
var del = require('del'); | ||
var fs = require('fs'); | ||
var testee = require('../lib/testee'); | ||
|
||
var fixture = path.join(__dirname, 'coverage'); | ||
|
||
describe('Coverage', function () { | ||
var config = { | ||
root: path.join(__dirname, '..'), | ||
reporter: function () { | ||
// print nothing | ||
}, | ||
coverage: { | ||
dir: 'test/coverage/', | ||
reporters: ['html'], | ||
ignore: ['node_modules'] | ||
} | ||
}; | ||
var browser = process.env.TEST_BROWSER || 'firefox'; | ||
var browsers = [browser]; | ||
|
||
beforeEach(function () { | ||
return del([fixture]).then(function () { | ||
return new global.Promise(function (resolve, reject) { | ||
fs.mkdir(fixture, function (error) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
return del([fixture]); | ||
}); | ||
|
||
describe('QUnit example', function () { | ||
it('socketio', function () { | ||
return testee.test(['examples/qunit/index.html'], browsers, config).fail(function (error) { | ||
assert.equal(error.message, 'There were 0 general errors and 1 total test failures.'); | ||
assert.ok(fs.existsSync('test/coverage/qunit/blogpost.js.html'), 'reports coverage of blogpost.js'); | ||
assert.ok(fs.existsSync('test/coverage/qunit/test.js.html'), 'reports coverage of qunit/test.js'); | ||
}); | ||
}); | ||
|
||
it('rest', function () { | ||
return testee.test(['examples/qunit/rest.html'], browsers, config).fail(function (error) { | ||
assert.equal(error.message, 'There were 0 general errors and 1 total test failures.'); | ||
assert.ok(fs.existsSync('test/coverage/qunit/blogpost.js.html'), 'reports coverage of blogpost.js'); | ||
assert.ok(fs.existsSync('test/coverage/qunit/test.js.html'), 'reports coverage of qunit/test.js'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Jasmine example', function () { | ||
it('socketio', function () { | ||
return testee.test(['examples/jasmine/index.html'], browsers, config).fail(function (error) { | ||
assert.equal(error.message, 'There were 0 general errors and 1 total test failures.'); | ||
assert.ok(fs.existsSync('test/coverage/jasmine/blogpost.js.html'), 'reports coverage of blogpost.js'); | ||
assert.ok(fs.existsSync('test/coverage/jasmine/test.js.html'), 'reports coverage of jasmine/test.js'); | ||
}); | ||
}); | ||
|
||
it('rest', function () { | ||
return testee.test(['examples/jasmine/rest.html'], browsers, config).fail(function (error) { | ||
assert.equal(error.message, 'There were 0 general errors and 1 total test failures.'); | ||
assert.ok(fs.existsSync('test/coverage/jasmine/blogpost.js.html'), 'reports coverage of blogpost.js'); | ||
assert.ok(fs.existsSync('test/coverage/jasmine/test.js.html'), 'reports coverage of jasmine/test.js'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Mocha example', function () { | ||
it('socketio', function () { | ||
return testee.test(['examples/mocha/index.html'], browsers, config).fail(function (error) { | ||
assert.equal(error.message, 'There were 0 general errors and 1 total test failures.'); | ||
assert.ok(fs.existsSync('test/coverage/mocha/blogpost.js.html'), 'reports coverage of blogpost.js'); | ||
assert.ok(fs.existsSync('test/coverage/mocha/test.js.html'), 'reports coverage of mocha/test.js'); | ||
}); | ||
}); | ||
|
||
it('rest', function () { | ||
return testee.test(['examples/mocha/rest.html'], browsers, config).fail(function (error) { | ||
assert.equal(error.message, 'There were 0 general errors and 1 total test failures.'); | ||
assert.ok(fs.existsSync('test/coverage/mocha/blogpost.js.html'), 'reports coverage of blogpost.js'); | ||
assert.ok(fs.existsSync('test/coverage/mocha/test.js.html'), 'reports coverage of mocha/test.js'); | ||
}); | ||
}); | ||
}); | ||
}); |