From 5f91d04525b4ea4517a8c70751f5c8b69129267a Mon Sep 17 00:00:00 2001 From: tjaskula Date: Mon, 12 Feb 2018 13:45:39 +0100 Subject: [PATCH 1/7] Updating typescript dependencies to --latest --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ab014b5..738c722 100644 --- a/package.json +++ b/package.json @@ -47,14 +47,14 @@ }, "devDependencies": { "@types/history": "4.6.2", - "@types/react": "16.0.36", - "@types/react-dom": "16.0.3", - "@types/react-hot-loader": "3.0.5", - "@types/react-redux": "5.0.14", - "@types/react-router": "4.0.21", - "@types/react-router-dom": "4.2.3", - "@types/react-router-redux": "5.0.11", - "@types/webpack": "3.8.5", + "@types/react": "16.0.38", + "@types/react-dom": "16.0.4", + "@types/react-hot-loader": "3.0.6", + "@types/react-redux": "5.0.15", + "@types/react-router": "4.0.22", + "@types/react-router-dom": "4.2.4", + "@types/react-router-redux": "5.0.12", + "@types/webpack": "3.8.8", "@types/webpack-env": "1.13.5", "aspnet-prerendering": "^3.0.1", "aspnet-webpack": "^2.0.3", From 963fe6da17667ae6e27c544b71d0bf1a9cf2597c Mon Sep 17 00:00:00 2001 From: tjaskula Date: Tue, 13 Feb 2018 13:56:34 +0100 Subject: [PATCH 2/7] Add ts-jest and @types/jest dependencies and enabling jest configuration --- package.json | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 738c722..ce6a9f1 100644 --- a/package.json +++ b/package.json @@ -12,41 +12,23 @@ "build:debug": "node run build --debug" }, "jest": { - "collectCoverageFrom": [ - "src/**/*.{js,jsx,mjs}" - ], - "setupFiles": [ - "/config/polyfills.js" - ], - "testMatch": [ - "/src/**/__tests__/**/*.{js,jsx,mjs}", - "/src/**/?(*.)(spec|test).{js,jsx,mjs}" - ], - "testEnvironment": "node", - "testURL": "http://localhost", "transform": { - "^.+\\.(js|jsx|mjs)$": "/node_modules/babel-jest", - "^.+\\.css$": "/config/jest/cssTransform.js", - "^(?!.*\\.(js|jsx|mjs|css|json)$)": "/config/jest/fileTransform.js" - }, - "transformIgnorePatterns": [ - "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$" - ], - "moduleNameMapper": { - "^react-native$": "react-native-web" + "^.+\\.(t|j)sx?$": "ts-jest" }, + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ - "web.js", - "mjs", + "ts", + "tsx", "js", - "json", - "web.jsx", "jsx", + "json", "node" - ] + ], + "mapCoverage": true }, "devDependencies": { "@types/history": "4.6.2", + "@types/jest": "^22.1.3", "@types/react": "16.0.38", "@types/react-dom": "16.0.4", "@types/react-hot-loader": "3.0.6", @@ -102,6 +84,7 @@ "redux": "3.7.2", "redux-thunk": "2.2.0", "style-loader": "0.20.1", + "ts-jest": "^22.0.4", "typescript": "2.7.1", "url-loader": "0.6.2", "webpack": "3.10.0", From a40ca65dff57a9a2f64db21476a9d35a4b7169eb Mon Sep 17 00:00:00 2001 From: tjaskula Date: Thu, 15 Feb 2018 16:05:18 +0100 Subject: [PATCH 3/7] Add example unit test, configuration for jest and script file. Related to Luteceo/aspnet-starter-kit-2.0#4 --- client/examples/Hello.test.ts | 10 ++++++++++ client/examples/Hello.ts | 28 ++++++++++++++++++++++++++++ package.json | 15 ++++++++++++--- scripts/test.js | 27 +++++++++++++++++++++++++++ tsconfig.json | 3 ++- 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 client/examples/Hello.test.ts create mode 100644 client/examples/Hello.ts create mode 100644 scripts/test.js diff --git a/client/examples/Hello.test.ts b/client/examples/Hello.test.ts new file mode 100644 index 0000000..2a48e36 --- /dev/null +++ b/client/examples/Hello.test.ts @@ -0,0 +1,10 @@ +declare var jest, describe, it, expect; + +import { Hello } from './Hello'; + +describe('Hello Class', () => { + it('should throw an error', () => { + expect.assertions(1); + expect(() => new Hello()).toThrowError('Hello error!') + }); +}); \ No newline at end of file diff --git a/client/examples/Hello.ts b/client/examples/Hello.ts new file mode 100644 index 0000000..ee7b947 --- /dev/null +++ b/client/examples/Hello.ts @@ -0,0 +1,28 @@ +interface FooInterface { + foo: string; + bar: number; //This interface should be stripped and the line numbers should still fit. + } + + export class Hello { + constructor() { + const greeting = ` + this + is + a + multiline + greeting + `; + + this.unexcuted(() => {}); + + throw new Error('Hello error!'); + } + + public unexcuted(action: () => void = () => {}): void { + if (action) { + action(); + } else { + console.log('unexcuted'); + } + } + } \ No newline at end of file diff --git a/package.json b/package.json index ce6a9f1..9764af5 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "scripts": { "postinstall": "dotnet restore server", "start": "node run", + "test": "node scripts/test.js --env=jsdom", + "tslint": "tslint client/*.ts", "build": "node run build", "build:debug": "node run build --debug" }, @@ -15,7 +17,14 @@ "transform": { "^.+\\.(t|j)sx?$": "ts-jest" }, - "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "collectCoverageFrom": [ + "client/**/*.{js,ts,jsx,tsx,mjs}" + ], + "mapCoverage": true, + "testMatch": [ + "/client/**/__tests__/**/*.{js,ts,jsx,tsx,mjs}", + "/client/**/?(*.)(spec|test).{js,ts,jsx,tsx,mjs}" + ], "moduleFileExtensions": [ "ts", "tsx", @@ -23,8 +32,7 @@ "jsx", "json", "node" - ], - "mapCoverage": true + ] }, "devDependencies": { "@types/history": "4.6.2", @@ -85,6 +93,7 @@ "redux-thunk": "2.2.0", "style-loader": "0.20.1", "ts-jest": "^22.0.4", + "tslint": "^5.9.1", "typescript": "2.7.1", "url-loader": "0.6.2", "webpack": "3.10.0", diff --git a/scripts/test.js b/scripts/test.js new file mode 100644 index 0000000..6461a7f --- /dev/null +++ b/scripts/test.js @@ -0,0 +1,27 @@ +'use strict'; + +// Do this as the first thing so that any code reading it knows the right env. +process.env.BABEL_ENV = 'test'; +process.env.NODE_ENV = 'test'; +process.env.PUBLIC_URL = ''; + +// Makes the script crash on unhandled rejections instead of silently +// ignoring them. In the future, promise rejections that are not handled will +// terminate the Node.js process with a non-zero exit code. +process.on('unhandledRejection', err => { + throw err; +}); + +// Ensure environment variables are read. +// require('../config/env'); + +const jest = require('jest'); +const argv = process.argv.slice(2); + +// Watch unless on CI or in coverage mode +if (!process.env.CI && argv.indexOf('--coverage') < 0) { + argv.push('--watch'); +} + + +jest.run(argv); diff --git a/tsconfig.json b/tsconfig.json index 7909f2d..b837dbb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,8 @@ "skipDefaultLibCheck": true, "strict": true, "lib": ["es6", "dom"], - "types": ["webpack-env"] + "types": ["webpack-env"], + "noImplicitAny": false }, "exclude": [ "bin", From 67f976de8f00e33988fae67a9c001e44f3f63112 Mon Sep 17 00:00:00 2001 From: tjaskula Date: Fri, 16 Feb 2018 09:20:08 +0100 Subject: [PATCH 4/7] Disable Eslint for webpack and run.js scripts --- run.js | 1 + webpack.config.js | 2 +- webpack.config.vendor.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/run.js b/run.js index 06532a9..f749c53 100644 --- a/run.js +++ b/run.js @@ -1,3 +1,4 @@ +/* eslint-disable */ const fs = require('fs'); const del = require('del'); const cpy = require('cpy'); diff --git a/webpack.config.js b/webpack.config.js index e2274cd..438491a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,10 +1,10 @@ +/* eslint-disable */ const path = require('path'); const webpack = require('webpack'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; const merge = require('webpack-merge'); -/* eslint-disable global-require */ const isDebug = global.DEBUG === false ? false : !process.argv.includes('--release'); const config = (isDebug) => { diff --git a/webpack.config.vendor.js b/webpack.config.vendor.js index d2ce503..194b9ef 100644 --- a/webpack.config.vendor.js +++ b/webpack.config.vendor.js @@ -1,9 +1,9 @@ +/* eslint-disable */ const path = require('path'); const webpack = require('webpack'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); const merge = require('webpack-merge'); -/* eslint-disable global-require */ const isDebug = global.DEBUG === false ? false : !process.argv.includes('--release'); const config = (isDebug) => { From 145f0c3210484f9c793a9010a71828f2f0937597 Mon Sep 17 00:00:00 2001 From: tjaskula Date: Sat, 17 Feb 2018 10:16:35 +0100 Subject: [PATCH 5/7] Delete script/tests.js and moving code into run.js 'test' scripts. Resolves Luteceo/aspnet-starter-kit-2.0#4 --- package.json | 2 +- run.js | 37 +++++++++++++++++++++++++++++++++++++ scripts/test.js | 27 --------------------------- 3 files changed, 38 insertions(+), 28 deletions(-) delete mode 100644 scripts/test.js diff --git a/package.json b/package.json index 9764af5..611f0c4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "postinstall": "dotnet restore server", "start": "node run", - "test": "node scripts/test.js --env=jsdom", + "test": "node run test --env=jsdom", "tslint": "tslint client/*.ts", "build": "node run build", "build:debug": "node run build --debug" diff --git a/run.js b/run.js index f749c53..aa18355 100644 --- a/run.js +++ b/run.js @@ -69,6 +69,43 @@ tasks.set('build', () => { })); }); + +// +// Run tests +// ----------------------------------------------------------------------------- +tasks.set('test', () => { + // Do this as the first thing so that any code reading it knows the right env. + process.env.BABEL_ENV = 'test'; + process.env.NODE_ENV = 'test'; + process.env.PUBLIC_URL = ''; + return Promise.resolve() + //.then(() => run('clean')) + //.then(() => run('bundle')) + //.then(() => run('copy')) + //.then(() => run('appsettings')) + .then(() => new Promise((resolve, reject) => { + // Makes the script crash on unhandled rejections instead of silently + // ignoring them. In the future, promise rejections that are not handled will + // terminate the Node.js process with a non-zero exit code. + process.on('unhandledRejection', err => { + throw err; + }); + + // Ensure environment variables are read. + // require('../config/env'); + + const jest = require('jest'); + const argv = process.argv.slice(2); + + // Watch unless on CI or in coverage mode + if (!process.env.CI && argv.indexOf('--coverage') < 0) { + argv.push('--watch'); + } + + jest.run(argv); + })); +}); + // // Build website and launch it in a browser for testing in watch mode // ----------------------------------------------------------------------------- diff --git a/scripts/test.js b/scripts/test.js deleted file mode 100644 index 6461a7f..0000000 --- a/scripts/test.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'test'; -process.env.NODE_ENV = 'test'; -process.env.PUBLIC_URL = ''; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -// require('../config/env'); - -const jest = require('jest'); -const argv = process.argv.slice(2); - -// Watch unless on CI or in coverage mode -if (!process.env.CI && argv.indexOf('--coverage') < 0) { - argv.push('--watch'); -} - - -jest.run(argv); From d88a787d3e77e75d8b7996b27a0b471943aec9ee Mon Sep 17 00:00:00 2001 From: tjaskula Date: Sun, 18 Feb 2018 10:37:33 +0100 Subject: [PATCH 6/7] Excluding coverage folder from git --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2f544c4..44234b8 100644 --- a/.gitignore +++ b/.gitignore @@ -238,3 +238,6 @@ _Pvt_Extensions # JetBrains .idea/ + +# Unit test coverage file +coverage/ \ No newline at end of file From 4e578ad083b20314ca99816b3ef227786979f6ee Mon Sep 17 00:00:00 2001 From: tjaskula Date: Tue, 20 Feb 2018 10:38:10 +0100 Subject: [PATCH 7/7] Add coverage script run for unit testing --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 611f0c4..b961f32 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "postinstall": "dotnet restore server", "start": "node run", "test": "node run test --env=jsdom", + "test:coverage": "node run test --coverage --env=jsdom", "tslint": "tslint client/*.ts", "build": "node run build", "build:debug": "node run build --debug"