Skip to content

Commit 57fa364

Browse files
Merge pull request #24 from ekonstantinidis/jest-tests
Initialize Tests (Jest)
2 parents a860a02 + 3228738 commit 57fa364

25 files changed

+1168
-54
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
npm-debug.log
33

44
build/
5+
coverage/
56
node_modules/
67
Gitify.app/
8+

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
language: node_js
22

33
node_js:
4-
- '0.12'
4+
- '0.10.36'
5+
6+
addons:
7+
code_climate:
8+
repo_token: 7c19339cc50fdc0dceb2acc8e022e939d845e1676eee84ca9115c5a9b6796992
59

610
install:
711
- npm install
12+
- npm install -g codeclimate-test-reporter
813

914
script:
1015
- npm test
16+
17+
after_script:
18+
- codeclimate < ./coverage/lcov.info

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
Gitify [![Build Status](https://travis-ci.org/ekonstantinidis/gitify.svg?branch=master)](https://travis-ci.org/ekonstantinidis/gitify)
2-
==========
3-
GitHub Notifications on your menu bar.
1+
# Gitify
2+
[![travis][travis-image]][travis-url]
3+
[![cc-coverage][cc-coverage-image]][cc-coverage-url]
4+
5+
[travis-image]: https://travis-ci.org/ekonstantinidis/gitify.svg?branch=master
6+
[travis-url]: https://travis-ci.org/ekonstantinidis/gitify
7+
[cc-coverage-image]: https://codeclimate.com/github/ekonstantinidis/gitify/badges/coverage.svg
8+
[cc-coverage-url]: https://codeclimate.com/github/ekonstantinidis/gitify/coverage
9+
10+
### GitHub Notifications on your menu bar.
411

512
![Gitify](images/press.png)
613

7-
### Installation
14+
### Download
815
You can download Gitify from the [releases](https://github.com/ekonstantinidis/gitify/releases) page. Currently only supports OS X.
916

1017
### Prerequisites

package.json

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,88 @@
44
"description": "GitHub Notifications on your menu bar.",
55
"main": "main.js",
66
"scripts": {
7-
"build-js": "npm run mkdir -p build/js && browserify -t reactify src/js/app.js -o build/js/app.js",
7+
"build-js": "mkdir -p build/js && browserify -t reactify src/js/app.js -o build/js/app.js",
88
"build": "npm install && mkdir -p build/js && grunt build && npm run build-js",
99
"watch-js": "watchify -t reactify src/js/app.js -o build/js/app.js -v",
1010
"watch": "grunt build && npm build && npm run watch-js | grunt watch",
1111
"start": "electron .",
1212
"dist": "rm -rf Gitify.app/ && electron-packager . Gitify --platform=darwin --arch=x64 --version=0.27.1 --icon=images/app-icon.icns --prune --ignore=src",
13-
"test": "jsxhint --reporter node_modules/jshint-stylish/stylish.js 'src/**/*.js', 'index.js' --exclude 'Gruntfile.js'"
13+
"test": "jsxhint --reporter node_modules/jshint-stylish/stylish.js 'src/**/*.js', 'index.js' --exclude 'Gruntfile.js' && jscs 'src/js/' && jest",
14+
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
15+
},
16+
"jshintConfig": {
17+
"browserify": true,
18+
"unused": true,
19+
"undef": true,
20+
"globals": {
21+
"console": false
22+
}
23+
},
24+
"jscsConfig": {
25+
"esprima": "esprima-fb",
26+
"disallowMultipleVarDecl": "exceptUndefined",
27+
"validateQuoteMarks": {
28+
"mark": "'",
29+
"escape": false
30+
},
31+
"validateParameterSeparator": ", ",
32+
"validateIndentation": 2,
33+
"requireSpacesInFunction": {
34+
"beforeOpeningRoundBrace": true,
35+
"beforeOpeningCurlyBrace": true
36+
},
37+
"requireSpacesInConditionalExpression": {
38+
"afterTest": true,
39+
"beforeConsequent": true,
40+
"afterConsequent": true,
41+
"beforeAlternate": true
42+
},
43+
"disallowTrailingWhitespace": true,
44+
"maximumLineLength": 100,
45+
"requireCurlyBraces": true,
46+
"disallowMixedSpacesAndTabs": true,
47+
"requireSpaceBeforeBinaryOperators": true,
48+
"safeContextKeyword": [
49+
"self"
50+
],
51+
"disallowMultipleLineBreaks": true,
52+
"disallowMultipleLineStrings": true,
53+
"disallowSpaceAfterObjectKeys": true,
54+
"disallowNewlineBeforeBlockStatements": true,
55+
"disallowTrailingComma": true,
56+
"requireCommaBeforeLineBreak": true,
57+
"requireSpaceBetweenArguments": true,
58+
"requireSpaceBeforeBlockStatements": true,
59+
"requireSpaceBeforeObjectValues": true,
60+
"requireSpacesInForStatement": true
61+
},
62+
"jest": {
63+
"scriptPreprocessor": "src/js/__tests__/preprocessor.js",
64+
"collectCoverage": true,
65+
"collectCoverageOnlyFrom": {
66+
"src/js/actions/actions.js": true,
67+
"src/js/components/login.js": true,
68+
"src/js/components/navigation.js": true,
69+
"src/js/components/notification.js": true,
70+
"src/js/components/notifications.js": true,
71+
"src/js/components/repository.js": true,
72+
"src/js/components/footer.js": true,
73+
"src/js/stores/auth.js": true,
74+
"src/js/stores/notifications.js": true
75+
},
76+
"unmockedModulePathPatterns": [
77+
"node_modules/react",
78+
"node_modules/react-tools",
79+
"node_modules/underscore"
80+
],
81+
"testPathDirs": [
82+
"src/js/__tests__/"
83+
],
84+
"testPathIgnorePatterns": [
85+
"src/js/__tests__/preprocessor.js",
86+
"src/js/__tests__/__mocks__/",
87+
"node_modules/"
88+
]
1489
},
1590
"repository": {
1691
"type": "git",
@@ -36,6 +111,7 @@
36111
"octicons": "=2.2.0",
37112
"react": "=0.13.3",
38113
"react-router": "=0.13.3",
114+
"react-tools": "=0.13.3",
39115
"reactify": "=1.1.1",
40116
"reflux": "=0.2.7",
41117
"reloading": "0.0.6",
@@ -46,11 +122,14 @@
46122
"devDependencies": {
47123
"electron-packager": "=4.1.2",
48124
"electron-prebuilt": "=0.27.1",
125+
"esprima-fb": "=15001.1.0-dev-harmony-fb",
49126
"grunt": "=0.4.5",
50127
"grunt-contrib-clean": "=0.6.0",
51128
"grunt-contrib-copy": "=0.8.0",
52129
"grunt-contrib-less": "=1.0.1",
53130
"grunt-contrib-watch": "=0.6.1",
131+
"jest-cli": "=0.4.5",
132+
"jscs": "^1.13.1",
54133
"jshint-stylish": "=1.0.2",
55134
"jsxhint": "=0.15.0",
56135
"less": "=2.5.1"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// mock of react router used in the tests
2+
var React = require('react');
3+
4+
function Router (params) {
5+
this.name = 'router';
6+
this.params = params;
7+
}
8+
9+
Router.prototype.makeHref = function () {};
10+
Router.prototype.transitionTo = function () {};
11+
Router.prototype.isActive = function () {
12+
return false;
13+
};
14+
15+
Router.prototype.getCurrentParams = function () {
16+
return this.params;
17+
};
18+
19+
Router.Link = React.createClass({
20+
render: function () {
21+
return (<a/>);
22+
}
23+
});
24+
25+
module.exports = Router;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* global jest */
2+
3+
var superagent = jest.genMockFromModule('superagent');
4+
5+
var Response = jest.genMockFunction().mockImplementation(function () {
6+
this.status = 200;
7+
this.ok = true;
8+
});
9+
10+
Response.prototype.send = jest.genMockFunction();
11+
Response.prototype.toError = jest.genMockFunction();
12+
13+
var Request = jest.genMockFunction().mockImplementation(function (method, url) {
14+
this.method = method;
15+
this.url = url;
16+
});
17+
18+
Request.prototype.accept = jest.genMockFunction().mockReturnThis();
19+
Request.prototype.set = jest.genMockFunction().mockReturnThis();
20+
Request.prototype.send = jest.genMockFunction().mockReturnThis();
21+
Request.prototype.field = jest.genMockFunction().mockReturnThis();
22+
Request.prototype.query = jest.genMockFunction().mockReturnThis();
23+
Request.prototype.end = jest.genMockFunction().mockImplementation(function (callback) {
24+
25+
if (superagent.mockDelay) {
26+
this.delayTimer = setTimeout(callback, 0, superagent.mockError, superagent.mockResponse);
27+
28+
return;
29+
}
30+
31+
callback(superagent.mockError, superagent.mockResponse);
32+
});
33+
34+
Request.prototype.abort = jest.genMockFunction().mockImplementation(function () {
35+
this.aborted = true;
36+
37+
if (this.delayTimer) {
38+
clearTimeout(this.delayTimer);
39+
}
40+
});
41+
42+
superagent.Request = Request;
43+
superagent.Response = Response;
44+
45+
superagent.mockResponse = new Response();
46+
superagent.mockError = null;
47+
superagent.mockDelay = false;
48+
49+
function __setResponse (status, ok, body, error) {
50+
var mockedResponse = jest.genMockFunction().mockImplementation(function () {
51+
this.status = status;
52+
this.ok = ok;
53+
this.body = body;
54+
});
55+
56+
superagent.mockError = {
57+
response: {
58+
body: error
59+
}
60+
};
61+
62+
superagent.mockResponse = new mockedResponse();
63+
}
64+
65+
module.exports = {
66+
Response: Response,
67+
Request: Request,
68+
post: function () {
69+
return new Request();
70+
},
71+
get: function () {
72+
return new Request();
73+
},
74+
patch: function () {
75+
return new Request();
76+
},
77+
put: function () {
78+
return new Request();
79+
},
80+
__setResponse: __setResponse
81+
};

src/js/__tests__/basic.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* global describe, it, expect */
2+
3+
describe('basic', function () {
4+
it('adds two and two and gets four', function () {
5+
expect(2 + 2).toBe(4);
6+
});
7+
});

src/js/__tests__/components/footer.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* global jest, describe, beforeEach, it, expect */
2+
3+
jest.dontMock('reflux');
4+
jest.dontMock('../../actions/actions.js');
5+
jest.dontMock('../../components/footer.js');
6+
7+
var React = require('react/addons');
8+
var TestUtils = React.addons.TestUtils;
9+
10+
describe('Test for Footer', function () {
11+
12+
var Actions, Footer;
13+
14+
beforeEach(function () {
15+
// Mock Electron's window.require
16+
// and remote.require('shell')
17+
window.require = function () {
18+
return {
19+
require: function () {
20+
return {
21+
openExternal: function () {
22+
return {};
23+
}
24+
};
25+
}
26+
};
27+
};
28+
29+
Actions = require('../../actions/actions.js');
30+
Footer = require('../../components/footer.js');
31+
});
32+
33+
it('Should load the footer', function () {
34+
35+
var instance = TestUtils.renderIntoDocument(<Footer />);
36+
expect(instance.openRepoBrowser).toBeDefined();
37+
38+
instance.openRepoBrowser();
39+
40+
});
41+
42+
});

0 commit comments

Comments
 (0)