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

@ -27,6 +27,7 @@ describe('app module', function() {
return assert.equal(app.getVersion(), '0.1.0');
});
});
describe('app.setVersion(version)', function() {
return it('overrides the version', function() {
assert.equal(app.getVersion(), '0.1.0');
@ -35,11 +36,13 @@ describe('app module', function() {
return app.setVersion('0.1.0');
});
});
describe('app.getName()', function() {
return it('returns the name field of package.json', function() {
return assert.equal(app.getName(), 'Electron Test');
});
});
describe('app.setName(name)', function() {
return it('overrides the name', function() {
assert.equal(app.getName(), 'Electron Test');
@ -48,17 +51,20 @@ describe('app module', function() {
return app.setName('Electron Test');
});
});
describe('app.getLocale()', function() {
return it('should not be empty', function() {
return assert.notEqual(app.getLocale(), '');
});
});
describe('app.exit(exitCode)', function() {
var appProcess;
appProcess = null;
var appProcess = null;
afterEach(function() {
return appProcess != null ? appProcess.kill() : void 0;
});
return it('emits a process exit event with the code', function(done) {
var appPath, electronPath, output;
appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app');
@ -77,15 +83,17 @@ describe('app module', function() {
});
});
});
return describe('BrowserWindow events', function() {
var w;
w = null;
var w = null;
afterEach(function() {
if (w != null) {
w.destroy();
}
return w = null;
});
it('should emit browser-window-focus event when window is focused', function(done) {
app.once('browser-window-focus', function(e, window) {
assert.equal(w.id, window.id);
@ -96,6 +104,7 @@ describe('app module', function() {
});
return w.emit('focus');
});
it('should emit browser-window-blur event when window is blured', function(done) {
app.once('browser-window-blur', function(e, window) {
assert.equal(w.id, window.id);
@ -106,6 +115,7 @@ describe('app module', function() {
});
return w.emit('blur');
});
return it('should emit browser-window-created event when window is created', function(done) {
app.once('browser-window-created', function(e, window) {
return setImmediate(function() {

View file

@ -5,8 +5,8 @@ const clipboard = require('electron').clipboard;
const nativeImage = require('electron').nativeImage;
describe('clipboard module', function() {
var fixtures;
fixtures = path.resolve(__dirname, 'fixtures');
var fixtures = path.resolve(__dirname, 'fixtures');
describe('clipboard.readImage()', function() {
return it('returns NativeImage intance', function() {
var i, p;
@ -16,6 +16,7 @@ describe('clipboard module', function() {
return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
});
});
describe('clipboard.readText()', function() {
return it('returns unicode string correctly', function() {
var text;
@ -24,6 +25,7 @@ describe('clipboard module', function() {
return assert.equal(clipboard.readText(), text);
});
});
describe('clipboard.readHtml()', function() {
return it('returns markup correctly', function() {
var markup, text;
@ -33,6 +35,7 @@ describe('clipboard module', function() {
return assert.equal(clipboard.readHtml(), markup);
});
});
describe('clipboard.readRtf', function() {
return it('returns rtf text correctly', function() {
var rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}";
@ -40,6 +43,7 @@ describe('clipboard module', function() {
return assert.equal(clipboard.readRtf(), rtf);
});
});
return describe('clipboard.write()', function() {
return it('returns data correctly', function() {
var i, markup, p, text, rtf;

View file

@ -10,29 +10,33 @@ const crashReporter = remote.require('electron').crashReporter;
const BrowserWindow = remote.require('electron').BrowserWindow;
describe('crash-reporter module', function() {
var fixtures, isCI, w;
fixtures = path.resolve(__dirname, 'fixtures');
w = null;
var fixtures = path.resolve(__dirname, 'fixtures');
var w = null;
beforeEach(function() {
return w = new BrowserWindow({
show: false
});
});
afterEach(function() {
return w.destroy();
});
if (process.mas) {
return;
}
isCI = remote.getGlobal('isCi');
var isCI = remote.getGlobal('isCi');
if (isCI) {
return;
}
it('should send minidump when renderer crashes', function(done) {
var called, port, server;
this.timeout(120000);
called = false;
server = http.createServer(function(req, res) {
var called = false;
var server = http.createServer(function(req, res) {
var form;
server.close();
form = new multiparty.Form();
@ -54,7 +58,7 @@ describe('crash-reporter module', function() {
return done();
});
});
port = remote.process.port;
var port = remote.process.port;
return server.listen(port, '127.0.0.1', function() {
port = server.address().port;
remote.process.port = port;
@ -72,6 +76,7 @@ describe('crash-reporter module', function() {
return w.loadURL(crashUrl);
});
});
return describe(".start(options)", function() {
return it('requires that the companyName and submitURL options be specified', function() {
assert.throws(function() {

View file

@ -3,9 +3,9 @@ const path = require('path');
const BrowserWindow = require('electron').remote.BrowserWindow;
describe('debugger module', function() {
var fixtures, w;
fixtures = path.resolve(__dirname, 'fixtures');
w = null;
var fixtures = path.resolve(__dirname, 'fixtures');
var w = null;
beforeEach(function() {
if (w != null) {
w.destroy();
@ -16,6 +16,7 @@ describe('debugger module', function() {
height: 400
});
});
afterEach(function() {
if (w != null) {
w.destroy();

View file

@ -16,8 +16,8 @@ const comparePaths = function(path1, path2) {
};
describe('ipc module', function() {
var fixtures;
fixtures = path.join(__dirname, 'fixtures');
var fixtures = path.join(__dirname, 'fixtures');
describe('remote.require', function() {
it('should returns same object for the same module', function() {
var dialog1, dialog2;
@ -25,36 +25,39 @@ describe('ipc module', function() {
dialog2 = remote.require('electron');
return assert.equal(dialog1, dialog2);
});
it('should work when object contains id property', function() {
var a;
a = remote.require(path.join(fixtures, 'module', 'id.js'));
return assert.equal(a.id, 1127);
});
return it('should search module from the user app', function() {
comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js'));
return comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules'));
});
});
describe('remote.createFunctionWithReturnValue', function() {
return it('should be called in browser synchronously', function() {
var buf, call, result;
buf = new Buffer('test');
call = remote.require(path.join(fixtures, 'module', 'call.js'));
result = call.call(remote.createFunctionWithReturnValue(buf));
var buf = new Buffer('test');
var call = remote.require(path.join(fixtures, 'module', 'call.js'));
var result = call.call(remote.createFunctionWithReturnValue(buf));
return assert.equal(result.constructor.name, 'Buffer');
});
});
describe('remote object in renderer', function() {
it('can change its properties', function() {
var property, property2;
property = remote.require(path.join(fixtures, 'module', 'property.js'));
var property = remote.require(path.join(fixtures, 'module', 'property.js'));
assert.equal(property.property, 1127);
property.property = 1007;
assert.equal(property.property, 1007);
property2 = remote.require(path.join(fixtures, 'module', 'property.js'));
var property2 = remote.require(path.join(fixtures, 'module', 'property.js'));
assert.equal(property2.property, 1007);
return property.property = 1127;
});
return it('can construct an object from its member', function() {
var call, obj;
call = remote.require(path.join(fixtures, 'module', 'call.js'));
@ -62,37 +65,37 @@ describe('ipc module', function() {
return assert.equal(obj.test, 'test');
});
});
describe('remote value in browser', function() {
var print;
print = path.join(fixtures, 'module', 'print_name.js');
var print = path.join(fixtures, 'module', 'print_name.js');
it('keeps its constructor name for objects', function() {
var buf, print_name;
buf = new Buffer('test');
print_name = remote.require(print);
var buf = new Buffer('test');
var print_name = remote.require(print);
return assert.equal(print_name.print(buf), 'Buffer');
});
return it('supports instanceof Date', function() {
var now, print_name;
now = new Date();
print_name = remote.require(print);
var now = new Date();
var print_name = remote.require(print);
assert.equal(print_name.print(now), 'Date');
return assert.deepEqual(print_name.echo(now), now);
});
});
describe('remote promise', function() {
return it('can be used as promise in each side', function(done) {
var promise;
promise = remote.require(path.join(fixtures, 'module', 'promise.js'));
var promise = remote.require(path.join(fixtures, 'module', 'promise.js'));
return promise.twicePromise(Promise.resolve(1234)).then(function(value) {
assert.equal(value, 2468);
return done();
});
});
});
describe('ipc.sender.send', function() {
return it('should work when sending an object containing id property', function(done) {
var obj;
obj = {
var obj = {
id: 1,
name: 'ly'
};
@ -103,16 +106,17 @@ describe('ipc module', function() {
return ipcRenderer.send('message', obj);
});
});
describe('ipc.sendSync', function() {
it('can be replied by setting event.returnValue', function() {
var msg;
msg = ipcRenderer.sendSync('echo', 'test');
var msg = ipcRenderer.sendSync('echo', 'test');
return assert.equal(msg, 'test');
});
return it('does not crash when reply is not sent and browser is destroyed', function(done) {
var w;
this.timeout(10000);
w = new BrowserWindow({
var w = new BrowserWindow({
show: false
});
ipcMain.once('send-sync-message', function(event) {
@ -123,18 +127,19 @@ describe('ipc module', function() {
return w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'));
});
});
return describe('remote listeners', function() {
var w;
w = null;
var w = null;
afterEach(function() {
return w.destroy();
});
return it('can be added and removed correctly', function() {
var listener;
w = new BrowserWindow({
show: false
});
listener = function() {};
var listener = function() {};
w.on('test', listener);
assert.equal(w.listenerCount('test'), 1);
w.removeListener('test', listener);

View file

@ -9,8 +9,7 @@ const MenuItem = remote.require('electron').MenuItem;
describe('menu module', function() {
describe('Menu.buildFromTemplate', function() {
it('should be able to attach extra fields', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'text',
extra: 'field'
@ -18,9 +17,9 @@ describe('menu module', function() {
]);
return assert.equal(menu.items[0].extra, 'field');
});
it('does not modify the specified template', function() {
var template;
template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;");
var template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;");
return assert.deepStrictEqual(template, [
{
label: 'text',
@ -32,10 +31,10 @@ describe('menu module', function() {
}
]);
});
return describe('Menu.buildFromTemplate should reorder based on item position specifiers', function() {
it('should position before existing item', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: '2',
id: '2'
@ -52,9 +51,9 @@ describe('menu module', function() {
assert.equal(menu.items[1].label, '2');
return assert.equal(menu.items[2].label, '3');
});
it('should position after existing item', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: '1',
id: '1'
@ -71,9 +70,9 @@ describe('menu module', function() {
assert.equal(menu.items[1].label, '2');
return assert.equal(menu.items[2].label, '3');
});
it('should position at endof existing separator groups', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
type: 'separator',
id: 'numbers'
@ -115,9 +114,9 @@ describe('menu module', function() {
assert.equal(menu.items[6].label, 'b');
return assert.equal(menu.items[7].label, 'c');
});
it('should create separator group if endof does not reference existing separator group', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'a',
id: 'a',
@ -153,9 +152,9 @@ describe('menu module', function() {
assert.equal(menu.items[6].label, '2');
return assert.equal(menu.items[7].label, '3');
});
return it('should continue inserting items at next index when no specifier is present', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: '4',
id: '4'
@ -182,10 +181,10 @@ describe('menu module', function() {
});
});
});
describe('Menu.insert', function() {
return it('should store item in @items by its index', function() {
var item, menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: '1'
}, {
@ -194,7 +193,7 @@ describe('menu module', function() {
label: '3'
}
]);
item = new MenuItem({
var item = new MenuItem({
label: 'inserted'
});
menu.insert(1, item);
@ -204,10 +203,10 @@ describe('menu module', function() {
return assert.equal(menu.items[3].label, '3');
});
});
describe('MenuItem.click', function() {
return it('should be called with the item object passed', function(done) {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'text',
click: function(item) {
@ -220,10 +219,10 @@ describe('menu module', function() {
return menu.delegate.executeCommand(menu.items[0].commandId);
});
});
return describe('MenuItem with checked property', function() {
it('clicking an checkbox item should flip the checked property', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'text',
type: 'checkbox'
@ -233,9 +232,9 @@ describe('menu module', function() {
menu.delegate.executeCommand(menu.items[0].commandId);
return assert.equal(menu.items[0].checked, true);
});
it('clicking an radio item should always make checked property true', function() {
var menu;
menu = Menu.buildFromTemplate([
var menu = Menu.buildFromTemplate([
{
label: 'text',
type: 'radio'
@ -246,6 +245,7 @@ describe('menu module', function() {
menu.delegate.executeCommand(menu.items[0].commandId);
return assert.equal(menu.items[0].checked, true);
});
it('at least have one item checked in each group', function() {
var i, j, k, menu, template;
template = [];
@ -269,6 +269,7 @@ describe('menu module', function() {
assert.equal(menu.items[0].checked, true);
return assert.equal(menu.items[12].checked, true);
});
it('should assign groupId automatically', function() {
var groupId, i, j, k, l, m, menu, results, template;
template = [];
@ -298,6 +299,7 @@ describe('menu module', function() {
}
return results;
});
return it("setting 'checked' should flip other items' 'checked' property", function() {
var i, j, k, l, m, menu, n, o, p, q, results, template;
template = [];

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);

View file

@ -4,16 +4,15 @@ const screen = require('electron').screen;
describe('screen module', function() {
describe('screen.getCursorScreenPoint()', function() {
return it('returns a point object', function() {
var point;
point = screen.getCursorScreenPoint();
var point = screen.getCursorScreenPoint();
assert.equal(typeof point.x, 'number');
return assert.equal(typeof point.y, 'number');
});
});
return describe('screen.getPrimaryDisplay()', function() {
return it('returns a display object', function() {
var display;
display = screen.getPrimaryDisplay();
var display = screen.getPrimaryDisplay();
assert.equal(typeof display.scaleFactor, 'number');
assert(display.size.width > 0);
return assert(display.size.height > 0);

View file

@ -11,11 +11,12 @@ const session = remote.session;
const BrowserWindow = remote.BrowserWindow;
describe('session module', function() {
var fixtures, url, w;
this.timeout(10000);
fixtures = path.resolve(__dirname, 'fixtures');
w = null;
url = "http://127.0.0.1";
var fixtures = path.resolve(__dirname, 'fixtures');
var w = null;
var url = "http://127.0.0.1";
beforeEach(function() {
return w = new BrowserWindow({
show: false,
@ -23,6 +24,7 @@ describe('session module', function() {
height: 400
});
});
afterEach(function() {
return w.destroy();
});
@ -62,6 +64,7 @@ describe('session module', function() {
});
});
});
it('should over-write the existent cookie', function(done) {
return session.defaultSession.cookies.set({
url: url,
@ -92,6 +95,7 @@ describe('session module', function() {
});
});
});
it('should remove cookies', function(done) {
return session.defaultSession.cookies.set({
url: url,
@ -155,6 +159,7 @@ describe('session module', function() {
height: 400
});
});
afterEach(function() {
return w.destroy();
});
@ -213,6 +218,7 @@ describe('session module', function() {
assert(fs.existsSync(downloadFilePath));
return fs.unlinkSync(downloadFilePath);
};
it('can download using BrowserWindow.loadURL', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() {
var port;
@ -225,6 +231,7 @@ describe('session module', function() {
});
});
});
it('can download using WebView.downloadURL', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() {
var port, webview;
@ -243,6 +250,7 @@ describe('session module', function() {
return document.body.appendChild(webview);
});
});
it('can cancel download', function(done) {
return downloadServer.listen(0, '127.0.0.1', function() {
var port;

View file

@ -3,13 +3,11 @@ const path = require('path');
const webFrame = require('electron').webFrame;
describe('webFrame module', function() {
var fixtures;
fixtures = path.resolve(__dirname, 'fixtures');
var fixtures = path.resolve(__dirname, 'fixtures');
return describe('webFrame.registerURLSchemeAsPrivileged', function() {
return it('supports fetch api', function(done) {
var url;
webFrame.registerURLSchemeAsPrivileged('file');
url = "file://" + fixtures + "/assets/logo.png";
var url = "file://" + fixtures + "/assets/logo.png";
return fetch(url).then(function(response) {
assert(response.ok);
return done();

View file

@ -5,9 +5,8 @@ const remote = require('electron').remote;
const session = remote.session;
describe('webRequest module', function() {
var defaultURL, server, ses;
ses = session.defaultSession;
server = http.createServer(function(req, res) {
var ses = session.defaultSession;
var server = http.createServer(function(req, res) {
var content;
res.setHeader('Custom', ['Header']);
content = req.url;
@ -16,7 +15,8 @@ describe('webRequest module', function() {
}
return res.end(content);
});
defaultURL = null;
var defaultURL = null;
before(function(done) {
return server.listen(0, '127.0.0.1', function() {
var port;
@ -25,13 +25,16 @@ describe('webRequest module', function() {
return done();
});
});
after(function() {
return server.close();
});
describe('webRequest.onBeforeRequest', function() {
afterEach(function() {
return ses.webRequest.onBeforeRequest(null);
});
it('can cancel the request', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) {
return callback({
@ -48,9 +51,9 @@ describe('webRequest module', function() {
}
});
});
it('can filter URLs', function(done) {
var filter;
filter = {
var filter = {
urls: [defaultURL + "filter/*"]
};
ses.webRequest.onBeforeRequest(filter, function(details, callback) {
@ -77,6 +80,7 @@ describe('webRequest module', function() {
}
});
});
it('receives details object', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) {
assert.equal(typeof details.id, 'number');
@ -98,6 +102,7 @@ describe('webRequest module', function() {
}
});
});
it('receives post data in details object', function(done) {
var postData = {
name: 'post test',
@ -125,6 +130,7 @@ describe('webRequest module', function() {
}
});
});
return it('can redirect the request', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) {
if (details.url === defaultURL) {
@ -147,10 +153,12 @@ describe('webRequest module', function() {
});
});
});
describe('webRequest.onBeforeSendHeaders', function() {
afterEach(function() {
return ses.webRequest.onBeforeSendHeaders(null);
});
it('receives details object', function(done) {
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
assert.equal(typeof details.requestHeaders, 'object');
@ -167,6 +175,7 @@ describe('webRequest module', function() {
}
});
});
it('can change the request headers', function(done) {
ses.webRequest.onBeforeSendHeaders(function(details, callback) {
var requestHeaders;
@ -187,6 +196,7 @@ describe('webRequest module', function() {
}
});
});
return it('resets the whole headers', function(done) {
var requestHeaders;
requestHeaders = {
@ -209,10 +219,12 @@ describe('webRequest module', function() {
});
});
});
describe('webRequest.onSendHeaders', function() {
afterEach(function() {
return ses.webRequest.onSendHeaders(null);
});
return it('receives details object', function(done) {
ses.webRequest.onSendHeaders(function(details) {
return assert.equal(typeof details.requestHeaders, 'object');
@ -229,10 +241,12 @@ describe('webRequest module', function() {
});
});
});
describe('webRequest.onHeadersReceived', function() {
afterEach(function() {
return ses.webRequest.onHeadersReceived(null);
});
it('receives details object', function(done) {
ses.webRequest.onHeadersReceived(function(details, callback) {
assert.equal(details.statusLine, 'HTTP/1.1 200 OK');
@ -251,6 +265,7 @@ describe('webRequest module', function() {
}
});
});
it('can change the response header', function(done) {
ses.webRequest.onHeadersReceived(function(details, callback) {
var responseHeaders;
@ -272,6 +287,7 @@ describe('webRequest module', function() {
}
});
});
return it('does not change header by default', function(done) {
ses.webRequest.onHeadersReceived(function(details, callback) {
return callback({});
@ -289,10 +305,12 @@ describe('webRequest module', function() {
});
});
});
describe('webRequest.onResponseStarted', function() {
afterEach(function() {
return ses.webRequest.onResponseStarted(null);
});
return it('receives details object', function(done) {
ses.webRequest.onResponseStarted(function(details) {
assert.equal(typeof details.fromCache, 'boolean');
@ -313,11 +331,13 @@ describe('webRequest module', function() {
});
});
});
describe('webRequest.onBeforeRedirect', function() {
afterEach(function() {
ses.webRequest.onBeforeRedirect(null);
return ses.webRequest.onBeforeRequest(null);
});
return it('receives details object', function(done) {
var redirectURL;
redirectURL = defaultURL + "redirect";
@ -348,10 +368,12 @@ describe('webRequest module', function() {
});
});
});
describe('webRequest.onCompleted', function() {
afterEach(function() {
return ses.webRequest.onCompleted(null);
});
return it('receives details object', function(done) {
ses.webRequest.onCompleted(function(details) {
assert.equal(typeof details.fromCache, 'boolean');
@ -370,11 +392,13 @@ describe('webRequest module', function() {
});
});
});
return describe('webRequest.onErrorOccurred', function() {
afterEach(function() {
ses.webRequest.onErrorOccurred(null);
return ses.webRequest.onBeforeRequest(null);
});
return it('receives details object', function(done) {
ses.webRequest.onBeforeRequest(function(details, callback) {
return callback({

View file

@ -10,8 +10,8 @@ const ipcMain = remote.require('electron').ipcMain;
const BrowserWindow = remote.require('electron').BrowserWindow;
describe('asar package', function() {
var fixtures;
fixtures = path.join(__dirname, 'fixtures');
var fixtures = path.join(__dirname, 'fixtures');
describe('node api', function() {
describe('fs.readFileSync', function() {
it('does not leak fd', function() {
@ -21,6 +21,7 @@ describe('asar package', function() {
readCalls++;
}
});
it('reads a normal file', function() {
var file1, file2, file3;
file1 = path.join(fixtures, 'asar', 'a.asar', 'file1');
@ -30,6 +31,7 @@ describe('asar package', function() {
file3 = path.join(fixtures, 'asar', 'a.asar', 'file3');
return assert.equal(fs.readFileSync(file3).toString().trim(), 'file3');
});
it('reads from a empty file', function() {
var buffer, file;
file = path.join(fixtures, 'asar', 'empty.asar', 'file1');
@ -37,11 +39,13 @@ describe('asar package', function() {
assert.equal(buffer.length, 0);
return assert.equal(buffer.toString(), '');
});
it('reads a linked file', function() {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'link1');
return assert.equal(fs.readFileSync(p).toString().trim(), 'file1');
});
it('reads a file from linked directory', function() {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'file1');
@ -49,6 +53,7 @@ describe('asar package', function() {
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
return assert.equal(fs.readFileSync(p).toString().trim(), 'file1');
});
it('throws ENOENT error when can not find file', function() {
var p, throws;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
@ -57,6 +62,7 @@ describe('asar package', function() {
};
return assert.throws(throws, /ENOENT/);
});
it('passes ENOENT error to callback when can not find file', function() {
var async, p;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
@ -67,12 +73,14 @@ describe('asar package', function() {
});
return async = true;
});
return it('reads a normal file with unpacked files', function() {
var p;
p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt');
return assert.equal(fs.readFileSync(p).toString().trim(), 'a');
});
});
describe('fs.readFile', function() {
it('reads a normal file', function(done) {
var p;
@ -83,6 +91,7 @@ describe('asar package', function() {
return done();
});
});
it('reads from a empty file', function(done) {
var p;
p = path.join(fixtures, 'asar', 'empty.asar', 'file1');
@ -92,6 +101,7 @@ describe('asar package', function() {
return done();
});
});
it('reads a linked file', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'link1');
@ -101,6 +111,7 @@ describe('asar package', function() {
return done();
});
});
it('reads a file from linked directory', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
@ -110,6 +121,7 @@ describe('asar package', function() {
return done();
});
});
return it('throws ENOENT error when can not find file', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
@ -119,6 +131,7 @@ describe('asar package', function() {
});
});
});
describe('fs.lstatSync', function() {
it('handles path with trailing slash correctly', function() {
var p;
@ -126,6 +139,7 @@ describe('asar package', function() {
fs.lstatSync(p);
return fs.lstatSync(p + '/');
});
it('returns information of root', function() {
var p, stats;
p = path.join(fixtures, 'asar', 'a.asar');
@ -135,6 +149,7 @@ describe('asar package', function() {
assert.equal(stats.isSymbolicLink(), false);
return assert.equal(stats.size, 0);
});
it('returns information of a normal file', function() {
var file, j, len, p, ref2, results, stats;
ref2 = ['file1', 'file2', 'file3', path.join('dir1', 'file1'), path.join('link2', 'file1')];
@ -150,6 +165,7 @@ describe('asar package', function() {
}
return results;
});
it('returns information of a normal directory', function() {
var file, j, len, p, ref2, results, stats;
ref2 = ['dir1', 'dir2', 'dir3'];
@ -165,6 +181,7 @@ describe('asar package', function() {
}
return results;
});
it('returns information of a linked file', function() {
var file, j, len, p, ref2, results, stats;
ref2 = ['link1', path.join('dir1', 'link1'), path.join('link2', 'link2')];
@ -180,6 +197,7 @@ describe('asar package', function() {
}
return results;
});
it('returns information of a linked directory', function() {
var file, j, len, p, ref2, results, stats;
ref2 = ['link2', path.join('dir1', 'link2'), path.join('link2', 'link2')];
@ -195,6 +213,7 @@ describe('asar package', function() {
}
return results;
});
return it('throws ENOENT error when can not find file', function() {
var file, j, len, p, ref2, results, throws;
ref2 = ['file4', 'file5', path.join('dir1', 'file4')];
@ -210,12 +229,13 @@ describe('asar package', function() {
return results;
});
});
describe('fs.lstat', function() {
it('handles path with trailing slash correctly', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1');
return fs.lstat(p + '/', done);
});
it('returns information of root', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar');
fs.lstat(p, function(err, stats) {
@ -227,6 +247,7 @@ describe('asar package', function() {
return done();
});
});
it('returns information of a normal file', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'file1');
fs.lstat(p, function(err, stats) {
@ -238,6 +259,7 @@ describe('asar package', function() {
return done();
});
});
it('returns information of a normal directory', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'dir1');
fs.lstat(p, function(err, stats) {
@ -249,6 +271,7 @@ describe('asar package', function() {
return done();
});
});
it('returns information of a linked file', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link1');
fs.lstat(p, function(err, stats) {
@ -260,6 +283,7 @@ describe('asar package', function() {
return done();
});
});
it('returns information of a linked directory', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2');
fs.lstat(p, function(err, stats) {
@ -271,6 +295,7 @@ describe('asar package', function() {
return done();
});
});
return it('throws ENOENT error when can not find file', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'file4');
fs.lstat(p, function(err) {
@ -279,97 +304,97 @@ describe('asar package', function() {
});
});
});
describe('fs.realpathSync', function() {
it('returns real path root', function() {
var p, parent, r;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = 'a.asar';
r = fs.realpathSync(path.join(parent, p));
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = 'a.asar';
var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, p));
});
it('returns real path of a normal file', function() {
var p, parent, r;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'file1');
r = fs.realpathSync(path.join(parent, p));
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'file1');
var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, p));
});
it('returns real path of a normal directory', function() {
var p, parent, r;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'dir1');
r = fs.realpathSync(path.join(parent, p));
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'dir1');
var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, p));
});
it('returns real path of a linked file', function() {
var p, parent, r;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'link2', 'link1');
r = fs.realpathSync(path.join(parent, p));
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link1');
var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, 'a.asar', 'file1'));
});
it('returns real path of a linked directory', function() {
var p, parent, r;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'link2', 'link2');
r = fs.realpathSync(path.join(parent, p));
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link2');
var r = fs.realpathSync(path.join(parent, p));
return assert.equal(r, path.join(parent, 'a.asar', 'dir1'));
});
return it('throws ENOENT error when can not find file', function() {
var p, parent, throws;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'not-exist');
throws = function() {
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'not-exist');
var throws = function() {
return fs.realpathSync(path.join(parent, p));
};
return assert.throws(throws, /ENOENT/);
});
});
describe('fs.realpath', function() {
it('returns real path root', function(done) {
var p, parent;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = 'a.asar';
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = 'a.asar';
return fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null);
assert.equal(r, path.join(parent, p));
return done();
});
});
it('returns real path of a normal file', function(done) {
var p, parent;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'file1');
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'file1');
return fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null);
assert.equal(r, path.join(parent, p));
return done();
});
});
it('returns real path of a normal directory', function(done) {
var p, parent;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'dir1');
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'dir1');
return fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null);
assert.equal(r, path.join(parent, p));
return done();
});
});
it('returns real path of a linked file', function(done) {
var p, parent;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'link2', 'link1');
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link1');
return fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null);
assert.equal(r, path.join(parent, 'a.asar', 'file1'));
return done();
});
});
it('returns real path of a linked directory', function(done) {
var p, parent;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'link2', 'link2');
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'link2', 'link2');
return fs.realpath(path.join(parent, p), function(err, r) {
assert.equal(err, null);
assert.equal(r, path.join(parent, 'a.asar', 'dir1'));
@ -377,9 +402,8 @@ describe('asar package', function() {
});
});
return it('throws ENOENT error when can not find file', function(done) {
var p, parent;
parent = fs.realpathSync(path.join(fixtures, 'asar'));
p = path.join('a.asar', 'not-exist');
var parent = fs.realpathSync(path.join(fixtures, 'asar'));
var p = path.join('a.asar', 'not-exist');
return fs.realpath(path.join(parent, p), function(err) {
assert.equal(err.code, 'ENOENT');
return done();
@ -388,32 +412,32 @@ describe('asar package', function() {
});
describe('fs.readdirSync', function() {
it('reads dirs from root', function() {
var dirs, p;
p = path.join(fixtures, 'asar', 'a.asar');
dirs = fs.readdirSync(p);
var p = path.join(fixtures, 'asar', 'a.asar');
var dirs = fs.readdirSync(p);
return assert.deepEqual(dirs, ['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']);
});
it('reads dirs from a normal dir', function() {
var dirs, p;
p = path.join(fixtures, 'asar', 'a.asar', 'dir1');
dirs = fs.readdirSync(p);
var p = path.join(fixtures, 'asar', 'a.asar', 'dir1');
var dirs = fs.readdirSync(p);
return assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']);
});
it('reads dirs from a linked dir', function() {
var dirs, p;
p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2');
dirs = fs.readdirSync(p);
var p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2');
var dirs = fs.readdirSync(p);
return assert.deepEqual(dirs, ['file1', 'file2', 'file3', 'link1', 'link2']);
});
return it('throws ENOENT error when can not find file', function() {
var p, throws;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
throws = function() {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var throws = function() {
return fs.readdirSync(p);
};
return assert.throws(throws, /ENOENT/);
});
});
describe('fs.readdir', function() {
it('reads dirs from root', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar');
@ -423,6 +447,7 @@ describe('asar package', function() {
return done();
});
});
it('reads dirs from a normal dir', function(done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'dir1');
fs.readdir(p, function(err, dirs) {
@ -439,15 +464,16 @@ describe('asar package', function() {
return done();
});
});
return it('throws ENOENT error when can not find file', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return fs.readdir(p, function(err) {
assert.equal(err.code, 'ENOENT');
return done();
});
});
});
describe('fs.openSync', function() {
it('opens a normal/linked/under-linked-directory file', function() {
var buffer, fd, file, j, len, p, ref2, results;
@ -464,19 +490,19 @@ describe('asar package', function() {
}
return results;
});
return it('throws ENOENT error when can not find file', function() {
var p, throws;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
throws = function() {
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var throws = function() {
return fs.openSync(p);
};
return assert.throws(throws, /ENOENT/);
});
});
describe('fs.open', function() {
it('opens a normal file', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'file1');
var p = path.join(fixtures, 'asar', 'a.asar', 'file1');
return fs.open(p, 'r', function(err, fd) {
var buffer;
assert.equal(err, null);
@ -488,48 +514,48 @@ describe('asar package', function() {
});
});
});
return it('throws ENOENT error when can not find file', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return fs.open(p, 'r', function(err) {
assert.equal(err.code, 'ENOENT');
return done();
});
});
});
describe('fs.mkdir', function() {
return it('throws error when calling inside asar archive', function(done) {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return fs.mkdir(p, function(err) {
assert.equal(err.code, 'ENOTDIR');
return done();
});
});
});
describe('fs.mkdirSync', function() {
return it('throws error when calling inside asar archive', function() {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
var p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
return assert.throws((function() {
return fs.mkdirSync(p);
}), new RegExp('ENOTDIR'));
});
});
describe('child_process.fork', function() {
it('opens a normal js file', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js'));
var child = child_process.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js'));
child.on('message', function(msg) {
assert.equal(msg, 'message');
return done();
});
return child.send('message');
});
return it('supports asar in the forked js', function(done) {
var child, file;
file = path.join(fixtures, 'asar', 'a.asar', 'file1');
child = child_process.fork(path.join(fixtures, 'module', 'asar.js'));
var file = path.join(fixtures, 'asar', 'a.asar', 'file1');
var child = child_process.fork(path.join(fixtures, 'module', 'asar.js'));
child.on('message', function(content) {
assert.equal(content, fs.readFileSync(file).toString());
return done();
@ -537,6 +563,7 @@ describe('asar package', function() {
return child.send(file);
});
});
describe('child_process.execFile', function() {
var echo, execFile, execFileSync, ref2;
if (process.platform !== 'darwin') {
@ -544,6 +571,7 @@ describe('asar package', function() {
}
ref2 = require('child_process'), execFile = ref2.execFile, execFileSync = ref2.execFileSync;
echo = path.join(fixtures, 'asar', 'echo.asar', 'echo');
it('executes binaries', function(done) {
execFile(echo, ['test'], function(error, stdout) {
assert.equal(error, null);
@ -551,15 +579,17 @@ describe('asar package', function() {
return done();
});
});
return xit('execFileSync executes binaries', function() {
var output;
output = execFileSync(echo, ['test']);
return assert.equal(String(output), 'test\n');
});
});
describe('internalModuleReadFile', function() {
var internalModuleReadFile;
internalModuleReadFile = process.binding('fs').internalModuleReadFile;
var internalModuleReadFile = process.binding('fs').internalModuleReadFile;
it('read a normal file', function() {
var file1, file2, file3;
file1 = path.join(fixtures, 'asar', 'a.asar', 'file1');
@ -569,25 +599,28 @@ describe('asar package', function() {
file3 = path.join(fixtures, 'asar', 'a.asar', 'file3');
return assert.equal(internalModuleReadFile(file3).toString().trim(), 'file3');
});
return it('reads a normal file with unpacked files', function() {
var p;
p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt');
return assert.equal(internalModuleReadFile(p).toString().trim(), 'a');
});
});
return describe('process.noAsar', function() {
var errorName;
errorName = process.platform === 'win32' ? 'ENOENT' : 'ENOTDIR';
var errorName = process.platform === 'win32' ? 'ENOENT' : 'ENOTDIR';
beforeEach(function() {
return process.noAsar = true;
});
afterEach(function() {
return process.noAsar = false;
});
it('disables asar support in sync API', function() {
var dir, file;
file = path.join(fixtures, 'asar', 'a.asar', 'file1');
dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
var file = path.join(fixtures, 'asar', 'a.asar', 'file1');
var dir = path.join(fixtures, 'asar', 'a.asar', 'dir1');
assert.throws((function() {
return fs.readFileSync(file);
}), new RegExp(errorName));
@ -601,6 +634,7 @@ describe('asar package', function() {
return fs.readdirSync(dir);
}), new RegExp(errorName));
});
it('disables asar support in async API', function(done) {
var dir, file;
file = path.join(fixtures, 'asar', 'a.asar', 'file1');
@ -619,6 +653,7 @@ describe('asar package', function() {
});
});
});
return it('treats *.asar as normal file', function() {
var asar, content1, content2, originalFs;
originalFs = require('original-fs');
@ -632,44 +667,44 @@ describe('asar package', function() {
});
});
});
describe('asar protocol', function() {
var url;
url = require('url');
var url = require('url');
it('can request a file in package', function(done) {
var p;
p = path.resolve(fixtures, 'asar', 'a.asar', 'file1');
var p = path.resolve(fixtures, 'asar', 'a.asar', 'file1');
return $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'file1');
return done();
});
});
it('can request a file in package with unpacked files', function(done) {
var p;
p = path.resolve(fixtures, 'asar', 'unpack.asar', 'a.txt');
var p = path.resolve(fixtures, 'asar', 'unpack.asar', 'a.txt');
return $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'a');
return done();
});
});
it('can request a linked file in package', function(done) {
var p;
p = path.resolve(fixtures, 'asar', 'a.asar', 'link2', 'link1');
var p = path.resolve(fixtures, 'asar', 'a.asar', 'link2', 'link1');
return $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'file1');
return done();
});
});
it('can request a file in filesystem', function(done) {
var p;
p = path.resolve(fixtures, 'asar', 'file');
var p = path.resolve(fixtures, 'asar', 'file');
return $.get("file://" + p, function(data) {
assert.equal(data.trim(), 'file');
return done();
});
});
it('gets 404 when file is not found', function(done) {
var p;
p = path.resolve(fixtures, 'asar', 'a.asar', 'no-exist');
var p = path.resolve(fixtures, 'asar', 'a.asar', 'no-exist');
return $.ajax({
url: "file://" + p,
error: function(err) {
@ -678,19 +713,20 @@ describe('asar package', function() {
}
});
});
it('sets __dirname correctly', function(done) {
var p, u, w;
after(function() {
w.destroy();
return ipcMain.removeAllListeners('dirname');
});
w = new BrowserWindow({
var w = new BrowserWindow({
show: false,
width: 400,
height: 400
});
p = path.resolve(fixtures, 'asar', 'web.asar', 'index.html');
u = url.format({
var p = path.resolve(fixtures, 'asar', 'web.asar', 'index.html');
var u = url.format({
protocol: 'file',
slashed: true,
pathname: p
@ -701,19 +737,20 @@ describe('asar package', function() {
});
return w.loadURL(u);
});
return it('loads script tag in html', function(done) {
var p, u, w;
after(function() {
w.destroy();
return ipcMain.removeAllListeners('ping');
});
w = new BrowserWindow({
var w = new BrowserWindow({
show: false,
width: 400,
height: 400
});
p = path.resolve(fixtures, 'asar', 'script.asar', 'index.html');
u = url.format({
var p = path.resolve(fixtures, 'asar', 'script.asar', 'index.html');
var u = url.format({
protocol: 'file',
slashed: true,
pathname: p
@ -725,15 +762,17 @@ describe('asar package', function() {
});
});
});
describe('original-fs module', function() {
var originalFs;
originalFs = require('original-fs');
var originalFs = require('original-fs');
it('treats .asar as file', function() {
var file, stats;
file = path.join(fixtures, 'asar', 'a.asar');
stats = originalFs.statSync(file);
return assert(stats.isFile());
});
return it('is available in forked scripts', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'original-fs.js'));
@ -744,9 +783,10 @@ describe('asar package', function() {
return child.send('message');
});
});
describe('graceful-fs module', function() {
var gfs;
gfs = require('graceful-fs');
var gfs = require('graceful-fs');
it('recognize asar archvies', function() {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'link1');
@ -756,9 +796,10 @@ describe('asar package', function() {
return assert.notEqual(fs.readdir, gfs.readdir);
});
});
describe('mkdirp module', function() {
var mkdirp;
mkdirp = require('mkdirp');
var mkdirp = require('mkdirp');
return it('throws error when calling inside asar archive', function() {
var p;
p = path.join(fixtures, 'asar', 'a.asar', 'not-exist');
@ -767,20 +808,20 @@ describe('asar package', function() {
}), new RegExp('ENOTDIR'));
});
});
return describe('native-image', function() {
it('reads image from asar archive', function() {
var logo, p;
p = path.join(fixtures, 'asar', 'logo.asar', 'logo.png');
logo = nativeImage.createFromPath(p);
var p = path.join(fixtures, 'asar', 'logo.asar', 'logo.png');
var logo = nativeImage.createFromPath(p);
return assert.deepEqual(logo.getSize(), {
width: 55,
height: 55
});
});
return it('reads image from asar archive with unpacked files', function() {
var logo, p;
p = path.join(fixtures, 'asar', 'unpack.asar', 'atom.png');
logo = nativeImage.createFromPath(p);
var p = path.join(fixtures, 'asar', 'unpack.asar', 'atom.png');
var logo = nativeImage.createFromPath(p);
return assert.deepEqual(logo.getSize(), {
width: 1024,
height: 1024

View file

@ -8,20 +8,22 @@ const BrowserWindow = remote.require('electron').BrowserWindow;
const session = remote.require('electron').session;
describe('chromium feature', function() {
var fixtures, listener;
fixtures = path.resolve(__dirname, 'fixtures');
listener = null;
var fixtures = path.resolve(__dirname, 'fixtures');
var listener = null;
afterEach(function() {
if (listener != null) {
window.removeEventListener('message', listener);
}
return listener = null;
});
xdescribe('heap snapshot', function() {
return it('does not crash', function() {
return process.atomBinding('v8_util').takeHeapSnapshot();
});
});
describe('sending request of http protocol urls', function() {
return it('does not crash', function(done) {
var server;
@ -38,13 +40,15 @@ describe('chromium feature', function() {
});
});
});
describe('document.hidden', function() {
var url, w;
url = "file://" + fixtures + "/pages/document-hidden.html";
w = null;
var url = "file://" + fixtures + "/pages/document-hidden.html";
var w = null;
afterEach(function() {
return w != null ? w.destroy() : void 0;
});
it('is set correctly when window is not shown', function(done) {
w = new BrowserWindow({
show: false
@ -55,6 +59,7 @@ describe('chromium feature', function() {
});
return w.loadURL(url);
});
return it('is set correctly when window is inactive', function(done) {
w = new BrowserWindow({
show: false
@ -67,6 +72,7 @@ describe('chromium feature', function() {
return w.loadURL(url);
});
});
xdescribe('navigator.webkitGetUserMedia', function() {
return it('calls its callbacks', function(done) {
this.timeout(5000);
@ -80,18 +86,21 @@ describe('chromium feature', function() {
});
});
});
describe('navigator.language', function() {
return it('should not be empty', function() {
return assert.notEqual(navigator.language, '');
});
});
describe('navigator.serviceWorker', function() {
var url, w;
url = "file://" + fixtures + "/pages/service-worker/index.html";
w = null;
var url = "file://" + fixtures + "/pages/service-worker/index.html";
var w = null;
afterEach(function() {
return w != null ? w.destroy() : void 0;
});
return it('should register for file scheme', function(done) {
w = new BrowserWindow({
show: false
@ -113,8 +122,10 @@ describe('chromium feature', function() {
return w.loadURL(url);
});
});
describe('window.open', function() {
this.timeout(20000);
it('returns a BrowserWindowProxy object', function() {
var b;
b = window.open('about:blank', '', 'show=no');
@ -122,6 +133,7 @@ describe('chromium feature', function() {
assert.equal(b.constructor.name, 'BrowserWindowProxy');
return b.close();
});
it('accepts "node-integration" as feature', function(done) {
var b;
listener = function(event) {
@ -132,6 +144,7 @@ describe('chromium feature', function() {
window.addEventListener('message', listener);
return b = window.open("file://" + fixtures + "/pages/window-opener-node.html", '', 'nodeIntegration=no,show=no');
});
it('inherit options of parent window', function(done) {
var b;
listener = function(event) {
@ -144,6 +157,7 @@ describe('chromium feature', function() {
window.addEventListener('message', listener);
return b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', 'show=no');
});
return it('does not override child options', function(done) {
var b, size;
size = {
@ -159,6 +173,7 @@ describe('chromium feature', function() {
return b = window.open("file://" + fixtures + "/pages/window-open-size.html", '', "show=no,width=" + size.width + ",height=" + size.height);
});
});
describe('window.opener', function() {
var url, w;
this.timeout(10000);
@ -188,6 +203,7 @@ describe('chromium feature', function() {
return b = window.open(url, '', 'show=no');
});
});
describe('window.postMessage', function() {
return it('sets the source and origin correctly', function(done) {
var b, sourceId;
@ -211,6 +227,7 @@ describe('chromium feature', function() {
});
});
});
describe('window.opener.postMessage', function() {
return it('sets source and origin correctly', function(done) {
var b;
@ -225,6 +242,7 @@ describe('chromium feature', function() {
return b = window.open("file://" + fixtures + "/pages/window-opener-postMessage.html", '', 'show=no');
});
});
describe('creating a Uint8Array under browser side', function() {
return it('does not crash', function() {
var RUint8Array;
@ -232,6 +250,7 @@ describe('chromium feature', function() {
return new RUint8Array;
});
});
describe('webgl', function() {
return it('can be get as context in canvas', function() {
var webgl;
@ -242,6 +261,7 @@ describe('chromium feature', function() {
return assert.notEqual(webgl, null);
});
});
describe('web workers', function() {
it('Worker can work', function(done) {
var message, worker;
@ -254,6 +274,7 @@ describe('chromium feature', function() {
};
return worker.postMessage(message);
});
return it('SharedWorker can work', function(done) {
var message, worker;
worker = new SharedWorker('../fixtures/workers/shared_worker.js');
@ -265,15 +286,18 @@ describe('chromium feature', function() {
return worker.port.postMessage(message);
});
});
describe('iframe', function() {
var iframe;
iframe = null;
var iframe = null;
beforeEach(function() {
return iframe = document.createElement('iframe');
});
afterEach(function() {
return document.body.removeChild(iframe);
});
return it('does not have node integration', function(done) {
iframe.src = "file://" + fixtures + "/pages/set-global.html";
document.body.appendChild(iframe);
@ -283,6 +307,7 @@ describe('chromium feature', function() {
};
});
});
describe('storage', function() {
return it('requesting persitent quota works', function(done) {
return navigator.webkitPersistentStorage.requestQuota(1024 * 1024, function(grantedBytes) {
@ -291,15 +316,17 @@ describe('chromium feature', function() {
});
});
});
describe('websockets', function() {
var WebSocketServer, server, wss;
wss = null;
server = null;
WebSocketServer = ws.Server;
var wss = null;
var server = null;
var WebSocketServer = ws.Server;
afterEach(function() {
wss.close();
return server.close();
});
return it('has user agent', function(done) {
server = http.createServer();
return server.listen(0, '127.0.0.1', function() {
@ -319,6 +346,7 @@ describe('chromium feature', function() {
});
});
});
return describe('Promise', function() {
it('resolves correctly in Node.js calls', function(done) {
document.registerElement('x-element', {
@ -338,6 +366,7 @@ describe('chromium feature', function() {
return called = true;
});
});
return it('resolves correctly in Electron calls', function(done) {
document.registerElement('y-element', {
prototype: Object.create(HTMLElement.prototype, {

View file

@ -3,14 +3,15 @@ const path = require('path');
const temp = require('temp');
describe('third-party module', function() {
var fixtures;
fixtures = path.join(__dirname, 'fixtures');
var fixtures = path.join(__dirname, 'fixtures');
temp.track();
if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) {
describe('runas', function() {
it('can be required in renderer', function() {
return require('runas');
});
return it('can be required in node binary', function(done) {
var child, runas;
runas = path.join(fixtures, 'module', 'runas.js');
@ -21,6 +22,7 @@ describe('third-party module', function() {
});
});
});
describe('ffi', function() {
return it('does not crash', function() {
var ffi, libm;
@ -32,6 +34,7 @@ describe('third-party module', function() {
});
});
}
return describe('q', function() {
var Q;
Q = require('q');

View file

@ -6,8 +6,8 @@ const os = require('os');
const remote = require('electron').remote;
describe('node feature', function() {
var fixtures;
fixtures = path.join(__dirname, 'fixtures');
var fixtures = path.join(__dirname, 'fixtures');
describe('child_process', function() {
return describe('child_process.fork', function() {
it('works in current process', function(done) {
@ -19,6 +19,7 @@ describe('node feature', function() {
});
return child.send('message');
});
it('preserves args', function(done) {
var args, child;
args = ['--expose_gc', '-test', '1'];
@ -29,6 +30,7 @@ describe('node feature', function() {
});
return child.send('message');
});
it('works in forked process', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'));
@ -38,6 +40,7 @@ describe('node feature', function() {
});
return child.send('message');
});
it('works in forked process when options.env is specifed', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
@ -49,6 +52,7 @@ describe('node feature', function() {
});
return child.send('message');
});
it('works in browser process', function(done) {
var child, fork;
fork = remote.require('child_process').fork;
@ -59,6 +63,7 @@ describe('node feature', function() {
});
return child.send('message');
});
it('has String::localeCompare working in script', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'locale-compare.js'));
@ -68,6 +73,7 @@ describe('node feature', function() {
});
return child.send('message');
});
return it('has setImmediate working in script', function(done) {
var child;
child = child_process.fork(path.join(fixtures, 'module', 'set-immediate.js'));
@ -79,17 +85,20 @@ describe('node feature', function() {
});
});
});
describe('contexts', function() {
describe('setTimeout in fs callback', function() {
if (process.env.TRAVIS === 'true') {
return;
}
return it('does not crash', function(done) {
return fs.readFile(__filename, function() {
return setTimeout(done, 0);
});
});
});
describe('throw error in node context', function() {
return it('gets caught', function(done) {
var error, lsts;
@ -110,11 +119,13 @@ describe('node feature', function() {
});
});
});
describe('setTimeout called under Chromium event loop in browser process', function() {
return it('can be scheduled in time', function(done) {
return remote.getGlobal('setTimeout')(done, 0);
});
});
return describe('setInterval called under Chromium event loop in browser process', function() {
return it('can be scheduled in time', function(done) {
var clear, interval;
@ -126,11 +137,13 @@ describe('node feature', function() {
});
});
});
describe('message loop', function() {
describe('process.nextTick', function() {
it('emits the callback', function(done) {
return process.nextTick(done);
});
return it('works in nested calls', function(done) {
return process.nextTick(function() {
return process.nextTick(function() {
@ -139,10 +152,12 @@ describe('node feature', function() {
});
});
});
return describe('setImmediate', function() {
it('emits the callback', function(done) {
return setImmediate(done);
});
return it('works in nested calls', function(done) {
return setImmediate(function() {
return setImmediate(function() {
@ -152,10 +167,12 @@ describe('node feature', function() {
});
});
});
describe('net.connect', function() {
if (process.platform !== 'darwin') {
return;
}
return it('emit error when connect to a socket path without listeners', function(done) {
var child, script, socketPath;
socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
@ -172,6 +189,7 @@ describe('node feature', function() {
});
});
});
describe('Buffer', function() {
it('can be created from WebKit external string', function() {
var b, p;
@ -181,6 +199,7 @@ describe('node feature', function() {
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋');
return assert.equal(Buffer.byteLength(p.innerText), 45);
});
return it('correctly parses external one-byte UTF8 string', function() {
var b, p;
p = document.createElement('p');