Initial work to get working in Firefox

This commit is contained in:
Nathaniel van Diepen
2016-12-14 13:55:43 -07:00
parent 628d6eb2f1
commit 9823acc03f
81 changed files with 5501 additions and 5496 deletions

View File

@@ -1,40 +1,40 @@
var fs = require('fs');
var page;
var beforeLoadFn;
beforeEach(function() {
page = require('webpage').create();
page.onConsoleMessage = function(msg) { console.log(msg); };
page.onError = function(msg, trace) {
var msgStack = [msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
});
}
// we need try..catch here as mocha throws error that catched by phantom.onError
try {
mocha.throwError(msgStack.join('\n'));
} catch(e) { }
};
page.onInitialized = function() {
page.injectJs(node_modules + 'chai/chai.js');
page.injectJs(node_modules + 'sinon/pkg/sinon.js');
page.injectJs(node_modules + 'sinon-chrome/chrome.js');
page.injectJs(node_modules + 'sinon-chrome/src/phantom-tweaks.js');
page.injectJs(node_modules + 'require-stub/index.js');
// call additional function defined in tests
if (beforeLoadFn) {
beforeLoadFn();
}
};
});
afterEach(function() {
page.close();
beforeLoadFn = null;
var fs = require('fs');
var page;
var beforeLoadFn;
beforeEach(function() {
page = require('webpage').create();
page.onConsoleMessage = function(msg) { console.log(msg); };
page.onError = function(msg, trace) {
var msgStack = [msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
});
}
// we need try..catch here as mocha throws error that catched by phantom.onError
try {
mocha.throwError(msgStack.join('\n'));
} catch(e) { }
};
page.onInitialized = function() {
page.injectJs(node_modules + 'chai/chai.js');
page.injectJs(node_modules + 'sinon/pkg/sinon.js');
page.injectJs(node_modules + 'sinon-chrome/chrome.js');
page.injectJs(node_modules + 'sinon-chrome/src/phantom-tweaks.js');
page.injectJs(node_modules + 'require-stub/index.js');
// call additional function defined in tests
if (beforeLoadFn) {
beforeLoadFn();
}
};
});
afterEach(function() {
page.close();
beforeLoadFn = null;
});

View File

