From 1a6d5ea10526e0d16811d9406aa39dae0de309b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Rosiek?= Date: Sat, 17 Jun 2017 13:41:24 +0200 Subject: [PATCH 1/3] Added sample reducer tests for ReactRedux template --- .../ClientApp/store/Counter.spec.ts | 22 +++++++++++++++++++ templates/ReactReduxSpa/package.json | 18 +++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts diff --git a/templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts b/templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts new file mode 100644 index 00000000..b01dd54e --- /dev/null +++ b/templates/ReactReduxSpa/ClientApp/store/Counter.spec.ts @@ -0,0 +1,22 @@ +import 'jest'; +import { reducer } from './Counter'; + +describe('Coutner reducer', () => { + it('should handle initial state', () => { + expect(reducer(undefined, {} as any)).toEqual({ count: 0 }); + }); + + it('should handle INCREMENT_COUNT', () => { + expect(reducer( + { count: 0 }, + { type: 'INCREMENT_COUNT' })) + .toEqual({ count: 1 }); + }); + + it('should handle DECREMENT_COUNT', () => { + expect(reducer( + { count: 1 }, + { type: 'DECREMENT_COUNT' })) + .toEqual({ count: 0 }); + }); +}); \ No newline at end of file diff --git a/templates/ReactReduxSpa/package.json b/templates/ReactReduxSpa/package.json index 56edd57c..65b0fe32 100644 --- a/templates/ReactReduxSpa/package.json +++ b/templates/ReactReduxSpa/package.json @@ -1,8 +1,24 @@ { "name": "WebApplicationBasic", "version": "0.0.0", + "scripts": { + "test": "jest" + }, + "jest": { + "transform": { + ".(ts|tsx)": "/node_modules/ts-jest/preprocessor.js" + }, + "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "json" + ] + } "dependencies": { "@types/history": "4.5.1", + "@types/jest": "20.0.0", "@types/react": "15.0.24", "@types/react-dom": "15.5.0", "@types/react-redux": "4.4.40", @@ -21,6 +37,7 @@ "extract-text-webpack-plugin": "2.1.0", "file-loader": "0.11.1", "history": "4.6.1", + "jest": "20.0.4", "jquery": "3.2.1", "json-loader": "0.5.4", "node-noop": "1.0.0", @@ -33,6 +50,7 @@ "redux": "3.6.0", "redux-thunk": "2.2.0", "style-loader": "0.17.0", + "ts-jest": "20.0.6", "typescript": "2.3.2", "url-loader": "0.5.8", "webpack": "2.5.1", From 8bfb4f62f96a639f22a1375fa41abd9ee96fa7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Rosiek?= Date: Sat, 17 Jun 2017 13:44:26 +0200 Subject: [PATCH 2/3] Added missing comma --- templates/ReactReduxSpa/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/ReactReduxSpa/package.json b/templates/ReactReduxSpa/package.json index 65b0fe32..f82eab8c 100644 --- a/templates/ReactReduxSpa/package.json +++ b/templates/ReactReduxSpa/package.json @@ -15,7 +15,7 @@ "js", "json" ] - } + }, "dependencies": { "@types/history": "4.5.1", "@types/jest": "20.0.0", From 501cafa9526d071f026cd07fbf7f1783f9256f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Rosiek?= Date: Sat, 17 Jun 2017 14:44:20 +0200 Subject: [PATCH 3/3] Added option to create React-Redux project without tests --- templates/package-builder/src/yeoman/app/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/templates/package-builder/src/yeoman/app/index.ts b/templates/package-builder/src/yeoman/app/index.ts index fadda587..e9163c7d 100644 --- a/templates/package-builder/src/yeoman/app/index.ts +++ b/templates/package-builder/src/yeoman/app/index.ts @@ -22,14 +22,17 @@ const testSpecificPaths = [ const testSpecificNpmPackages = [ "@types/chai", "@types/jasmine", + "@types/jest", "chai", "jasmine-core", + "jest", "karma", "karma-chai", "karma-chrome-launcher", "karma-cli", "karma-jasmine", - "karma-webpack" + "karma-webpack", + "ts-jest" ]; type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void; @@ -47,7 +50,7 @@ const templates: TemplateConfig[] = [ { value: 'aurelia', rootDir: 'aurelia', name: 'Aurelia', tests: false }, { value: 'knockout', rootDir: 'knockout', name: 'Knockout', tests: false }, { value: 'react', rootDir: 'react', name: 'React', tests: false }, - { value: 'react-redux', rootDir: 'react-redux', name: 'React with Redux', tests: false }, + { value: 'react-redux', rootDir: 'react-redux', name: 'React with Redux', tests: true }, { value: 'vue', rootDir: 'vue', name: 'Vue', tests: false } ]; @@ -247,6 +250,12 @@ function rewritePackageJson(contents, includeTests) { delete contents.scripts; } } + + // Delete 'jest' section + const jest = contents.jest; + if (jest) { + delete contents.jest; + } } return contents;