Add newlines between describe/it blocks

This commit is contained in:
Kevin Sawicki 2016-02-16 17:09:41 -08:00
parent 709661156a
commit e63c3c727a
15 changed files with 455 additions and 295 deletions

View file

@ -6,13 +6,13 @@ const remote = require('electron').remote;
const protocol = remote.require('electron').protocol;
describe('protocol module', function() {
var postData, protocolName, text;
protocolName = 'sp';
text = 'valar morghulis';
postData = {
var protocolName = 'sp';
var text = 'valar morghulis';
var postData = {
name: 'post test',
type: 'string'
};
afterEach(function(done) {
return protocol.unregisterProtocol(protocolName, function() {
return protocol.uninterceptProtocol('http', function() {
@ -20,11 +20,12 @@ describe('protocol module', function() {
});
});
});
describe('protocol.register(Any)Protocol', function() {
var emptyHandler;
emptyHandler = function(request, callback) {
var emptyHandler = function(request, callback) {
return callback();
};
it('throws error when scheme is already registered', function(done) {
return protocol.registerStringProtocol(protocolName, emptyHandler, function(error) {
assert.equal(error, null);
@ -34,9 +35,9 @@ describe('protocol module', function() {
});
});
});
it('does not crash when handler is called twice', function(done) {
var doubleHandler;
doubleHandler = function(request, callback) {
var doubleHandler = function(request, callback) {
try {
callback(text);
return callback();
@ -60,6 +61,7 @@ describe('protocol module', function() {
});
});
});
it('sends error when callback is called with nothing', function(done) {
return protocol.registerBufferProtocol(protocolName, emptyHandler, function(error) {
if (error) {
@ -77,9 +79,9 @@ describe('protocol module', function() {
});
});
});
return it('does not crash when callback is called in next tick', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return setImmediate(function() {
return callback(text);
});
@ -101,6 +103,7 @@ describe('protocol module', function() {
});
});
});
describe('protocol.unregisterProtocol', function() {
return it('returns error when scheme does not exist', function(done) {
return protocol.unregisterProtocol('not-exist', function(error) {
@ -109,10 +112,10 @@ describe('protocol module', function() {
});
});
});
describe('protocol.registerStringProtocol', function() {
it('sends string as response', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(text);
};
return protocol.registerStringProtocol(protocolName, handler, function(error) {
@ -131,9 +134,9 @@ describe('protocol module', function() {
});
});
});
it('sets Access-Control-Allow-Origin', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(text);
};
return protocol.registerStringProtocol(protocolName, handler, function(error) {
@ -153,9 +156,9 @@ describe('protocol module', function() {
});
});
});
it('sends object as response', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback({
data: text,
mimeType: 'text/html'
@ -177,9 +180,9 @@ describe('protocol module', function() {
});
});
});
return it('fails when sending object other than string', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(new Date);
};
return protocol.registerBufferProtocol(protocolName, handler, function(error) {
@ -199,12 +202,12 @@ describe('protocol module', function() {
});
});
});
describe('protocol.registerBufferProtocol', function() {
var buffer;
buffer = new Buffer(text);
var buffer = new Buffer(text);
it('sends Buffer as response', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(buffer);
};
return protocol.registerBufferProtocol(protocolName, handler, function(error) {
@ -223,11 +226,12 @@ describe('protocol module', function() {
});
});
});
it('sets Access-Control-Allow-Origin', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(buffer);
};
return protocol.registerBufferProtocol(protocolName, handler, function(error) {
if (error) {
return done(error);
@ -245,9 +249,9 @@ describe('protocol module', function() {
});
});
});
it('sends object as response', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback({
data: buffer,
mimeType: 'text/html'
@ -269,9 +273,9 @@ describe('protocol module', function() {
});
});
});
return it('fails when sending string', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(text);
};
return protocol.registerBufferProtocol(protocolName, handler, function(error) {
@ -291,15 +295,15 @@ describe('protocol module', function() {
});
});
});
describe('protocol.registerFileProtocol', function() {
var fileContent, filePath, normalContent, normalPath;
filePath = path.join(__dirname, 'fixtures', 'asar', 'a.asar', 'file1');
fileContent = require('fs').readFileSync(filePath);
normalPath = path.join(__dirname, 'fixtures', 'pages', 'a.html');
normalContent = require('fs').readFileSync(normalPath);
var filePath = path.join(__dirname, 'fixtures', 'asar', 'a.asar', 'file1');
var fileContent = require('fs').readFileSync(filePath);
var normalPath = path.join(__dirname, 'fixtures', 'pages', 'a.html');
var normalContent = require('fs').readFileSync(normalPath);
it('sends file path as response', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(filePath);
};
return protocol.registerFileProtocol(protocolName, handler, function(error) {
@ -318,9 +322,9 @@ describe('protocol module', function() {
});
});
});
it('sets Access-Control-Allow-Origin', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(filePath);
};
return protocol.registerFileProtocol(protocolName, handler, function(error) {
@ -363,11 +367,12 @@ describe('protocol module', function() {
});
});
});
it('can send normal file', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(normalPath);
};
return protocol.registerFileProtocol(protocolName, handler, function(error) {
if (error) {
return done(error);
@ -384,10 +389,10 @@ describe('protocol module', function() {
});
});
});
it('fails when sending unexist-file', function(done) {
var fakeFilePath, handler;
fakeFilePath = path.join(__dirname, 'fixtures', 'asar', 'a.asar', 'not-exist');
handler = function(request, callback) {
var fakeFilePath = path.join(__dirname, 'fixtures', 'asar', 'a.asar', 'not-exist');
var handler = function(request, callback) {
return callback(fakeFilePath);
};
return protocol.registerBufferProtocol(protocolName, handler, function(error) {
@ -406,9 +411,9 @@ describe('protocol module', function() {
});
});
});
return it('fails when sending unsupported content', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(new Date);
};
return protocol.registerBufferProtocol(protocolName, handler, function(error) {
@ -428,10 +433,10 @@ describe('protocol module', function() {
});
});
});
describe('protocol.registerHttpProtocol', function() {
it('sends url as response', function(done) {
var server;
server = http.createServer(function(req, res) {
var server = http.createServer(function(req, res) {
assert.notEqual(req.headers.accept, '');
res.end(text);
return server.close();
@ -462,9 +467,9 @@ describe('protocol module', function() {
});
});
});
it('fails when sending invalid url', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback({
url: 'url'
});
@ -485,9 +490,9 @@ describe('protocol module', function() {
});
});
});
return it('fails when sending unsupported content', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(new Date);
};
return protocol.registerHttpProtocol(protocolName, handler, function(error) {
@ -507,6 +512,7 @@ describe('protocol module', function() {
});
});
});
describe('protocol.isProtocolHandled', function() {
it('returns true for file:', function(done) {
return protocol.isProtocolHandled('file', function(result) {
@ -514,27 +520,30 @@ describe('protocol module', function() {
return done();
});
});
it('returns true for http:', function(done) {
return protocol.isProtocolHandled('http', function(result) {
assert.equal(result, true);
return done();
});
});
it('returns true for https:', function(done) {
return protocol.isProtocolHandled('https', function(result) {
assert.equal(result, true);
return done();
});
});
it('returns false when scheme is not registred', function(done) {
return protocol.isProtocolHandled('no-exist', function(result) {
assert.equal(result, false);
return done();
});
});
it('returns true for custom protocol', function(done) {
var emptyHandler;
emptyHandler = function(request, callback) {
var emptyHandler = function(request, callback) {
return callback();
};
return protocol.registerStringProtocol(protocolName, emptyHandler, function(error) {
@ -545,9 +554,9 @@ describe('protocol module', function() {
});
});
});
return it('returns true for intercepted protocol', function(done) {
var emptyHandler;
emptyHandler = function(request, callback) {
var emptyHandler = function(request, callback) {
return callback();
};
return protocol.interceptStringProtocol('http', emptyHandler, function(error) {
@ -559,11 +568,12 @@ describe('protocol module', function() {
});
});
});
describe('protocol.intercept(Any)Protocol', function() {
var emptyHandler;
emptyHandler = function(request, callback) {
var emptyHandler = function(request, callback) {
return callback();
};
it('throws error when scheme is already intercepted', function(done) {
return protocol.interceptStringProtocol('http', emptyHandler, function(error) {
assert.equal(error, null);
@ -573,9 +583,9 @@ describe('protocol module', function() {
});
});
});
it('does not crash when handler is called twice', function(done) {
var doubleHandler;
doubleHandler = function(request, callback) {
var doubleHandler = function(request, callback) {
try {
callback(text);
return callback();
@ -599,6 +609,7 @@ describe('protocol module', function() {
});
});
});
return it('sends error when callback is called with nothing', function(done) {
if (process.env.TRAVIS === 'true') {
return done();
@ -620,10 +631,10 @@ describe('protocol module', function() {
});
});
});
describe('protocol.interceptStringProtocol', function() {
it('can intercept http protocol', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(text);
};
return protocol.interceptStringProtocol('http', handler, function(error) {
@ -642,9 +653,9 @@ describe('protocol module', function() {
});
});
});
it('can set content-type', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback({
mimeType: 'application/json',
data: '{"value": 1}'
@ -667,9 +678,9 @@ describe('protocol module', function() {
});
});
});
return it('can receive post data', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
var uploadData;
uploadData = request.uploadData[0].bytes.toString();
return callback({
@ -695,10 +706,10 @@ describe('protocol module', function() {
});
});
});
describe('protocol.interceptBufferProtocol', function() {
it('can intercept http protocol', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
return callback(new Buffer(text));
};
return protocol.interceptBufferProtocol('http', handler, function(error) {
@ -717,9 +728,9 @@ describe('protocol module', function() {
});
});
});
return it('can receive post data', function(done) {
var handler;
handler = function(request, callback) {
var handler = function(request, callback) {
var uploadData;
uploadData = request.uploadData[0].bytes;
return callback(uploadData);
@ -743,10 +754,10 @@ describe('protocol module', function() {
});
});
});
describe('protocol.interceptHttpProtocol', function() {
return it('can send POST request', function(done) {
var server;
server = http.createServer(function(req, res) {
var server = http.createServer(function(req, res) {
var body;
body = '';
req.on('data', function(chunk) {
@ -758,10 +769,9 @@ describe('protocol module', function() {
return server.close();
});
return server.listen(0, '127.0.0.1', function() {
var handler, port, url;
port = server.address().port;
url = "http://127.0.0.1:" + port;
handler = function(request, callback) {
var port = server.address().port;
var url = "http://127.0.0.1:" + port;
var handler = function(request, callback) {
var data;
data = {
url: url,
@ -794,6 +804,7 @@ describe('protocol module', function() {
});
});
});
return describe('protocol.uninterceptProtocol', function() {
it('returns error when scheme does not exist', function(done) {
return protocol.uninterceptProtocol('not-exist', function(error) {
@ -801,6 +812,7 @@ describe('protocol module', function() {
return done();
});
});
return it('returns error when scheme is not intercepted', function(done) {
return protocol.uninterceptProtocol('http', function(error) {
assert.notEqual(error, null);