@@ -1,17 +1,17 @@
jest.dontMock('../../assets/js/components/Alert.jsx');
describe('Alert', function() {
var React, Alert, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Alert = require('../../assets/js/components/Alert.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
jest.dontMock('../../assets/js/components/Alert.jsx');
describe('Alert', function() {
var React, Alert, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Alert = require('../../assets/js/components/Alert.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
});

View File

@@ -1,17 +1,17 @@
jest.dontMock('../../assets/js/components/MainList.jsx');
describe('MainList', function() {
var React, MainList, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
MainList = require('../../assets/js/components/MainList.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
jest.dontMock('../../assets/js/components/MainList.jsx');
describe('MainList', function() {
var React, MainList, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
MainList = require('../../assets/js/components/MainList.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
});

View File

@@ -1,17 +1,17 @@
jest.dontMock('../../assets/js/components/Navbar.jsx');
describe('Navbar', function() {
var React, Navbar, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Navbar = require('../../assets/js/components/Navbar.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
jest.dontMock('../../assets/js/components/Navbar.jsx');
describe('Navbar', function() {
var React, Navbar, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Navbar = require('../../assets/js/components/Navbar.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
});

View File

@@ -1,17 +1,17 @@
jest.dontMock('../../assets/js/components/Options.jsx');
describe('Options', function() {
var React, Options, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Options = require('../../assets/js/components/Options.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
jest.dontMock('../../assets/js/components/Options.jsx');
describe('Options', function() {
var React, Options, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Options = require('../../assets/js/components/Options.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
});

View File

@@ -1,17 +1,17 @@
jest.dontMock('../../assets/js/components/SitesList.jsx');
describe('SitesList', function() {
var React, SitesList, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
SitesList = require('../../assets/js/components/SitesList.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
jest.dontMock('../../assets/js/components/SitesList.jsx');
describe('SitesList', function() {
var React, SitesList, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
SitesList = require('../../assets/js/components/SitesList.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
});

View File

@@ -1,17 +1,17 @@
jest.dontMock('../../assets/js/components/Wakatime.jsx');
describe('Wakatime', function() {
var React, Wakatime, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Wakatime = require('../../assets/js/components/Wakatime.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
jest.dontMock('../../assets/js/components/Wakatime.jsx');
describe('Wakatime', function() {
var React, Wakatime, TestUtils, Component;
beforeEach(function() {
// Setup our tools
React = require('react/addons');
Wakatime = require('../../assets/js/components/Wakatime.jsx');
TestUtils = React.addons.TestUtils;
// Create the React component here using TestUtils and store into Component
});
it('should work', function() {
expect(2 + 2).toEqual(4);
});
});

View File

@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>

View File

@@ -1,11 +1,11 @@
var chai = require('chai');
var sinon = require('sinon');
var chrome = require('sinon-chrome');
var expect = chai.expect;
describe('Chrome Dev Tools', function() {
it('should work', function() {
chrome.browserAction.setTitle({title: 'hello'});
sinon.assert.calledOnce(chrome.browserAction.setTitle);
});
});
var chai = require('chai');
var sinon = require('sinon');
var chrome = require('sinon-chrome');
var expect = chai.expect;
describe('Chrome Dev Tools', function() {
it('should work', function() {
chrome.browserAction.setTitle({title: 'hello'});
sinon.assert.calledOnce(chrome.browserAction.setTitle);
});
});

View File

@@ -1,10 +1,10 @@
var chai = require('chai');
var expect = chai.expect;
import changeExtensionIcon from '../../assets/js/helpers/changeExtensionIcon';
describe('changeExtensionIcon', function() {
it('should be a function', function() {
expect(changeExtensionIcon).to.be.a('function');
});
var chai = require('chai');
var expect = chai.expect;
import changeExtensionIcon from '../../assets/js/helpers/changeExtensionIcon';
describe('changeExtensionIcon', function() {
it('should be a function', function() {
expect(changeExtensionIcon).to.be.a('function');
});
});

View File

@@ -1,10 +1,10 @@
var chai = require('chai');
var expect = chai.expect;
import changeExtensionState from '../../assets/js/helpers/changeExtensionState';
describe('changeExtensionState', function() {
it('should be a function', function() {
expect(changeExtensionState).to.be.a('function');
});
var chai = require('chai');
var expect = chai.expect;
import changeExtensionState from '../../assets/js/helpers/changeExtensionState';
describe('changeExtensionState', function() {
it('should be a function', function() {
expect(changeExtensionState).to.be.a('function');
});
});

View File

@@ -1,18 +1,18 @@
var chai = require('chai');
var sinon = require('sinon-chai');
var chrome = require('sinon-chrome');
var expect = chai.expect;
import changeExtensionTooltip from '../../assets/js/helpers/changeExtensionTooltip';
describe('changeExtensionTooltip', function() {
it('should be a function', function() {
expect(changeExtensionTooltip).to.be.a('function');
});
// it('should change the extension tooltip', function() {
// changeExtensionTooltip('WakaTime');
// expect(chrome.browserAction.setTitle).toHaveBeenCalledWith({title: 'Wakatime'});
// sinon.assert.calledWithMatch(chrome.browserAction.setTitle, {title: 'WakaTime'});
// });
});
var chai = require('chai');
var sinon = require('sinon-chai');
var chrome = require('sinon-chrome');
var expect = chai.expect;
import changeExtensionTooltip from '../../assets/js/helpers/changeExtensionTooltip';
describe('changeExtensionTooltip', function() {
it('should be a function', function() {
expect(changeExtensionTooltip).to.be.a('function');
});
// it('should change the extension tooltip', function() {
// changeExtensionTooltip('WakaTime');
// expect(chrome.browserAction.setTitle).toHaveBeenCalledWith({title: 'Wakatime'});
// sinon.assert.calledWithMatch(chrome.browserAction.setTitle, {title: 'WakaTime'});
// });
});

View File

@@ -1,26 +1,26 @@
var chai = require('chai');
var expect = chai.expect;
import contains from '../../assets/js/helpers/contains';
describe('contains', function() {
it('should be a function', function() {
expect(contains).to.be.a('function');
});
it('should match url against blacklist and return true', function() {
var list = "localhost\ntest.com";
var url = 'http://localhost/fooapp';
expect(contains(url, list)).to.equal(true);
});
it('should not match url against blacklist and return false', function() {
var list = "localhost2\ntest.com";
var url = 'http://localhost/fooapp';
expect(contains(url, list)).to.equal(false);
});
});
var chai = require('chai');
var expect = chai.expect;
import contains from '../../assets/js/helpers/contains';
describe('contains', function() {
it('should be a function', function() {
expect(contains).to.be.a('function');
});
it('should match url against blacklist and return true', function() {
var list = "localhost\ntest.com";
var url = 'http://localhost/fooapp';
expect(contains(url, list)).to.equal(true);
});
it('should not match url against blacklist and return false', function() {
var list = "localhost2\ntest.com";
var url = 'http://localhost/fooapp';
expect(contains(url, list)).to.equal(false);
});
});

View File

@@ -1,19 +1,19 @@
var chai = require('chai');
var expect = chai.expect;
import getDomainFromUrl from '../../assets/js/helpers/getDomainFromUrl';
describe('getDomainFromUrl', function() {
it('should be a function', function() {
expect(getDomainFromUrl).to.be.a('function');
});
it('should return the domain', function() {
expect(getDomainFromUrl('http://google.com/something/very/secret')).to.equal('http://google.com');
expect(getDomainFromUrl('http://www.google.com/something/very/secret')).to.equal('http://www.google.com');
// This is not how it was imaged to work, but let's leave it here as a warning.
expect(getDomainFromUrl('google.com/something/very/secret')).to.equal('google.com//very');
});
var chai = require('chai');
var expect = chai.expect;
import getDomainFromUrl from '../../assets/js/helpers/getDomainFromUrl';
describe('getDomainFromUrl', function() {
it('should be a function', function() {
expect(getDomainFromUrl).to.be.a('function');
});
it('should return the domain', function() {
expect(getDomainFromUrl('http://google.com/something/very/secret')).to.equal('http://google.com');
expect(getDomainFromUrl('http://www.google.com/something/very/secret')).to.equal('http://www.google.com');
// This is not how it was imaged to work, but let's leave it here as a warning.
expect(getDomainFromUrl('google.com/something/very/secret')).to.equal('google.com//very');
});
});

View File

@@ -1,18 +1,18 @@
var chai = require('chai');
var expect = chai.expect;
import in_array from '../../assets/js/helpers/in_array';
describe('in_array', function() {
it('should be a function', function() {
expect(in_array).to.be.a('function');
});
it('should find the needle and return true', function() {
expect(in_array('4', ['4', '3', '2', '1'])).to.equal(true);
});
it('should not find the needle and it should return false', function() {
expect(in_array('5', ['4', '3', '2', '1'])).to.equal(false);
});
var chai = require('chai');
var expect = chai.expect;
import in_array from '../../assets/js/helpers/in_array';
describe('in_array', function() {
it('should be a function', function() {
expect(in_array).to.be.a('function');
});
it('should find the needle and return true', function() {
expect(in_array('4', ['4', '3', '2', '1'])).to.equal(true);
});
it('should not find the needle and it should return false', function() {
expect(in_array('5', ['4', '3', '2', '1'])).to.equal(false);
});
});

View File

@@ -1,24 +1,24 @@
/**
* Test Runner for Mocha tests
* Using phantomjs to render page and execute scripts
*/
var node_modules = '../node_modules/';
phantom.injectJs(node_modules + 'mocha/mocha.js');
phantom.injectJs(node_modules + 'sinon-chrome/src/phantom-tweaks.js');
mocha.setup({ui: 'bdd', reporter: 'spec'});
// Setup
phantom.injectJs('beforeeach.js');
// Tests
phantom.injectJs('helpers/changeExtensionTooltip.spec.js');
// Execute
mocha.run(function(failures) {
// setTimeout is needed to supress "Unsafe JavaScript attempt to access..."
// see https://github.com/ariya/phantomjs/issues/12697
setTimeout(function() {
phantom.exit(failures);
}, 0);
/**
* Test Runner for Mocha tests
* Using phantomjs to render page and execute scripts
*/
var node_modules = '../node_modules/';
phantom.injectJs(node_modules + 'mocha/mocha.js');
phantom.injectJs(node_modules + 'sinon-chrome/src/phantom-tweaks.js');
mocha.setup({ui: 'bdd', reporter: 'spec'});
// Setup
phantom.injectJs('beforeeach.js');
// Tests
phantom.injectJs('helpers/changeExtensionTooltip.spec.js');
// Execute
mocha.run(function(failures) {
// setTimeout is needed to supress "Unsafe JavaScript attempt to access..."
// see https://github.com/ariya/phantomjs/issues/12697
setTimeout(function() {
phantom.exit(failures);
}, 0);
});