Skip to content

Commit

Permalink
Add webpack e2e example (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlewis92 authored Dec 6, 2016
1 parent aec4fba commit 9dfa5f1
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
88 changes: 88 additions & 0 deletions examples/webpack/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const webpack = require('webpack');

const webpackConfig = {
module: {
loaders: [{
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules/
}],
postLoaders: [{
test: /src\/.+\.ts$/,
exclude: /(node_modules|\.spec\.ts$)/,
loader: 'sourcemap-istanbul-instrumenter-loader?force-sourcemap=true'
}]
},
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: null,
test: /\.(ts|js)($|\?)/i
})
],
resolve: {
extensions: ['', '.ts', '.js']
}
};

module.exports = config => {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: './',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],

// list of files / patterns to load in the browser
files: [
'test/test.spec.ts'
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/test.spec.ts': ['webpack', 'sourcemap']
},

webpack: webpackConfig,

remapIstanbulReporter: {
reports: {
html: 'coverage/html',
'text-summary': null
}
},

phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
exitOnResourceError: true
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['dots', 'coverage', 'karma-remap-istanbul'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};
27 changes: 27 additions & 0 deletions examples/webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "karma-remap-istanbul-example",
"private": true,
"version": "1.0.0",
"description": "Karma remap istanbul example",
"scripts": {
"test": "karma start"
},
"license": "MIT",
"devDependencies": {
"@types/chai": "~3.4.32",
"@types/mocha": "~2.2.31",
"chai": "~3.5.0",
"karma": "~1.2.0",
"karma-coverage": "~1.1.1",
"karma-mocha": "~1.1.1",
"karma-phantomjs-launcher": "~1.0.2",
"karma-remap-istanbul": "~0.2.1",
"karma-sourcemap-loader": "~0.3.7",
"karma-webpack": "~1.8.0",
"mocha": "~3.0.2",
"sourcemap-istanbul-instrumenter-loader": "~0.2.0",
"ts-loader": "~0.8.2",
"typescript": "~2.0.2",
"webpack": "~1.13.2"
}
}
11 changes: 11 additions & 0 deletions examples/webpack/src/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class Foo {

bar(): boolean {
return true; //covered
}

baz(): boolean {
return false; // not covered
}

}
11 changes: 11 additions & 0 deletions examples/webpack/test/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {expect} from 'chai';
import {Foo} from './../src/example';

describe('Foo', () => {

it('should return true', () => {
const foo: Foo = new Foo();
expect(foo.bar()).to.be.true;
});

});
11 changes: 11 additions & 0 deletions examples/webpack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"removeComments": false,
"noImplicitAny": false
},
"compileOnSave": false
}

0 comments on commit 9dfa5f1

Please sign in to comment.