26 |
27 |
28 | )
29 | }
30 | }
31 |
32 | export default Template
33 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 | TicTacTuring
17 |
18 |
19 |
20 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/config/env.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
4 | // injected into the application via DefinePlugin in Webpack configuration.
5 |
6 | var REACT_APP = /^REACT_APP_/i;
7 |
8 | function getClientEnvironment(publicUrl) {
9 | var raw = Object
10 | .keys(process.env)
11 | .filter(key => REACT_APP.test(key))
12 | .reduce((env, key) => {
13 | env[key] = process.env[key];
14 | return env;
15 | }, {
16 | // Useful for determining whether we’re running in production mode.
17 | // Most importantly, it switches React into the correct mode.
18 | 'NODE_ENV': process.env.NODE_ENV || 'development',
19 | // Useful for resolving the correct path to static assets in `public`.
20 | // For example, .
21 | // This should only be used as an escape hatch. Normally you would put
22 | // images into the `src` and `import` them in code to get their paths.
23 | 'PUBLIC_URL': publicUrl
24 | });
25 | // Stringify all values so we can feed into Webpack DefinePlugin
26 | var stringified = {
27 | 'process.env': Object
28 | .keys(raw)
29 | .reduce((env, key) => {
30 | env[key] = JSON.stringify(raw[key]);
31 | return env;
32 | }, {})
33 | };
34 |
35 | return { raw, stringified };
36 | }
37 |
38 | module.exports = getClientEnvironment;
39 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ticturing",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "material-ui": "^0.17.4",
7 | "react": "15.4.2",
8 | "react-dom": "15.4.2",
9 | "react-router": "3.0.2",
10 | "react-tap-event-plugin": "^2.0.1"
11 | },
12 | "devDependencies": {
13 | "autoprefixer": "6.7.2",
14 | "babel-core": "6.22.1",
15 | "babel-eslint": "7.1.1",
16 | "babel-jest": "18.0.0",
17 | "babel-loader": "6.2.10",
18 | "babel-plugin-react-relay": "^0.10.0",
19 | "babel-preset-react-app": "^2.2.0",
20 | "babel-runtime": "^6.20.0",
21 | "case-sensitive-paths-webpack-plugin": "1.1.4",
22 | "chalk": "1.1.3",
23 | "connect-history-api-fallback": "1.3.0",
24 | "cross-spawn": "4.0.2",
25 | "css-loader": "0.26.1",
26 | "detect-port": "1.1.0",
27 | "dotenv": "2.0.0",
28 | "eslint": "3.8.1",
29 | "eslint-config-react-app": "0.5.0",
30 | "eslint-loader": "1.6.0",
31 | "eslint-plugin-flowtype": "2.21.0",
32 | "eslint-plugin-import": "2.0.1",
33 | "eslint-plugin-jsx-a11y": "2.2.3",
34 | "eslint-plugin-react": "6.4.1",
35 | "extract-text-webpack-plugin": "1.0.1",
36 | "file-loader": "0.10.0",
37 | "fs-extra": "0.30.0",
38 | "html-webpack-plugin": "2.24.0",
39 | "http-proxy-middleware": "0.17.3",
40 | "jest": "17.0.2",
41 | "json-loader": "0.5.4",
42 | "object-assign": "4.1.1",
43 | "postcss-loader": "1.2.2",
44 | "promise": "7.1.1",
45 | "react-dev-utils": "0.4.2",
46 | "recursive-readdir": "2.1.0",
47 | "strip-ansi": "3.0.1",
48 | "style-loader": "0.13.1",
49 | "url-loader": "0.5.7",
50 | "webpack": "1.14.0",
51 | "webpack-dev-server": "1.16.2",
52 | "webpack-manifest-plugin": "1.1.0",
53 | "whatwg-fetch": "1.0.0"
54 | },
55 | "scripts": {
56 | "start": "GRAPHQL_ENDPOINT=https://api.graph.cool/relay/v1/cj1kws33p0gyh0165f43flbmp node scripts/start.js",
57 | "build": "GRAPHQL_ENDPOINT=https://api.graph.cool/relay/v1/cj1kws33p0gyh0165f43flbmp node scripts/build.js",
58 | "test": "node scripts/test.js --env=jsdom"
59 | },
60 | "jest": {
61 | "collectCoverageFrom": [
62 | "src/**/*.{js,jsx}"
63 | ],
64 | "setupFiles": [
65 | "/config/polyfills.js"
66 | ],
67 | "testPathIgnorePatterns": [
68 | "[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
69 | ],
70 | "testEnvironment": "node",
71 | "testURL": "http://localhost",
72 | "transform": {
73 | "^.+\\.(js|jsx)$": "/node_modules/babel-jest",
74 | "^.+\\.css$": "/config/jest/cssTransform.js",
75 | "^(?!.*\\.(js|jsx|css|json)$)": "/config/jest/fileTransform.js"
76 | },
77 | "transformIgnorePatterns": [
78 | "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
79 | ],
80 | "moduleNameMapper": {
81 | "^react-native$": "react-native-web"
82 | }
83 | },
84 | "babel": {
85 | "plugins": [
86 | "react-relay"
87 | ],
88 | "presets": [
89 | "react-app"
90 | ]
91 | },
92 | "eslintConfig": {
93 | "extends": "react-app"
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/config/paths.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var path = require('path');
4 | var fs = require('fs');
5 | var url = require('url');
6 |
7 | // Make sure any symlinks in the project folder are resolved:
8 | // https://github.com/facebookincubator/create-react-app/issues/637
9 | var appDirectory = fs.realpathSync(process.cwd());
10 | function resolveApp(relativePath) {
11 | return path.resolve(appDirectory, relativePath);
12 | }
13 |
14 | // We support resolving modules according to `NODE_PATH`.
15 | // This lets you use absolute paths in imports inside large monorepos:
16 | // https://github.com/facebookincubator/create-react-app/issues/253.
17 |
18 | // It works similar to `NODE_PATH` in Node itself:
19 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
20 |
21 | // We will export `nodePaths` as an array of absolute paths.
22 | // It will then be used by Webpack configs.
23 | // Jest doesn’t need this because it already handles `NODE_PATH` out of the box.
24 |
25 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
26 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
27 | // https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
28 |
29 | var nodePaths = (process.env.NODE_PATH || '')
30 | .split(process.platform === 'win32' ? ';' : ':')
31 | .filter(Boolean)
32 | .filter(folder => !path.isAbsolute(folder))
33 | .map(resolveApp);
34 |
35 | var envPublicUrl = process.env.PUBLIC_URL;
36 |
37 | function ensureSlash(path, needsSlash) {
38 | var hasSlash = path.endsWith('/');
39 | if (hasSlash && !needsSlash) {
40 | return path.substr(path, path.length - 1);
41 | } else if (!hasSlash && needsSlash) {
42 | return path + '/';
43 | } else {
44 | return path;
45 | }
46 | }
47 |
48 | function getPublicUrl(appPackageJson) {
49 | return envPublicUrl || require(appPackageJson).homepage;
50 | }
51 |
52 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer
53 | // "public path" at which the app is served.
54 | // Webpack needs to know it to put the right
888 | ```
889 |
890 | Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.**
891 |
892 | ## Running Tests
893 |
894 | >Note: this feature is available with `react-scripts@0.3.0` and higher.
895 | >[Read the migration guide to learn how to enable it in older projects!](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md#migrating-from-023-to-030)
896 |
897 | Create React App uses [Jest](https://facebook.github.io/jest/) as its test runner. To prepare for this integration, we did a [major revamp](https://facebook.github.io/jest/blog/2016/09/01/jest-15.html) of Jest so if you heard bad things about it years ago, give it another try.
898 |
899 | Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser. This lets us enable fast iteration speed and prevent flakiness.
900 |
901 | While Jest provides browser globals such as `window` thanks to [jsdom](https://github.com/tmpvar/jsdom), they are only approximations of the real browser behavior. Jest is intended to be used for unit tests of your logic and your components rather than the DOM quirks.
902 |
903 | We recommend that you use a separate tool for browser end-to-end tests if you need them. They are beyond the scope of Create React App.
904 |
905 | ### Filename Conventions
906 |
907 | Jest will look for test files with any of the following popular naming conventions:
908 |
909 | * Files with `.js` suffix in `__tests__` folders.
910 | * Files with `.test.js` suffix.
911 | * Files with `.spec.js` suffix.
912 |
913 | The `.test.js` / `.spec.js` files (or the `__tests__` folders) can be located at any depth under the `src` top level folder.
914 |
915 | We recommend to put the test files (or `__tests__` folders) next to the code they are testing so that relative imports appear shorter. For example, if `App.test.js` and `App.js` are in the same folder, the test just needs to `import App from './App'` instead of a long relative path. Colocation also helps find tests more quickly in larger projects.
916 |
917 | ### Command Line Interface
918 |
919 | When you run `npm test`, Jest will launch in the watch mode. Every time you save a file, it will re-run the tests, just like `npm start` recompiles the code.
920 |
921 | The watcher includes an interactive command-line interface with the ability to run all tests, or focus on a search pattern. It is designed this way so that you can keep it open and enjoy fast re-runs. You can learn the commands from the “Watch Usage” note that the watcher prints after every run:
922 |
923 | 
924 |
925 | ### Version Control Integration
926 |
927 | By default, when you run `npm test`, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests runs fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests.
928 |
929 | Jest will always explicitly mention that it only ran tests related to the files changed since the last commit. You can also press `a` in the watch mode to force Jest to run all tests.
930 |
931 | Jest will always run all tests on a [continuous integration](#continuous-integration) server or if the project is not inside a Git or Mercurial repository.
932 |
933 | ### Writing Tests
934 |
935 | To create tests, add `it()` (or `test()`) blocks with the name of the test and its code. You may optionally wrap them in `describe()` blocks for logical grouping but this is neither required nor recommended.
936 |
937 | Jest provides a built-in `expect()` global function for making assertions. A basic test could look like this:
938 |
939 | ```js
940 | import sum from './sum';
941 |
942 | it('sums numbers', () => {
943 | expect(sum(1, 2)).toEqual(3);
944 | expect(sum(2, 2)).toEqual(4);
945 | });
946 | ```
947 |
948 | All `expect()` matchers supported by Jest are [extensively documented here](http://facebook.github.io/jest/docs/expect.html).
949 | You can also use [`jest.fn()` and `expect(fn).toBeCalled()`](http://facebook.github.io/jest/docs/expect.html#tohavebeencalled) to create “spies” or mock functions.
950 |
951 | ### Testing Components
952 |
953 | There is a broad spectrum of component testing techniques. They range from a “smoke test” verifying that a component renders without throwing, to shallow rendering and testing some of the output, to full rendering and testing component lifecycle and state changes.
954 |
955 | Different projects choose different testing tradeoffs based on how often components change, and how much logic they contain. If you haven’t decided on a testing strategy yet, we recommend that you start with creating simple smoke tests for your components:
956 |
957 | ```js
958 | import React from 'react';
959 | import ReactDOM from 'react-dom';
960 | import App from './App';
961 |
962 | it('renders without crashing', () => {
963 | const div = document.createElement('div');
964 | ReactDOM.render(, div);
965 | });
966 | ```
967 |
968 | This test mounts a component and makes sure that it didn’t throw during rendering. Tests like this provide a lot value with very little effort so they are great as a starting point, and this is the test you will find in `src/App.test.js`.
969 |
970 | When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior.
971 |
972 | If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). You can write a smoke test with it too:
973 |
974 | ```sh
975 | npm install --save-dev enzyme react-addons-test-utils
976 | ```
977 |
978 | ```js
979 | import React from 'react';
980 | import { shallow } from 'enzyme';
981 | import App from './App';
982 |
983 | it('renders without crashing', () => {
984 | shallow();
985 | });
986 | ```
987 |
988 | Unlike the previous smoke test using `ReactDOM.render()`, this test only renders `` and doesn’t go deeper. For example, even if `` itself renders a `