Setup CI tests (#100)

* use @xarc/xrun to streamline tasks in an imperative manner

* add lint-staged/husky for git hook tasks

* run prettier across all files

* fixing tests

* add ci test workflow

* add a ci workflow

* remove precommit in favor of husky

* add .prettierrc.js

* reformat with prettier
This commit is contained in:
Vu Nguyen
2021-01-13 23:05:05 -06:00
committed by GitHub
parent 649c64cf1d
commit 9ef655ac3b
117 changed files with 9484 additions and 4342 deletions

View File

@@ -2,39 +2,47 @@ var fs = require('fs');
var page;
var beforeLoadFn;
beforeEach(function() {
page = require('webpage').create();
page.onConsoleMessage = function(msg) { console.log(msg); };
beforeEach(function () {
page = require('webpage').create();
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.onConsoleMessage = function (msg) {
console.log(msg);
};
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();
}
};
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;
});
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;
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
});
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);
});
});
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;
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
});
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);
});
});
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;
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
});
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);
});
});
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;
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
});
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);
});
});
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;
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
});
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);
});
});
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;
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
});
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);
});
});
it('should work', function () {
expect(2 + 2).toEqual(4);
});
});

View File

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

View File

@@ -3,9 +3,9 @@ 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);
});
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';
var changeExtensionIcon = require('../../assets/js/helpers/changeExtensionIcon');
describe('changeExtensionIcon', function() {
it('should be a function', function() {
expect(changeExtensionIcon).to.be.a('function');
});
});
describe('changeExtensionIcon', function () {
it('should be a function', function () {
expect(changeExtensionIcon).to.be.a('function');
});
});

View File

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

View File

@@ -3,16 +3,15 @@ var sinon = require('sinon-chai');
var chrome = require('sinon-chrome');
var expect = chai.expect;
//import changeExtensionTooltip from '../../assets/js/helpers/changeExtensionTooltip';
var changeExtensionTooltip = require('../../assets/js/helpers/changeExtensionTooltip');
describe('changeExtensionTooltip', function () {
it('should be a function', function () {
expect(changeExtensionTooltip).to.be.a('function');
});
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'});
// });
// 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,24 @@
var chai = require('chai');
var expect = chai.expect;
//import contains from '../../assets/js/helpers/contains';
var contains = require('../../assets/js/helpers/contains');
describe('contains', function() {
it('should be a function', function() {
expect(contains).to.be.a('function');
});
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() {
it('should match url against blacklist and return true', function () {
var list = 'localhost\ntest.com';
var list = "localhost\ntest.com";
var url = 'http://localhost/fooapp';
expect(contains(url, list)).to.equal(true);
});
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';
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 url = 'http://localhost/fooapp';
expect(contains(url, list)).to.equal(false);
});
});

View File

@@ -1,19 +1,23 @@
var chai = require('chai');
var expect = chai.expect;
//import getDomainFromUrl from '../../assets/js/helpers/getDomainFromUrl';
var getDomainFromUrl = require('../../assets/js/helpers/getDomainFromUrl');
describe('getDomainFromUrl', function() {
it('should be a function', function() {
expect(getDomainFromUrl).to.be.a('function');
});
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');
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');
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');
});
});
// 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';
var in_array = require('../../assets/js/helpers/in_array');
describe('in_array', function() {
it('should be a function', function() {
expect(in_array).to.be.a('function');
});
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 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);
});
});
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

@@ -6,19 +6,19 @@
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'});
mocha.setup({ ui: 'bdd', reporter: 'spec' });
// Setup
phantom.injectJs('beforeeach.js');
// Tests
phantom.injectJs('helpers/changeExtensionTooltip.spec.js');
phantom.injectJs('..' + '/helpers/changeExtensionTooltip.spec.js');
// Execute
mocha.run(function(failures) {
mocha.run(function (failures) {
// setTimeout is needed to supress "Unsafe JavaScript attempt to access..."
// see https://github.com/ariya/phantomjs/issues/12697
setTimeout(function() {
setTimeout(function () {
phantom.exit(failures);
}, 0);
});
});