Skip to content

Commit 7a3c959

Browse files
authored
Merge pull request #34 from piotrwitek/migrate-to-jest
Migrate to jest
2 parents d8d7b28 + 6a3d255 commit 7a3c959

File tree

22 files changed

+4147
-214
lines changed

22 files changed

+4147
-214
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ src/**/*.map
2929
node_modules
3030
jspm_packages
3131

32+
# Test snapshots
33+
__snapshots__
34+
3235
# Build directory
3336
dist
3437
temp

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
## _React v15.3 / Redux v3.6 / TypeScript v2.1_ - starter-kit
22
#### __React-Router v2.8 / Seamless-Immutable / JSPM (SystemJS & Rollup with tree-shaking)__
33

4-
> ##### Futuristic, bundle-free development environment for building _Component-Driven SPA with React, Redux and TypeScript_ - utilizing power of Static Type-checking, ES.Next, CSS-Modules, Hot-reload, in-browser transpilation, tree-shaking - powered by JSPM (SystemJS & Rollup with tree-shaking).
4+
> ##### Futuristic, bundle-free development environment for building _Component-Driven SPA with React, Redux and TypeScript_ - utilizing power of Static Type-checking, ES.Next, CSS-Modules, Hot-reload, in-browser transpilation, tree-shaking - powered by JSPM (SystemJS & Rollup with tree-shaking)
55
6-
### _Demo Page:_ http://piotrwitek.github.io/react-redux-typescript-starter-kit/
7-
### _Minimal React-like + Redux starter-kit EVER (13KB Min+Gzip):_ https://github.com/piotrwitek/preact-typescript-rollup-starter-kit
6+
**Demo Page:**
7+
*- http://piotrwitek.github.io/react-redux-typescript-starter-kit/*
8+
9+
**Check also minimal [Preact](https://github.com/developit/preact) + Redux starter-kit (13KB Min+Gzip):**
10+
*- https://github.com/piotrwitek/preact-typescript-rollup-starter-kit*
811

912
Table of Contents
1013
1. [Innovations](#innovations)
@@ -22,7 +25,7 @@ Table of Contents
2225

2326
### - RAPID-SPEED DEVELOPMENT WORKFLOW - no bundling!
2427
No bundling during development, instead loading source files (.ts/.tsx) directly in the browser (using [plugin-typescript](https://github.com/frankwallis/plugin-typescript)).
25-
When file changes - skipping type-checking (which is delegated to seperate process) and reloading only the changed file with hot-reload.
28+
When file changes - skipping type-checking (which is delegated to seperate process) and reloading only the changed file with hot-reload
2629

2730
### - DELEGATED TYPE-CHECKING
2831
Type-checking is delegated to a seperate process using following options:
@@ -35,20 +38,20 @@ __NOTE:__ There are two seperate __tsconfig__ - one for type-checking during dev
3538

3639
[tsconfig for building production bundle](https://github.com/piotrwitek/react-redux-typescript-starter-kit/blob/a00c1b5854c36ea4d31fa1255ce920134bfc3855/jspm.config.js#L129)
3740

41+
### - STRICT NULL CHECKS - Enabled
42+
Enabled strictNullChecks with noImplicitAny tsc flags, to increase type safety and grant better tooling support using Non-nullable Types (v2.0) and Smarter Type Inference (v2.1) [Source](https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/)
43+
3844
### - HOT-RELOAD THAT SCALE
3945
Local dev server with hot-reloading out-of-the-box (using [systemjs-hot-reloader](https://github.com/capaj/systemjs-hot-reloader)).
40-
__How:__ Loading each module separately and using SystemJS module registry, on changes it's removing old module from registry and re-importing updated one then re-evaluating only those modules that was importing the changed module.
46+
__How:__ Loading each module separately and using SystemJS module registry, on changes it's removing old module from registry and re-importing updated one then re-evaluating only those modules that was importing the changed module
4147

42-
__Scale well with increasing modules count because you reload only modules that has changed.__
48+
__Great scaling capability with increasing module count because you reload single module files that has changed without rebuilding anything.__
4349
> __Differences with Webpack workflow explained__ from real project perspective by [@jonaskello](https://github.com/jonaskello) https://github.com/Microsoft/TypeScript/issues/1564#issuecomment-252903932
4450
4551
### - CLI WORKFLOW
4652
Most often your team is using different Editors/IDE's so you'll need to have a common way to run type-checking using a specific version of TypeScript compiler for consistent results and avoid Editor specific issues.
4753
Run `tsc -p src --watch` command for quick incremental type-checking or `tsc -p src` command for one-time complete check (JS emit is disabled to not clutter your project with intermediate JS files)
4854

49-
### - STRICT NULL CHECKS - Enabled
50-
Enabled strictNullChecks with noImplicitAny tsc flags, to increase type safety and grant better tooling support using Non-nullable Types (v2.0) and Smarter Type Inference (v2.1) [Source](https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/)
51-
5255
### - ASYNC/AWAIT/GENERATORS transformation when targeting ES5 (No Babel)
5356
Support for "async & generator functions" when targeting ES5 __without Babel!__
5457
- Async/Await - TypeScript v2.1 provide native support for ES5 transformation (https://github.com/Microsoft/TypeScript/pull/9175)
@@ -59,7 +62,11 @@ __Until then use an alternative solution covered below:__
5962

6063
[Facebook Regenerator Project](https://github.com/facebook/regenerator) instead of __Babel__ to transform Generator Functions. _(NOTE: Internally **Babel** is also running "regenerator runtime" for async and generator functions transformations - https://babeljs.io/docs/usage/caveats/)_
6164

62-
> When building for production use `npm run regenerator` command after completion of build step, this will run "regenerator" on app.js bundle. Alternatively use `npm run build:regenerator` command to automatically run "regenerator" with each production build.
65+
> When building for production use `npm run regenerator` command after completion of build step, this will run "regenerator" on app.js bundle. Alternatively use `npm run build:regenerator` command to automatically run "regenerator" with each production build
66+
67+
### - TESTING WITH TYPESCRIPT
68+
- Writing and running tests in TypeScript runtime using source files, abstracting complicated setups and transpilation complexity (use `npm test` CLI command)
69+
- Test harness using [jest](https://github.com/facebook/jest)
6370

6471
### - CSS-MODULES WITH TYPED CLASS-NAMES EXPERIMENT
6572
Locally scoped CSS styles, encapsulated as ES6 Modules that can be imported in UI components, with capability to type-check CSS class-names in your components using interfaces and leverage TypeScript IntelliSense features in Editor/IDE (using [csjs](https://github.com/rtsao/csjs#faq)):
@@ -72,7 +79,7 @@ __DEMO:__ http://piotrwitek.github.io/react-redux-typescript-starter-kit/#/css-m
7279

7380
### - Optimized JSPM (SystemJS) loading speed
7481
To speed up a full page reload by minimizing request count it is possible to create a development "vendor bundle" for external dependencies loaded from node_modules.
75-
If not leveraging HTTP/2, it is a best practice to bundle all external dependencies together and load as a one bundle.
82+
If not leveraging HTTP/2, it is a best practice to bundle all external dependencies together and load as a one bundle
7683

7784
Test reload speed improvement using this simple test procedure:
7885
1. run `npm run unbundle` -> open network tab in chrome dev tools -> reload the page -> check logged results
@@ -82,14 +89,12 @@ Test reload speed improvement using this simple test procedure:
8289

8390
## Features
8491

85-
- PRODUCTION-WORKFLOW - npm scripts for production bundling & deployment, github-hooks, linter, test runner etc.
92+
- PRODUCTION-WORKFLOW - cross-platform npm scripts for production bundling & deployment, github-hooks, linter, test runner etc.
8693
- TYPESAFE-API-CALLS - type checking contracts of REST API calls - forget constantly checking for API docs and let your IDE guide you
8794
- REACT-ROUTER - included `react-router-redux` to store your routing in state for Time-Travel capabilities
8895
- REDUX-DEV-TOOLS - installed Redux DevTools capabilities with [chrome-extension](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd)
8996
- IMMUTABLE-STORE - using `seamless-immutable` for simplicity and backwards-compatibility with vanilla JS (no hassle with `toJS()`, `get()`, `getIn()` in your containers and components)
9097
- BEM & ITCSS - using BEM with Inverted Triangle conventions to give meaning and context to CSS classes
91-
- TESTING IN TYPESCRIPT - writing and running tests from TypeScript source files without transpilation complexity (use `npm test` CLI command) - test harness using [tape](https://github.com/substack/tape) and [blue-tape](https://github.com/spion/blue-tape).
92-
- Type-safe React-Redux with TypeScript
9398

9499
#### React Best Practices & Optimizations
95100
- no mixins -> use ES6 style PureRenderMixin with PureComponent
@@ -140,12 +145,11 @@ Test reload speed improvement using this simple test procedure:
140145
│ ├── components # global reusable presentational components
141146
│ ├── containers # container components providing redux context
142147
│ ├── layouts # components defining page layouts
143-
│ ├── store # modules containing redux modules (reducers/constants/action creators)
144148
│ ├── services # modules abstracting communication with web services
149+
│ ├── store # modules containing redux modules (reducers/constants/action creators)
145150
│ ├── types # custom TypeScript definitions
146151
│ ├── utils # app utility modules
147152
│ ├── app.tsx # app entry module with routing config
148-
│ ├── test-runner.tsx # test suites config
149153
│ └── tsconfig.tsx # TypeScript compiler config
150154
├── index.html # index.html
151155
├── index.prod.html # index.html configured for production use
@@ -169,6 +173,9 @@ git clone https://github.com/piotrwitek/react-redux-typescript-starter-kit.git m
169173
// Install dependencies
170174
npm install
171175
176+
// Initiate JSPM and dev-bundle
177+
npm init
178+
172179
// Run development server with HMR
173180
npm start
174181
```
@@ -227,13 +234,15 @@ __NOTE: Use index.prod.html for production, it have slightly different loading l
227234

228235
#### Deployment
229236

237+
`npm run init` - install jspm packages and prebuilds vendor.dev.js bundle
238+
230239
`npm run init:deploy` - clone git repository in `/dist` folder (gh-pages branch)
231240

232241
`npm run deploy` - commit and push all changes found in `/dist` folder
233242

234243
#### Utility & Git Hooks
235244

236-
`npm run clean` - clean dist folder
245+
`npm run clean` - clean dist, node_modules, jspm_packages folder
237246

238247
`npm run lint` - run linter
239248

jest.config.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"automock": false,
3+
"moduleFileExtensions": [
4+
"ts",
5+
"tsx",
6+
"js"
7+
],
8+
"unmockedModulePathPatterns": [
9+
"<rootDir>/node_modules/react",
10+
"<rootDir>/node_modules/react-redux",
11+
"<rootDir>/node_modules/react-dom",
12+
"<rootDir>/node_modules/react-addons-test-utils",
13+
"<rootDir>/node_modules/fbjs"
14+
],
15+
"transform": {
16+
"^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
17+
},
18+
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
19+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
20+
"notify": false,
21+
"verbose": true,
22+
"globals": {
23+
"window": {},
24+
"__TS_CONFIG__": "<rootDir>/src/tsconfig.json"
25+
}
26+
}

jspm.config.js

Lines changed: 8 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SystemJS.config({
1212
"plugin-typescript": "github:frankwallis/plugin-typescript@5.2.9",
1313
"css": "github:systemjs/plugin-css@0.1.32",
1414
"systemjs-hot-reloader": "github:capaj/systemjs-hot-reloader@0.6.0",
15-
"blue-tape": "npm:blue-tape@0.2.0"
15+
"tslib": "npm:tslib@1.2.0"
1616
},
1717
"packages": {
1818
"github:capaj/systemjs-hot-reloader@0.6.0": {
@@ -22,97 +22,6 @@ SystemJS.config({
2222
"socket.io-client": "github:socketio/socket.io-client@1.5.1"
2323
}
2424
},
25-
"npm:blue-tape@0.2.0": {
26-
"map": {
27-
"tape": "npm:tape@4.6.2"
28-
}
29-
},
30-
"npm:resumer@0.0.0": {
31-
"map": {
32-
"through": "npm:through@2.3.8"
33-
}
34-
},
35-
"npm:string.prototype.trim@1.1.2": {
36-
"map": {
37-
"function-bind": "npm:function-bind@1.1.0",
38-
"es-abstract": "npm:es-abstract@1.6.1",
39-
"define-properties": "npm:define-properties@1.1.2"
40-
}
41-
},
42-
"npm:es-abstract@1.6.1": {
43-
"map": {
44-
"function-bind": "npm:function-bind@1.1.0",
45-
"es-to-primitive": "npm:es-to-primitive@1.1.1",
46-
"is-callable": "npm:is-callable@1.1.3",
47-
"is-regex": "npm:is-regex@1.0.3"
48-
}
49-
},
50-
"npm:has@1.0.1": {
51-
"map": {
52-
"function-bind": "npm:function-bind@1.1.0"
53-
}
54-
},
55-
"npm:es-to-primitive@1.1.1": {
56-
"map": {
57-
"is-callable": "npm:is-callable@1.1.3",
58-
"is-date-object": "npm:is-date-object@1.0.1",
59-
"is-symbol": "npm:is-symbol@1.0.1"
60-
}
61-
},
62-
"npm:define-properties@1.1.2": {
63-
"map": {
64-
"object-keys": "npm:object-keys@1.0.11",
65-
"foreach": "npm:foreach@2.0.5"
66-
}
67-
},
68-
"npm:minimatch@3.0.3": {
69-
"map": {
70-
"brace-expansion": "npm:brace-expansion@1.1.6"
71-
}
72-
},
73-
"npm:brace-expansion@1.1.6": {
74-
"map": {
75-
"balanced-match": "npm:balanced-match@0.4.2",
76-
"concat-map": "npm:concat-map@0.0.1"
77-
}
78-
},
79-
"npm:once@1.4.0": {
80-
"map": {
81-
"wrappy": "npm:wrappy@1.0.2"
82-
}
83-
},
84-
"npm:tape@4.6.2": {
85-
"map": {
86-
"inherits": "npm:inherits@2.0.3",
87-
"glob": "npm:glob@7.1.1",
88-
"deep-equal": "npm:deep-equal@1.0.1",
89-
"through": "npm:through@2.3.8",
90-
"function-bind": "npm:function-bind@1.1.0",
91-
"resumer": "npm:resumer@0.0.0",
92-
"minimist": "npm:minimist@1.2.0",
93-
"object-inspect": "npm:object-inspect@1.2.1",
94-
"resolve": "npm:resolve@1.1.7",
95-
"string.prototype.trim": "npm:string.prototype.trim@1.1.2",
96-
"defined": "npm:defined@1.0.0",
97-
"has": "npm:has@1.0.1"
98-
}
99-
},
100-
"npm:glob@7.1.1": {
101-
"map": {
102-
"inherits": "npm:inherits@2.0.3",
103-
"minimatch": "npm:minimatch@3.0.3",
104-
"fs.realpath": "npm:fs.realpath@1.0.0",
105-
"path-is-absolute": "npm:path-is-absolute@1.0.1",
106-
"once": "npm:once@1.4.0",
107-
"inflight": "npm:inflight@1.0.6"
108-
}
109-
},
110-
"npm:inflight@1.0.6": {
111-
"map": {
112-
"once": "npm:once@1.4.0",
113-
"wrappy": "npm:wrappy@1.0.2"
114-
}
115-
},
11625
"npm:debug@2.3.2": {
11726
"map": {
11827
"ms": "npm:ms@0.7.2"
@@ -137,6 +46,8 @@ SystemJS.config({
13746
},
13847
transpiler: "plugin-typescript",
13948
typescriptOptions: {
49+
"tsconfig": false,
50+
"typeCheck": false,
14051
"module": "system",
14152
"target": "es5",
14253
"emitDecoratorMetadata": true,
@@ -145,8 +56,10 @@ SystemJS.config({
14556
"moduleResolution": "node",
14657
"preserveConstEnums": true,
14758
"removeComments": true,
148-
"typeCheck": false,
149-
"tsconfig": false
59+
"noEmitHelpers": false,
60+
"importHelpers": false,
61+
"allowSyntheticDefaultImports": true,
62+
"sourceMap": true
15063
},
15164
packages: {
15265
"app": {
@@ -552,4 +465,4 @@ SystemJS.config({
552465
}
553466
}
554467
}
555-
});
468+
});

package.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,51 @@
99
"license": "MIT",
1010
"main": "server.js",
1111
"scripts": {
12-
"postinstall": "jspm install && npm run build:dev",
13-
"clean": "node scripts/clean.js",
12+
"clean": "shx rm -rf dist node_modules jspm_packages",
13+
"init": "jspm install && npm run build:dev",
1414
"init:deploy": "node scripts/init.js deploy",
1515
"deploy": "cd dist && git checkout gh-pages && git add --all && git commit -m \"New Release\" && git push",
16-
"precommit": "npm run lint",
17-
"prepush": "npm run lint && npm test",
16+
"precommit": "npm run lint && npm run tsc",
17+
"prepush": "npm run precommit && npm test",
1818
"preversion": "npm run lint && npm test",
19-
"unbundle": "rimraf temp/vendor.dev.js",
19+
"unbundle": "shx rm temp/vendor.dev.js",
2020
"build": "npm run build:app && npm run build:vendor",
2121
"build:app": "node scripts/build.js app",
2222
"build:vendor": "node scripts/build.js vendor",
2323
"build:dev": "node scripts/build.js dev",
2424
"build:debug": "node scripts/build.js debug",
2525
"bad": "npm run build:app && npm run deploy",
2626
"bvd": "npm run build:vendor && npm run deploy",
27-
"lint": "tslint ./src/**/*.ts[x]",
28-
"test": "jspm run src/test-runner | faucet",
27+
"lint": "tslint 'src/**/*.ts[x]'",
2928
"tsc": "tsc -p src",
3029
"tsc:watch": "tsc -p src -w",
30+
"test": "jest --config ./jest.config.json",
31+
"test:update": "jest -u --config ./jest.config.json",
3132
"regenerator": "node scripts/regenerator.js",
3233
"build:regenerator": "npm run build:app && npm run regenerator"
3334
},
3435
"devDependencies": {
35-
"@types/blue-tape": "^0.1.30",
3636
"@types/classnames": "^0.0.32",
37+
"@types/jest": "^16.0.1",
3738
"@types/react": "^0.14.43",
3839
"@types/react-dom": "^0.14.11",
3940
"@types/react-redux": "^4.4.32",
4041
"@types/react-router": "^2.0.39",
4142
"@types/react-router-redux": "^4.0.34",
42-
"@types/redux": "^3.6.31",
4343
"@types/redux-actions": "^0.8.32",
4444
"@types/seamless-immutable": "^6.1.2",
45-
"@types/tape": "^4.2.28",
45+
"@types/systemjs": "^0.19.32",
4646
"@types/whatwg-fetch": "^0.0.32",
47-
"faucet": "^0.0.1",
4847
"husky": "^0.11.8",
48+
"jest": "^17.0.3",
4949
"jspm": "^0.17.0-beta.32",
5050
"jspm-hmr": "^0.5.0",
51-
"regenerator": "^0.8.46",
52-
"rimraf": "^2.5.4",
51+
"regenerator": "^0.9.5",
5352
"shelljs": "^0.7.5",
54-
"tslint": "^3.15.1",
55-
"typescript": "^2.1.1"
53+
"shx": "^0.2.1",
54+
"ts-jest": "^17.0.3",
55+
"tslint": "^4.0.2",
56+
"typescript": "^2.1.4"
5657
},
5758
"jspm": {
5859
"name": "app",
@@ -70,10 +71,10 @@
7071
"whatwg-fetch": "npm:whatwg-fetch@^1.1.0"
7172
},
7273
"devDependencies": {
73-
"blue-tape": "npm:blue-tape@^0.2.0",
7474
"css": "github:systemjs/plugin-css@^0.1.32",
7575
"plugin-typescript": "github:frankwallis/plugin-typescript@^5.2.9",
76-
"systemjs-hot-reloader": "github:capaj/systemjs-hot-reloader@^0.6.0"
76+
"systemjs-hot-reloader": "github:capaj/systemjs-hot-reloader@^0.6.0",
77+
"tslib": "npm:tslib@^1.2.0"
7778
},
7879
"peerDependencies": {
7980
"assert": "npm:jspm-nodelibs-assert@^0.2.0",

scripts/clean.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ function App() {
2828
}
2929

3030
export const app = ReactDOM.render(
31-
<App />, document.getElementById('app-container')
31+
<App />, document.getElementById('app-container'),
3232
);

0 commit comments

Comments
 (0)