Skip to content

Commit

Permalink
Merge pull request #42 from cofacts/add-jest
Browse files Browse the repository at this point in the history
Add jest and coverall
  • Loading branch information
godgunman committed Oct 7, 2017
2 parents 60fdb65 + 3243405 commit 4fa8691
Show file tree
Hide file tree
Showing 15 changed files with 892 additions and 55 deletions.
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
server.dist.js
static/*
static/*
node_modules/*
.next
coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
*.log
server.dist.js
coverage
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ cache: yarn

script:
- npm run lint:check
- npm run test -- --coverage

after_success:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# rumors-site

[![Build Status](https://travis-ci.org/cofacts/rumors-site.svg?branch=master)](https://travis-ci.org/cofacts/rumors-site)
[![Build Status](https://travis-ci.org/cofacts/rumors-site.svg?branch=master)](https://travis-ci.org/cofacts/rumors-site) [![Coverage Status](https://coveralls.io/repos/github/cofacts/rumors-site/badge.svg?branch=master)](https://coveralls.io/github/cofacts/rumors-site?branch=master)

Rumors list / creation UI, with server-side rendering

Expand Down
2 changes: 1 addition & 1 deletion components/App.css → components/App/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

html {
font: 15px/1.6 思源黑體, "Source Han Sans", "Noto Sans CJK TC", 蘋方-, "PingFang TC", 微軟正黑體, "Microsoft JhengHei", sans-serif;
}
}
10 changes: 5 additions & 5 deletions components/App.js → components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import Head from 'next/head';
import { Provider } from 'react-redux';
import Router from 'next/router';
import { fromJS } from 'immutable';
import { setLogin } from '../util/gql';
import configure from '../redux';
import { showDialog, load } from '../redux/auth';
import { setLogin } from '../../util/gql';
import configure from '../../redux';
import { showDialog, load } from '../../redux/auth';
import AppHeader from './AppHeader';
import AppFooter from './AppFooter';
import LoginModal from './Modal/LoginModal';
import LoginModal from '../Modal/LoginModal';
import moment from 'moment';
import 'moment/locale/zh-tw';
import style from './App.css';
import NProgress from 'nprogress';
const { GA_TRACKER, AUTOTRACK_FILENAME } = require('../config');
const { GA_TRACKER, AUTOTRACK_FILENAME } = require('../../config');

let isBootstrapping = true;
moment.locale('zh-tw');
Expand Down
2 changes: 1 addition & 1 deletion components/AppFooter.js → components/App/AppFooter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { EDITOR_FACEBOOK_GROUP } from '../constants/urls';
import { EDITOR_FACEBOOK_GROUP } from '../../constants/urls';

export default function AppFooter() {
return (
Expand Down
6 changes: 3 additions & 3 deletions components/AppHeader.js → components/App/AppHeader.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { connect } from 'react-redux';
import { EDITOR_FACEBOOK_GROUP } from '../constants/urls';
import { Link } from '../routes';
import { showDialog, logout } from '../redux/auth';
import { EDITOR_FACEBOOK_GROUP } from '../../constants/urls';
import { Link } from '../../routes';
import { showDialog, logout } from '../../redux/auth';

function AppHeader({ user, onLoginClick, onLogoutClick }) {
return (
Expand Down
2 changes: 2 additions & 0 deletions components/App/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import app from './App';
export default app;
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
roots: [
'<rootDir>/components',
'<rootDir>/pages',
'<rootDir>/redux',
'<rootDir>/util',
],
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dev": "babel-node server",
"lint": "eslint --fix .",
"lint:check": "eslint .",
"test": "jest .",
"build": "docker build -t mrorz/rumors-site:latest .",
"build:next": "next build",
"build:server": "babel server.js -o server.dist.js",
Expand Down Expand Up @@ -53,13 +54,15 @@
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-wrap-in-js": "^1.1.1",
"babel-preset-env": "^1.6.0",
"coveralls": "^3.0.0",
"eslint": "^4.4.1",
"eslint-config-prettier": "^2.3.0",
"eslint-config-react-app": "^1.0.5",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-prettier": "^2.1.2",
"eslint-plugin-react": "^7.1.0",
"jest": "^21.2.1",
"prettier": "^1.4.4",
"redux-devtools-extension": "^2.13.2"
}
Expand Down
6 changes: 3 additions & 3 deletions pages/instant.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import Head from 'next/head';
import gql from '../util/gql';
import style from '../components/App.css';
import style from '../components/App/App.css';
import querystring from 'querystring';

const POLLING_INTERVAL = 5000;
Expand Down Expand Up @@ -234,14 +234,14 @@ class FullScreenResizer extends React.PureComponent {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: opacity .25s;
}
.hidden {
opacity: 0;
}
.scaler {
height: 768px; /* Fixed as in design mockup */
height: 768px;
/* Fixed as in design mockup */
padding: 0 44px;
}
`}</style>
Expand Down
14 changes: 14 additions & 0 deletions util/__tests__/__snapshots__/reducer.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reducer commonSetState sets state from payload 1`] = `
Immutable.Map {
"foo": "bar2",
}
`;

exports[`reducer commonSetState sets state from payload 2`] = `
Immutable.Map {
"foo": "bar",
"not-exist-key": "new-value",
}
`;
25 changes: 25 additions & 0 deletions util/__tests__/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { fromJS } from 'immutable';
import { commonSetState } from '../reducer';

describe('reducer', () => {
describe('commonSetState', () => {
const initState = fromJS({
state: {
foo: 'bar',
},
});
it('sets state from payload', () => {
expect(
commonSetState(initState, {
payload: { key: 'foo', value: 'bar2' },
}).get('state')
).toMatchSnapshot();

expect(
commonSetState(initState, {
payload: { key: 'not-exist-key', value: 'new-value' },
}).get('state')
).toMatchSnapshot();
});
});
});
Loading

0 comments on commit 4fa8691

Please sign in to comment.