diff --git a/.gitignore b/.gitignore index ad3ac3b..4daa53c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ dist/ *.env coverage/ npm-debug.log +test-dist/ +coverage-dist/ diff --git a/.travis.yml b/.travis.yml index 8526a15..713f44c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,10 @@ addons: firefox: latest script: - npm test +- npm run cover - npm run browser-test - npm run lint +- ./ci/coveralls.sh git: depth: 1 submodules: false diff --git a/ci/coveralls.sh b/ci/coveralls.sh new file mode 100755 index 0000000..b1dc937 --- /dev/null +++ b/ci/coveralls.sh @@ -0,0 +1,2 @@ +#!/bin/sh +cat ./coverage/lcov.info | $(npm bin)/coveralls || true diff --git a/gulpfile.js b/gulpfile.js index 17e2bd7..77d92dd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,16 +2,46 @@ var gulp = require("gulp"); var ts = require("gulp-typescript"); var tslint = require("gulp-tslint"); var jasmine = require("gulp-jasmine"); +var sourcemaps = require('gulp-sourcemaps'); +var istanbul = require("gulp-istanbul"); +var remapIstanbul = require("remap-istanbul/lib/gulpRemapIstanbul"); var tsProject = ts.createProject("tsconfig.json"); -gulp.task("build", function() { +gulp.task("coverage-build", function() { return tsProject.src() + .pipe(sourcemaps.init()) .pipe(tsProject()) - .js.pipe(gulp.dest("dist")); + .js.pipe(sourcemaps.write('.', {includeContent: false})) + .pipe(gulp.dest("coverage-dist")); }); -gulp.task('test', ['build'], function() { - return gulp.src("dist/*.spec.js").pipe(jasmine()); +gulp.task("pre-coverage", ["coverage-build"], function() { + return gulp.src(["coverage-dist/**/*.js"]) + .pipe(istanbul()) + .pipe(istanbul.hookRequire()); +}); + +gulp.task('coverage', ['coverage-build', 'pre-coverage'], function() { + return gulp.src("coverage-dist/*.spec.js") + .pipe(jasmine()) + .pipe(istanbul.writeReports({ + dir: './coverage', + reporters: ['json'], + reportOpts: { + json: {dir: './coverage', file: 'coverage-js.json'} + } + })).on("end", function () { + return gulp.src('coverage/coverage-js.json') + .pipe(remapIstanbul({ + basePath: 'src/', + reports: { + 'json': './coverage/coverage.json', + 'html': './coverage/html-report', + 'lcovonly': './coverage/lcov.info', + 'text': null + } + })); + }); }); gulp.task('lint', function() { @@ -20,4 +50,15 @@ gulp.task('lint', function() { .pipe(tslint.report()); }); -gulp.task('default', ['build', 'test', 'lint']) +gulp.task('test-build', function() { + return tsProject.src() + .pipe(tsProject()) + .pipe(gulp.dest("test-dist")); +}); + +gulp.task('test', ['test-build'], function() { + return gulp.src("test-dist/*.spec.js") + .pipe(jasmine()); +}); + +gulp.task('default', ['test', 'lint', 'coverage']) diff --git a/package.json b/package.json index f2e5c81..26f0486 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "gulp": "^3.9.1", "gulp-tslint": "^8.1.2", "gulp-typescript": "^3.2.3", + "gulp-sourcemaps": "^2.6.4", "tslint": "^5.8.0", "typescript": "^2.6.2", "webpack": "^3.10.0", @@ -22,11 +23,16 @@ "karma-sauce-launcher": "^1.2.0", "karma-webpack": "^2.0.9", "karma-sourcemap-loader": "^0.3.7", - "ts-loader": "^3.3.1" + "ts-loader": "^3.3.1", + "istanbul": "^0.4.5", + "gulp-istanbul": "^1.1.3", + "remap-istanbul": "^0.10.1", + "coveralls": "^3.0.0" }, "scripts": { "test": "gulp test", "lint": "gulp lint", + "cover": "gulp coverage", "browser-test": "karma start" }, "repository": {