Skip to content

Commit

Permalink
Merge pull request #7 from emyann/develop
Browse files Browse the repository at this point in the history
Feat(Tests): Release including Unit Tests and Major Updates
  • Loading branch information
emyann authored Jul 19, 2017
2 parents 1835b5e + 23392e4 commit e788c72
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ typings/**/*
~$*
*~
node_modules/
src/build/
coverage/
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ language: node_js
node_js:
- '6.7'

script: true
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

script:
- npm run test
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Built upon

- [x] [Webpack 2](https://webpack.github.io/docs/roadmap.html#2)
- [x] [Webpack 3](https://webpack.js.org/)
- [x] [Typescript 2](https://blogs.msdn.microsoft.com/typescript/2016/07/11/announcing-typescript-2-0-beta/)
- [x] [Webpack Dashboard](https://github.com/FormidableLabs/webpack-dashboard)
![Imgur](http://i.imgur.com/pETTX85.png)
Expand Down Expand Up @@ -52,7 +52,5 @@ After build phase, 3 files are generated into the `dist` folder:

## TODO

- [ ] Add TODO example
- [ ] Setup VSCode debug to match webpack-dev-server
- [ ] Setup a webpack common configuration and use webpack-merge
- [ ] Setup unit tests with Jasmine / Karma
- [ ] `create-ts-app` or `create-typescript-app` CLI instead of cloning the entire repository
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=759670
// for the documentation about the jsconfig.json format
"sourceMap": true,
"compilerOptions": {
"target": "es6",
"module": "commonjs",
Expand Down
61 changes: 61 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var webpackConf = require('./webpack.config.js');
module.exports = function (config) {
config.set({
basePath:'',
frameworks: ['jasmine'],
files: [{ pattern: './tests/unit/spec-bundle.js', watched: false }],
preprocessors: { './tests/unit/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
webpack: {
module: webpackConf.module,
resolve: webpackConf.resolve
},
webpackMiddleware: {
noInfo: true,
stats: 'errors-only'
},
reporters: ['kjhtml', 'spec', 'coverage'],
// optionally, configure the reporter
coverageReporter: {
// specify a common output directory
dir: './tests/build/reports/coverage',
reporters: [
// reporters not supporting the `file` property
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' },
// reporters supporting the `file` property, use `subdir` to directly
// output them in the `dir` directory
{ type: 'cobertura', subdir: '.', file: 'cobertura.txt' },
{ type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' },
{ type: 'teamcity', subdir: '.', file: 'teamcity.txt' },
{ type: 'text', subdir: '.', file: 'text.txt' },
{ type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
]
},
specReporter: {
maxLogLines: 5, // limit number of lines logged per test
suppressErrorSummary: true, // do not print error summary
suppressFailed: false, // do not print information about failed tests
suppressPassed: false, // do not print information about passed tests
suppressSkipped: true, // do not print information about skipped tests
showSpecTiming: false // print the time elapsed for each spec
},
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true,
concurrency: Infinity
});


if (process.env.TRAVIS) {
config.browsers = ['Chrome_travis_ci'];
}
};
55 changes: 35 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"scripts": {
"start": "npm run server:dev",
"server": "npm run server:dev",
"server:dev": "webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --content-base dist/",
"server:prod": "cross-env NODE_ENV=production webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --content-base dist/",
"server:dev": "webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --inline --progress --watch --open",
"server:prod": "cross-env NODE_ENV=production webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --open --content-base dist/",
"build": "npm run build:dev",
"build:dev": "webpack --config ./webpack.config.js --progress --profile --color --display-error-details --display-cached",
"build:prod": "cross-env NODE_ENV=production webpack --config ./webpack.config.js --progress --profile --color --display-error-details --display-cached --bail",
"clean": "npm cache clear && rimraf -- dist",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "karma start"
},
"repository": {
"type": "git",
Expand All @@ -21,25 +21,40 @@
"author": "yrenaudin",
"license": "ISC",
"devDependencies": {
"@types/lodash": "^4.14.50",
"cross-env": "^3.1.4",
"css-loader": "^0.26.1",
"@types/jasmine": "^2.5.53",
"@types/lodash": "^4.14.70",
"awesome-typescript-loader": "^3.2.1",
"cross-env": "^5.0.1",
"css-loader": "^0.28.4",
"ejs-loader": "^0.3.0",
"eslint": "^3.14.0",
"expose-loader": "^0.7.1",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.26.0",
"rimraf": "^2.5.4",
"style-loader": "^0.13.1",
"ts-loader": "^2.0.0",
"tslint": "^4.3.1",
"tslint-loader": "^3.3.0",
"typescript": "^2.1.5",
"webpack": "^2.1.0-beta.22",
"webpack-dashboard": "^0.2.1",
"webpack-dev-server": "2.2.0"
"eslint": "^4.2.0",
"expose-loader": "^0.7.3",
"html-loader": "^0.4.5",
"html-webpack-plugin": "^2.29.0",
"jasmine": "^2.6.0",
"jasmine-core": "^2.6.4",
"karma": "^1.7.0",
"karma-babel-preprocessor": "^6.0.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.31",
"karma-webpack": "^2.0.4",
"rimraf": "^2.6.1",
"source-map-loader": "^0.2.1",
"style-loader": "^0.18.2",
"tslint": "^5.5.0",
"tslint-loader": "^3.5.3",
"typescript": "^2.4.1",
"webpack": "^3.3.0",
"webpack-dashboard": "^0.4.0",
"webpack-dev-server": "2.5.1"
},
"dependencies": {
"lodash": "^4.17.4"
}
}
}
3 changes: 2 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
</head>

<body>
<div> You have successfully started your Typescript application using Webpack. By <a href="https://twitter.com/renaudin_yann">@renaudin_yann</a> </div>
<div> You have successfully started your Typescript application using Webpack. Open your console to see your printed message from the index.ts file </div>
<p>By <a href="https://twitter.com/renaudin_yann">@renaudin_yann</a> </p>
</body>

</html>
5 changes: 5 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('TypeScript WebPack Starter Tests', () => {
it('A good way to start building an awesome lib is by doing Unit Tests 👌🏽', () => {
expect(true).toBe(true);
});
})
9 changes: 9 additions & 0 deletions tests/unit/spec-bundle.js
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);
13 changes: 10 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"compilerOptions": {
"target": "es5",
"module": "es6",
"moduleResolution": "node",
"sourceMap": true
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2015",
"dom"
],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"node_modules",
Expand Down
131 changes: 71 additions & 60 deletions webpack.config.js
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;

0 comments on commit e788c72

Please sign in to comment.