Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
25 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
## Code Quality Check | ||
|
||
Rekit uses ESlint for code quality check. And uses [airbnb javascript guide](https://github.com/airbnb/javascript) as the basic rules for all codes. There are slight changes defined in `.eslintrc` for different parts of a Rekit application. | ||
|
||
Because it seems the rules suggested airbnb often change. There may be some eslint errors for a new created Rekit application. You need to either update the code or adding your own rules to clear those errors. | ||
Rekit uses ESlint for code quality check. It's the sames create-react-app. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
## Examples | ||
Below are real-world apps created with Rekit, you can look at them for reference: | ||
|
||
1. [Rekit portal](https://github.com/supnate/rekit-portal): the Rekit dev tool shipped with Rekit 2.0, it's built with Rekit so it's also a good example. | ||
1. [Rekit Studio](https://github.com/supnate/rekit): the Rekit IDE shipped with Rekit 2.2, it's built with Rekit so it's also a good example. | ||
2. [Command pad](https://github.com/supnate/command-pad): a handy GUI tool for managing command line tasks, built with [Electron](http://electron.atom.io) and Rekit 1.0. | ||
3. [Simple forum](https://github.com/supnate/rekit-example): a simple forum application built with Rekit 1.0. It connects to a real backend server powered by [Leancloud.cn](https://leancloud.cn)( a SaaS service). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,5 @@ | ||
## Testing | ||
|
||
Testing a React + Redux application is difficult, you need to know many libs/tools regarding React testing and learn their usage. But Rekit will setup everything for you. You just need to write test code in the auto generated test files, running test with Rekit Studio and reading the coverage report in a browser. | ||
From version 2.3.0, Rekit starts to use jest for unit test since the boilerplate is created by create-react-app. You can see more introduction at: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests . | ||
|
||
However here is the process of how React testing works. You can know how Rekit setups the testing process. | ||
|
||
1. [Istanbul](https://github.com/gotwarlost/istanbul) instruments the source code for test coverage report. Istanbul itself doesn't support JSX, but there's a babel plugin [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) then it works. | ||
2. Webpack builds all testing files with [mocha-webpack](https://github.com/zinserjan/mocha-webpack) which auto finds test files to test. | ||
3. [Mocha](https://github.com/mochajs/mocha) runs the built version of testing files. | ||
4. [nyc](https://github.com/istanbuljs/nyc) generates the test coverage report. | ||
|
||
All app testing files are saved in the folder `test/app`. And the folder structure is the same with the source code folder structure in `src` folder. | ||
|
||
#### How Rekit generates testing files | ||
When creating a new component or action, Rekit auto creates test cases for them. Even you don't add any code to to the generated test cases, they help you avoid simple errors. Such as: | ||
|
||
1. It ensures a component is always rendered successfully by checking the existence of the root DOM node with correct css class. | ||
2. It ensures reducer is immutable by checking equality of the previous and new states. | ||
|
||
For example, when creating a new page, it generates below test case: | ||
```javascript | ||
it('renders node with correct class name', () => { | ||
const pageProps = { | ||
home: {}, | ||
actions: {}, | ||
}; | ||
const renderedComponent = shallow( | ||
<TestPage1 {...pageProps} /> | ||
); | ||
|
||
expect( | ||
renderedComponent.find('.home-test-page-1').node | ||
).to.exist; | ||
}); | ||
``` | ||
|
||
When creating an action, it generates below reducer test case: | ||
```javascript | ||
it('reducer should handle MY_ACTION', () => { | ||
const prevState = {}; | ||
const state = reducer( | ||
prevState, | ||
{ type: MY_ACTION } | ||
); | ||
expect(state).to.not.equal(prevState); // should be immutable | ||
expect(state).to.deep.equal(prevState); // TODO: replace this line with real case. | ||
}); | ||
``` | ||
|
||
#### Run tests | ||
As you may have noticed, test cases also need to be built with webpack, then Mocha could run the test cases. So running a single test case file also needs the build. So `tools/run_test.js` is created to simplify this process. You can run any test case file just by the `run_test.js` tool. It's also exported as `npm test`. All arguments to it is just passed to the `run_test.js` script. The usage is as below: | ||
``` | ||
npm test // run all tests of the project | ||
npm test features/home // run tests under the `home` feature | ||
npm test **/List.test.js // run all tests named list.test.js under app folder | ||
``` | ||
|
||
The script is under your project, so you can edit it for free to meet your own requirements. | ||
|
||
By default it does below things: | ||
|
||
1. Istanbul instruments the source code. | ||
2. Mocha runs the test cases. | ||
3. nyc generates the test coverage report. | ||
|
||
|
||
#### See the coverage report | ||
If tests are are run for the whole project then test coverage report will be generated at `coverage` folder. | ||
The only difference is Rekit save all test files under the folder `/tests` rather than along side with source files under `/src` folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,5 @@ | ||
## Bundling | ||
|
||
Webpack is also considered one of the most difficult parts for building a React application. Luckily again Rekit setups everything for you. There are 2 webpack config files corresponding to different usage: | ||
|
||
* `webpack.config.js`: it's a webpack config factory for dev, dll and dist bundling. | ||
* `webpack.test.config.js`: the config for test build. | ||
|
||
#### Boost the build performance by using webpack-dll-plugin | ||
When a React application grows large, the build time in dev time takes long time. The `webpack-dll-plugin` could resolve the problem. There's very few docs about it but there's a great article introducing it: http://engineering.invisionapp.com/post/optimizing-webpack/ . Rekit takes use the approach mentioned in the article. | ||
|
||
The basic idea is to build common libs such as React, Redux, React-router into a separate dll bundle. So that they don't need to be built every time your code is changed. By doing this the build time could be significantly reduced. | ||
|
||
Rekit integrates the process in `tools/server.js` which is run when calling `npm start`. The script checks versions of all packages needed for the dll build. So that it auto builds a new dll when any dependency version is changed. | ||
It's the same as create-react-app, see more info at: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment . | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters