Skip to content
This repository was archived by the owner on Sep 24, 2020. It is now read-only.

Commit f23ea6b

Browse files
committed
Implement mocha unit testing
* Split webpack configuration into multiple files
1 parent 5e3e9b9 commit f23ea6b

17 files changed

+239
-212
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change log
22

3+
## [v0.5.0] (2017-03-23)
4+
5+
** Features **
6+
7+
* Implement mocha for unit testing
8+
* Split webpack configuration into multiple files
9+
310
## [v0.4.1] (2017-03-17)
411

512
** Fixes **
@@ -51,6 +58,8 @@
5158

5259
* Initial release
5360

61+
[v0.5.0]: https://github.com/ducksoupdev/vue-webpack-typescript/compare/v0.4.1...v0.5.0
62+
[v0.4.1]: https://github.com/ducksoupdev/vue-webpack-typescript/compare/v0.4.0...v0.4.1
5463
[v0.4.0]: https://github.com/ducksoupdev/vue-webpack-typescript/compare/v0.3.1...v0.4.0
5564
[v0.3.1]: https://github.com/ducksoupdev/vue-webpack-typescript/compare/v0.2.0...v0.3.1
5665
[v0.3.0]: https://github.com/ducksoupdev/vue-webpack-typescript/compare/v0.2.0...v0.3.0

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# webpack-typescript
22

3-
> A Vue 2.0 Webpack and Typescript setup with hot reload, unit testing, code coverage, sass and bundling/minification.
3+
> A Vue 2.2 Webpack and Typescript setup with hot reload, unit testing, code coverage, sass and bundling/minification.
44
5-
> This template is for Vue 2.0
5+
> This template is for Vue 2.2
66
77
### Usage
88

@@ -19,10 +19,10 @@ $ npm run dev
1919
### What's Included
2020

2121
- `npm run dev`: Webpack + Typescript with proper config for source maps & hot-reload.
22-
- `npm test`: Jasmine-based tests
23-
- `npm run test-watch`: Jasmine-based tests with hot-reload
22+
- `npm test`: Mocha-based unit tests
23+
- `npm run test:watch`: Mocha-based unit tests with hot-reload
2424
- `npm run coverage`: Karma coverage reporter
2525
- `npm run lint`: Lint all Typescript files
2626
- `npm run build`: build with HTML/CSS/JS minification.
27-
- `npm run ci-teamcity`: Teamcity CI integration
28-
- `npm run ci-jenkins`: Jenkins CI integration
27+
- `npm run ci:teamcity`: Teamcity CI integration
28+
- `npm run ci:jenkins`: Jenkins CI integration

