Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/coveralls coverage #4

Merged
merged 4 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ install:
script:
- npm test
- npm run build
after_success:
- npm run coveralls
before_deploy:
- pr-bumper bump
env:
Expand Down
7 changes: 6 additions & 1 deletion browser/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
it,
it, xit,
inject,
describe,
beforeEachProviders,
expect
} from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('App', () => {
beforeEachProviders(() => [
AppComponent
Expand All @@ -14,4 +15,8 @@ describe('App', () => {
// Add real test here
expect(2).toBe(2);
}));

xit('should skip', () => {
expect(true).toBe(false);
});
});
14 changes: 11 additions & 3 deletions browser/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = (config) => {
],

preprocessors: {
[`${__dirname}/karma-test-shim.js`]: ['webpack', 'sourcemap']
[`${__dirname}/karma-test-shim.js`]: ['coverage', 'webpack', 'sourcemap']
},

webpack: webpackConfig,
Expand All @@ -27,13 +27,21 @@ module.exports = (config) => {
noInfo: true
},

reporters: ['spec'],
reporters: ['spec', 'coverage'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true
singleRun: true,

coverageReporter: {
// specify a common output directory
dir: 'coverage/browser/js',
reporters: [
{type: 'json', subdir: '.'}
]
}
};

config.set(_config);
Expand Down
7 changes: 7 additions & 0 deletions browser/config/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ module.exports = {
test: /\.css$/,
loader: 'null'
}
],
postLoaders: [
{ //delays coverage til after tests are run, fixing transpiled source coverage error
test: /\.(js|ts)$/,
exclude: /(node_modules)\//,
loader: 'sourcemap-istanbul-instrumenter?force-sourcemap'
}
]
},

Expand Down
66 changes: 57 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ let tsc = require('gulp-typescript');
let sourcemaps = require('gulp-sourcemaps');
let tslint = require('gulp-tslint');
let nodemon = require('gulp-nodemon');
var jasmine = require('gulp-jasmine');
var istanbul = require('gulp-istanbul');
let jasmine = require('gulp-jasmine');
let istanbul = require('gulp-istanbul');
let runSequence = require('run-sequence');

var path = require('path');

// /* Variables */
Expand All @@ -26,8 +28,13 @@ let entryPoint = './localhost.js';
/**
* Remove build directory.
*/
gulp.task('clean', function () {
return gulp.src('build', {read: false})
gulp.task('clean-build', function () {
return gulp.src(['build'], {read: false})
.pipe(rimraf())
});

gulp.task('clean-coverage', function () {
return gulp.src(['coverage'], {read: false})
.pipe(rimraf())
});

Expand Down Expand Up @@ -75,12 +82,12 @@ gulp.task('format', (cb) => {
/**
* Compile TypeScript sources and create sourcemaps in build directory.
*/
gulp.task('compile', ['clean'], () => {
gulp.task('compile', ['clean-build'], () => {
let tsResult = gulp.src(sourceFiles.concat(testFiles))
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(sourcemaps.write('.', {sourceRoot: __dirname}))
.pipe(gulp.dest(outDir))
});

Expand All @@ -100,7 +107,19 @@ gulp.task('build', ['compile'], () => {
console.log('Building the project ...')
});

gulp.task('test', ['build'], () => {
gulp.task('pre-test', ['clean-coverage'], () => {
return gulp.src(['build/api/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});

gulp.task('test', [], (callback) => {
runSequence('build', 'pre-test', 'jasmine', callback);
});

gulp.task('jasmine', [], () => {
Error.stackTraceLimit = Infinity;

require('es6-shim');
Expand All @@ -109,13 +128,42 @@ gulp.task('test', ['build'], () => {

const SpecReporter = require('jasmine-spec-reporter');

return gulp.src(['build/**/*.spec.js'])
return gulp.src(['build/api/**/*.js', '!build/api/api/bootstrap.js'])
.pipe(jasmine({
reporter: new SpecReporter({
displayFailuresSummary: false
})
})
);
)
// Creating the reports after tests ran
.pipe(istanbul.writeReports({
dir: './coverage/api/js',
reporters: [ 'json' ]
}));
});

gulp.task('remap-istanbul', [], () => {

let remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul');
let fs = require('fs');
let merge = require('gulp-merge-json');
let files = [
'./coverage/browser/js/coverage-final.json',
'./coverage/api/js/coverage-final.json'
];

return gulp.src(files)
.pipe(merge('summary.json'))
.pipe(remapIstanbul({
reports: {
'json': './coverage/summary/coverage.json',
'html': './coverage/summary/html-report',
'text': './coverage/summary/text-summary',
'lcovonly': './coverage/summary/lcov.info'
}
})).on('end', () => {
console.log(fs.readFileSync('./coverage/summary/text-summary').toString());
});
});

gulp.task('nodemon', ['build'], () => {
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"start": "gulp nodemon",
"test": "gulp test && karma start",
"test": "gulp test && karma start && gulp remap-istanbul",
"coveralls": "cat coverage/summary/lcov.info | coveralls",
"build": "gulp compile && webpack --config browser/config/webpack.prod.js --progress --profile --bail",
"postinstall": "typings install"
},
Expand Down Expand Up @@ -40,12 +41,14 @@
"devDependencies": {
"babel-register": "^6.9.0",
"codelyzer": "0.0.19",
"coveralls": "^2.11.9",
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"gulp": "^3.9.1",
"gulp-istanbul": "^0.10.4",
"gulp-jasmine": "^2.3.0",
"gulp-merge-json": "^0.4.0",
"gulp-nodemon": "^2.0.7",
"gulp-rimraf": "^0.2.0",
"gulp-sourcemaps": "^1.6.0",
Expand All @@ -58,6 +61,7 @@
"jasmine-core": "^2.4.1",
"jasmine-spec-reporter": "^2.4.0",
"karma": "^0.13.22",
"karma-coverage": "^1.0.0",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
Expand All @@ -66,7 +70,10 @@
"null-loader": "^0.1.1",
"phantomjs-prebuilt": "^2.1.7",
"raw-loader": "^0.5.1",
"remap-istanbul": "^0.6.4",
"rimraf": "^2.5.2",
"run-sequence": "^1.2.0",
"sourcemap-istanbul-instrumenter-loader": "^0.2.0",
"style-loader": "^0.13.1",
"ts-loader": "^0.8.2",
"tslint": "^3.10.2",
Expand Down