Browse Source

Initial commit with a simple test.

Snow 8 years ago
commit
c2dca60ad4
10 changed files with 5705 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 65 0
      package.json
  3. 10 0
      public/index.html
  4. 13 0
      src/__test__/actions.test.js
  5. 4 0
      src/actions/constants.js
  6. 17 0
      src/actions/index.js
  7. 8 0
      src/index.js
  8. 2 0
      src/reducers/index.js
  9. 39 0
      webpack.config.js
  10. 5545 0
      yarn.lock

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+node_modules
+build

+ 65 - 0
package.json

@@ -0,0 +1,65 @@
+{
+  "name": "react-boilerplate",
+  "version": "1.0.0",
+  "main": "index.js",
+  "license": "MIT",
+  "babel": {
+    "presets": [
+      "es2015",
+      "react",
+      "stage-2"
+    ],
+    "plugins": [
+      "react-hot-loader/babel"
+    ]
+  },
+  "devDependencies": {
+    "babel-core": "^6.25.0",
+    "babel-jest": "^20.0.3",
+    "babel-loader": "^7.1.0",
+    "babel-preset-es2015": "^6.24.1",
+    "babel-preset-react": "^6.24.1",
+    "babel-preset-stage-2": "^6.24.1",
+    "enzyme": "^2.8.2",
+    "enzyme-to-json": "^1.5.1",
+    "eslint": "^3.19.0",
+    "eslint-config-airbnb": "^15.0.1",
+    "eslint-plugin-import": "^2.3.0",
+    "eslint-plugin-jsx-a11y": "^5.0.3",
+    "eslint-plugin-react": "^7.1.0",
+    "husky": "^0.14.1",
+    "jest": "^20.0.4",
+    "lint-staged": "^4.0.0",
+    "react-test-renderer": "^15.6.1",
+    "webpack": "^3.0.0",
+    "webpack-dev-server": "^2.5.0"
+  },
+  "scripts": {
+    "start": "webpack-dev-server --colors --hot --config ./webpack.config.js",
+    "build": "webpack --progress -p && cp ./public/* ./build",
+    "precommit": "lint-staged",
+    "test": "jest --watch"
+  },
+  "dependencies": {
+    "prop-types": "^15.5.10",
+    "react": "^15.6.1",
+    "react-dom": "^15.6.1",
+    "react-hot-loader": "next",
+    "react-motion": "^0.5.0",
+    "react-redux": "^5.0.5",
+    "react-router-dom": "4.1.1",
+    "redux": "^3.7.0",
+    "redux-actions": "^2.0.3",
+    "styled-components": "^2.1.0"
+  },
+  "lint-staged": {
+    "*.js": [
+      "prettier --single-quote --es5 --write",
+      "git add"
+    ],
+    "*.jsx": [
+      "prettier --single-quote --es5 --write",
+      "git add"
+    ]
+  }
+}

+ 10 - 0
public/index.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+  <head>
+      <title>My react boilerplate</title>
+  </head>
+  <body>
+    <div id="app"></div>
+    <script src="bundle.js"></script>
+  </body>
+</html>

+ 13 - 0
src/__test__/actions.test.js

@@ -0,0 +1,13 @@
+import actions from '../actions/';
+import * as c from '../actions/constants';
+
+describe('Check action creator', () => {
+  const testPayload = 'testPayload';
+
+  it('Check actions are correctly setup', () => {
+    expect(actions.selectSubreddit(testPayload)).toEqual({
+      type: c.SELECT_SUBREDDIT,
+      payload: testPayload
+    });
+  });
+});

+ 4 - 0
src/actions/constants.js

@@ -0,0 +1,4 @@
+export const SELECT_SUBREDDIT = 'SELECT_SUBREDDIT',
+  INVALIDATE_SUBREDDIT = 'INVALIDATE_SUBREDDIT',
+  REQUEST_POST = 'REQUEST_POST',
+  RECEIVE_POSTS = 'RECEIVE_POSTS';

+ 17 - 0
src/actions/index.js

@@ -0,0 +1,17 @@
+import { createActions } from 'redux-actions';
+import * as c from './constants';
+
+const actions = createActions(
+  {
+    [c.RECEIVE_POSTS]: subreddit => ({
+      subreddit,
+      posts: json.data.children.map(child => child.data),
+      recerivedAt: Date.now()
+    })
+  },
+  c.SELECT_SUBREDDIT,
+  c.INVALIDATE_SUBREDDIT,
+  c.REQUEST_POST
+);
+
+export default actions;

+ 8 - 0
src/index.js

@@ -0,0 +1,8 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+
+const title = <h2>Test setup</h2>;
+
+ReactDOM.render(<div>{title}</div>, document.getElementById('app'));
+
+module.hot.accept();

+ 2 - 0
src/reducers/index.js

@@ -0,0 +1,2 @@
+import * as c from '../actions/constants';
+import actions from '../actions/';

+ 39 - 0
webpack.config.js

@@ -0,0 +1,39 @@
+const webpack = require('webpack');
+
+module.exports = {
+  entry: [
+    'webpack-dev-server/client?http://localhost:8080',
+    'webpack/hot/only-dev-server',
+    'react-hot-loader/patch',
+    './src/index.js'
+  ],
+  module: {
+    loaders: [
+      {
+        test: /\.jsx?$/,
+        exclude: /node_modules/,
+        loaders: ['react-hot-loader/webpack', 'babel-loader']
+      }
+    ]
+  },
+  resolve: {
+    extensions: ['*', '.js', '.jsx']
+  },
+  output: {
+    path: __dirname + '/build',
+    publicPath: '/',
+    filename: 'bundle.js'
+  },
+  devServer: {
+    contentBase: './public',
+    hot: true
+  },
+  plugins: [
+    new webpack.optimize.ModuleConcatenationPlugin(),
+    new webpack.DefinePlugin({
+      'process.env': {
+        NODE_ENV: JSON.stringify('production')
+      }
+    })
+  ]
+};

File diff suppressed because it is too large
+ 5545 - 0
yarn.lock