Skip to content

Commit

Permalink
Added coverage reports
Browse files Browse the repository at this point in the history
  • Loading branch information
mtxr committed Apr 14, 2017
1 parent 535f963 commit 23fdf1a
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
.vscode-test/
coverage/
.nyc_output/
coverage.enabled
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"request": "launch",
"name": "Launch Coverage Tests",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test"],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/test/**/*.js"],
"preLaunchTask": "compile"
"preLaunchTask": "pre-coverage:vscode"
},
{
"name": "Launch Extension",
Expand All @@ -21,7 +21,7 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "compile"
"preLaunchTask": "pre-run:vscode"
},
{
"name": "Launch Tests",
Expand Down
21 changes: 15 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function runTests () {
}))
}

gulp.task('compile', function () {
gulp.task('compile', () => {
return tsProject.src()
.pipe(tsProject())
.js.pipe(gulp.dest('out'))
})

gulp.task('pre-test', ['compile'], function () {
gulp.task('pre-test', ['compile'], () => {
// This tells gulp which files you want to pipe
// In our case we want to pipe every `.js` file inside any folders inside `test`
return gulp.src('./out/**/*.js')
Expand All @@ -28,19 +28,28 @@ gulp.task('pre-test', ['compile'], function () {
.pipe(istanbul.hookRequire())
})

gulp.task('test', ['compile'], function () {
gulp.task('test', ['compile'], () => {
runTests()
})

gulp.task('coverage', ['pre-test'], function () {
gulp.task('coverage', ['pre-test'], () => {
runTests()
// Here we will create report files using the test's results
.pipe(istanbul.writeReports())
})

gulp.task('watch', function () {
gulp.task('watch', () => {
gulp.watch('./src/**/*.ts', ['compile'])
gulp.watch('./test/**/*.ts', ['compile'])
})

gulp.task('default', ['watch', 'coverage'])
gulp.task('default', ['pre-run:vscode', 'watch', 'coverage'])

gulp.task('pre-coverage:vscode', ['compile'], () => {
require('fs').writeFileSync(`${__dirname}/coverage.enabled`, 'true')
})

gulp.task('pre-run:vscode', ['compile'], () => {
const fs = require('fs')
if (fs.existsSync(`${__dirname}/coverage.enabled`)) fs.unlinkSync(`${__dirname}/coverage.enabled`)
})
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@
"test:coverage": "gulp coverage"
},
"devDependencies": {
"@types/chai": "^3.4.35",
"@types/mocha": "^2.3.3",
"@types/node": "^7.0.12",
"chai": "^3.5.0",
"decache": "^4.1.0",
"gulp": "^3.9.1",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
Expand All @@ -123,6 +121,7 @@
"remap-istanbul": "^0.6.4",
"semver": "^5.3.0",
"sinon": "^1.17.7",
"source-map-support": "^0.4.14",
"ts-node": "^2.1.0",
"typescript": "^2.0.3",
"vscode": "^1.0.0"
Expand Down
12 changes: 5 additions & 7 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// tslint:disable:no-reference
// tslint:disable:no-console

/// <reference path="../node_modules/@types/node/index.d.ts" />

'use strict';

import * as fs from 'fs';
import * as TestRunner from './test-runner';

const testRunner = TestRunner;
const mochaConfig: any = { ui: 'bdd', useColors: true };
const mochaConfig: any = { ui: 'bdd', useColors: true, reporter: 'spec' };
let coverageConfig: any;

if (process.argv.indexOf('--coverage') >= 0) {
if (fs.existsSync(`${__dirname}/../../coverage.enabled`)) {
coverageConfig = {
coverageDir: `${__dirname}/../coverage`,
coverageDir: `../../coverage`,
ignorePatterns: ['**/node_modules/**'],
sourcePath: `${__dirname}/../src`,
sourcePath: `../src`,
};
}

Expand Down
Loading

0 comments on commit 23fdf1a

Please sign in to comment.