template/config/helpers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const path = require("path");
2+
3+
// Helper functions
4+
const ROOT = path.resolve(__dirname, "..");
5+
6+
function root(args) {
7+
args = Array.prototype.slice.call(arguments, 0);
8+
return path.join.apply(path, [ROOT].concat(args));
9+
}
10+
11+
exports.root = root;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const helpers = require("./helpers"),
2+
DefinePlugin = require('webpack/lib/DefinePlugin'),
3+
CopyWebpackPlugin = require('copy-webpack-plugin');
4+
5+
let config = {
6+
entry: {
7+
"main": helpers.root("/src/main.ts")
8+
},
9+
output: {
10+
path: helpers.root("/dist/js"),
11+
filename: "[name].js"
12+
},
13+
devtool: "source-map",
14+
resolve: {
15+
extensions: [".ts", ".js", ".html"],
16+
alias: {
17+
'vue$': 'vue/dist/vue.common.js'
18+
}
19+
},
20+
module: {
21+
rules: [
22+
{test: /\.ts$/, exclude: /node_modules/, enforce: 'pre', loader: 'tslint-loader'},
23+
{test: /\.ts$/, exclude: /node_modules/, loader: "awesome-typescript-loader"},
24+
{test: /\.html$/, loader: 'raw-loader', exclude: ['./src/index.html']}
25+
],
26+
},
27+
plugins: [
28+
new CopyWebpackPlugin([
29+
{from: 'src/assets', to: '../assets'},
30+
{from: 'src/css', to: '../css'}
31+
]),
32+
new DefinePlugin({
33+
'process.env': {
34+
'ENV': process.env.NODE_ENV,
35+
'NODE_ENV': process.env.NODE_ENV
36+
}
37+
})
38+
]
39+
};
40+
41+
module.exports = config;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const webpackConfig = require("./webpack.config.base");
2+
3+
webpackConfig.module.rules[1].query = {
4+
compilerOptions: {
5+
inlineSourceMap: true,
6+
sourceMap: false
7+
}
8+
};
9+
10+
webpackConfig.module.rules = [...webpackConfig.module.rules,
11+
{
12+
test: /\.ts$/,
13+
enforce: "post",
14+
loader: "istanbul-instrumenter-loader",
15+
exclude: [
16+
"node_modules",
17+
/\.spec\.ts$/
18+
],
19+
query: {
20+
esModules: true
21+
}
22+
}
23+
];
24+
25+
webpackConfig.devtool = "inline-source-map";
26+
27+
module.exports = webpackConfig;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const helpers = require("./helpers"),
2+
webpackConfig = require("./webpack.config.base")
3+
4+
webpackConfig.devServer = {
5+
port: 8080,
6+
host: "localhost",
7+
historyApiFallback: true,
8+
watchOptions: {aggregateTimeout: 300, poll: 1000},
9+
contentBase: './src',
10+
open: true
11+
};
12+
13+
module.exports = webpackConfig;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin'),
2+
CompressionPlugin = require('compression-webpack-plugin'),
3+
webpackConfig = require("./webpack.config.base"),
4+
helpers = require("./helpers");
5+
6+
webpackConfig.entry["main.min"] = helpers.root("/src/main.ts");
7+
8+
webpackConfig.plugins = [...webpackConfig.plugins,
9+
new UglifyJsPlugin({
10+
include: /\.min\.js$/,
11+
minimize: true
12+
}),
13+
new CompressionPlugin({
14+
asset: "[path].gz[query]",
15+
test: /\.min\.js$/
16+
})
17+
];
18+
19+
module.exports = webpackConfig;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("./webpack.config.base");

template/karma.coverage.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var parseArgs = require('minimist');
2-
var webpackConfig = require('./webpack.config');
2+
var webpackConfig = require('./config/webpack.config.coverage');
33

44
var args = parseArgs(process.argv.slice(2), {
55
string: ['env'],
@@ -8,36 +8,6 @@ var args = parseArgs(process.argv.slice(2), {
88
}
99
});
1010

11-
webpackConfig.module.rules = [{
12-
test: /\.ts$/,
13-
exclude: /node_modules/,
14-
loader: "ts-loader",
15-
query: {
16-
compilerOptions: {
17-
inlineSourceMap: true,
18-
sourceMap: false
19-
}
20-
}
21-
},
22-
{
23-
test: /\.html$/,
24-
loader: 'raw-loader',
25-
exclude: ['./src/index.html']
26-
},
27-
{
28-
test: /\.ts$/,
29-
enforce: "post",
30-
loader: 'istanbul-instrumenter-loader',
31-
exclude: [
32-
'node_modules',
33-
/\.spec\.ts$/
34-
],
35-
query: {
36-
esModules: true
37-
}
38-
}
39-
];
40-
4111
var reporters = ['mocha', 'coverage'];
4212

4313
if (args.env === 'tc') {
@@ -51,7 +21,7 @@ if (args.env === 'jk') {
5121
module.exports = function (config) {
5222
config.set({
5323
basePath: '',
54-
frameworks: ['jasmine', 'source-map-support'],
24+
frameworks: ['mocha', 'chai', 'sinon'],
5525
files: [
5626
'node_modules/es6-promise/dist/es6-promise.auto.js',
5727
'src/test.ts'
@@ -83,6 +53,7 @@ module.exports = function (config) {
8353
logLevel: config.LOG_INFO,
8454
autoWatch: false,
8555
browsers: ['PhantomJS'],
86-
singleRun: true
56+
singleRun: true,
57+
concurrency: Infinity
8758
});
8859
};

template/karma.unit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var webpackConfig = require('./webpack.config');
1+
var webpackConfig = require('./config/webpack.config.base');
22

33
module.exports = function(config) {
44
config.set({
55
basePath: '',
6-
frameworks: ['jasmine'],
6+
frameworks: ['mocha', 'chai', 'sinon'],
77
files: [
88
'node_modules/es6-promise/dist/es6-promise.auto.js',
99
'src/test.ts'

0 commit comments

Comments
 (0)