-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Tests): Minimal working configuration for Unit Tests and coverag…
…e with Karma, TypeScript and WebPack
- Loading branch information
Showing
7 changed files
with
131 additions
and
107 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Error.stackTraceLimit = Infinity; | ||
|
||
var testContext = require.context('./src', true, /\.spec\.ts/); | ||
|
||
function requireAll(requireContext) { | ||
return requireContext.keys().map(requireContext); | ||
} | ||
|
||
var modules = requireAll(testContext); |
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,5 @@ | ||
describe('TypeScript WebPack Starter Tests', ()=> { | ||
it('A good way to start building an awesome lib is by doing Unit Tests 👌🏽', ()=> { | ||
describe('TypeScript WebPack Starter Tests', () => { | ||
it('A good way to start building an awesome lib is by doing Unit Tests 👌🏽', () => { | ||
expect(true).toBe(true); | ||
}) | ||
}); | ||
}) |
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,66 +1,77 @@ | ||
const webpack = require('webpack'); | ||
const path = require('path'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const DashboardPlugin = require('webpack-dashboard/plugin'); | ||
const nodeEnv = process.env.NODE_ENV || 'development'; | ||
const isProd = nodeEnv === 'production'; | ||
const webpack = require("webpack"); | ||
const path = require("path"); | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
const DashboardPlugin = require("webpack-dashboard/plugin"); | ||
const nodeEnv = process.env.NODE_ENV || "development"; | ||
const isProd = nodeEnv === "production"; | ||
|
||
var config = { | ||
devtool: isProd ? 'hidden-source-map' : 'cheap-eval-source-map', | ||
context: path.resolve('./src'), | ||
entry: { | ||
app: './index.ts', | ||
vendor: './vendor.ts' | ||
}, | ||
output: { | ||
path: path.resolve('./dist'), | ||
filename: '[name].bundle.js', | ||
sourceMapFilename: '[name].map', | ||
devtoolModuleFilenameTemplate: function (info) { | ||
return "file:///" + info.absoluteResourcePath; | ||
} | ||
}, | ||
module: { | ||
rules: [ | ||
{ enforce: 'pre', test: /\.ts$/, exclude: ["node_modules"], loader: 'ts-loader' }, | ||
{ test: /\.html$/, loader: "html" }, | ||
{ test: /\.css$/, loaders: ['style', 'css'] } | ||
] | ||
}, | ||
resolve: { | ||
extensions: [".ts", ".js"], | ||
modules: [path.resolve('./src'), 'node_modules'] | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'process.env': { // eslint-disable-line quote-props | ||
NODE_ENV: JSON.stringify(nodeEnv) | ||
} | ||
}), | ||
new HtmlWebpackPlugin({ | ||
title: 'Typescript Webpack Starter', | ||
template: '!!ejs-loader!src/index.html' | ||
}), | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'vendor', | ||
minChunks: Infinity, | ||
filename: 'vendor.bundle.js' | ||
}), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { warnings: false }, | ||
output: { comments: false }, | ||
sourceMap: false | ||
}), | ||
new DashboardPlugin(), | ||
new webpack.LoaderOptionsPlugin({ | ||
options: { | ||
tslint: { | ||
emitErrors: true, | ||
failOnHint: true | ||
} | ||
} | ||
}) | ||
devtool: isProd ? "hidden-source-map" : "source-map", | ||
context: path.resolve("./src"), | ||
entry: { | ||
app: "./index.ts", | ||
vendor: "./vendor.ts" | ||
}, | ||
output: { | ||
path: path.resolve("./dist"), | ||
filename: "[name].bundle.js", | ||
sourceMapFilename: "[name].bundle.map", | ||
devtoolModuleFilenameTemplate: function (info) { | ||
return "file:///" + info.absoluteResourcePath; | ||
} | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
enforce: "pre", | ||
test: /\.ts?$/, | ||
exclude: ["node_modules"], | ||
use: ["awesome-typescript-loader", "source-map-loader"] | ||
}, | ||
{ test: /\.html$/, loader: "html-loader" }, | ||
{ test: /\.css$/, loaders: ["style-loader", "css-loader"] } | ||
] | ||
}, | ||
resolve: { | ||
extensions: [".ts", ".js"] | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
"process.env": { | ||
// eslint-disable-line quote-props | ||
NODE_ENV: JSON.stringify(nodeEnv) | ||
} | ||
}), | ||
new HtmlWebpackPlugin({ | ||
title: "Typescript Webpack Starter", | ||
template: "!!ejs-loader!src/index.html" | ||
}), | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: "vendor", | ||
minChunks: Infinity, | ||
filename: "vendor.bundle.js" | ||
}), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { warnings: false }, | ||
output: { comments: false }, | ||
sourceMap: true | ||
}), | ||
new DashboardPlugin(), | ||
new webpack.LoaderOptionsPlugin({ | ||
options: { | ||
tslint: { | ||
emitErrors: true, | ||
failOnHint: true | ||
} | ||
} | ||
}) | ||
], | ||
devServer: { | ||
contentBase: path.join(__dirname, "dist/"), | ||
compress: true, | ||
port: 3000, | ||
hot: true | ||
} | ||
}; | ||
|
||
module.exports = config; |