Skip to content
This repository was archived by the owner on Jan 9, 2019. It is now read-only.

Commit 2d1b904

Browse files
author
Daniel Beus
committed
Added features of MSTest library.
Added passthrough of all features available to the MSTest library. Added setting of the working directory to the location of the test dll with the "!source" flag.
1 parent 397389a commit 2d1b904

File tree

7 files changed

+271
-90
lines changed

7 files changed

+271
-90
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

.eslintrc.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"extends": "eslint:recommended",
7+
"parserOptions": {
8+
"sourceType": "module"
9+
},
10+
"rules": {
11+
"indent": [
12+
"error",
13+
"tab"
14+
],
15+
"linebreak-style": [
16+
"error",
17+
"windows"
18+
],
19+
"quotes": [
20+
"error",
21+
"single"
22+
],
23+
"semi": [
24+
"error",
25+
"always"
26+
]
27+
}
28+
}

README.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@ Gulp wrapper for running MSTest
55
Usage
66
---------
77
Use gulp-mstest like any other gulp plugin:
8-
```
8+
9+
ES5
10+
``` javascript
911
var gulp = require('gulp'),
10-
mstest = require('gulp-mstest');
12+
mstest = require('gulp-mstest').default;
1113

1214
gulp.task('mstest', function () {
13-
return gulp.src('mytestlibrary.dll')
15+
return gulp.src(['mytestlibrary.dll'])
1416
.pipe(mstest());
1517
});
1618
```
1719

20+
ES2015
21+
``` javascript
22+
import gulp from 'gulp';
23+
import mstest from 'gulp-mstest';
24+
25+
gulp.task('mstest', () => gulp.src(['mstestlibrary.dll'])
26+
.pipe(mstest()));
27+
```
28+
1829
###Options
1930
Gulp-Mstest has a few minor settings that determine what gets output to the console. By default, nothing is printed to the console -- you will need to tie in another stream to get output. This is beneficial because it allows you to put the test results wherever you want (e.g. file, console, web service, etc.). However, if you'd like to have output, here are the settings to do so:
2031

@@ -27,3 +38,9 @@ Gulp-Mstest has a few minor settings that determine what gets output to the cons
2738
- quitOnFailed: This causes gulp-mstest to use a gulp plugin error if any of the tests in a dll failed to pass. This is useful when there are multiple test packages that must run and you want to be notified as soon as one fails.
2839
- If errorMessage or errorStackTrace are on, they will be output with the failed message
2940
- language: if you mstest.exe is non-english, change your language (ie. language='fr'). see mstest to see available language.
41+
42+
In addition to the above settings, all settings available to the mstest npm package will be passed through to the mstest library.
43+
44+
One change will allow you to use a special key `"!source"` to indicate to the library that the working directory should be set to the same directory as the test library.
45+
This will default to `"."` if no directory is passed in as a part of the test file path. For example, the path `"D:\code\tests\bin\Debug\mylibrary.tests.dll"` will set the
46+
working directory to `"D:\code\tests\bin\Debug"`. The path of just `"mylibrary.tests.dll"` will set the working directory to `"."`.

bin/index.js

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.default = RunTests;
7+
8+
var _gulpUtil = require('gulp-util');
9+
10+
var _gulpUtil2 = _interopRequireDefault(_gulpUtil);
11+
12+
var _through = require('through2');
13+
14+
var _through2 = _interopRequireDefault(_through);
15+
16+
var _mstest = require('mstest');
17+
18+
var _mstest2 = _interopRequireDefault(_mstest);
19+
20+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21+
22+
function RunTests() {
23+
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
24+
25+
var msTest = new _mstest2.default();
26+
msTest.details.errorMessage = true;
27+
msTest.details.errorStackTrace = true;
28+
msTest.language = opts.language;
29+
30+
if (opts.workingDir && !opts.workingDir === '!source') msTest.workingDir = opts.workingDir;
31+
32+
msTest.noIsolation = opts.noIsolation;
33+
msTest.testSettings = opts.testSettings;
34+
msTest.runConfig = opts.runConfig;
35+
msTest.resultsFile = opts.resultsFile;
36+
msTest.debugLog = opts.debugLog;
37+
msTest.useStdErr = opts.useStdErr;
38+
39+
return _through2.default.obj(function (file, enc, cb) {
40+
if (file.isNull()) return cb(null, file);
41+
42+
if (file.isStream()) return cb(new _gulpUtil2.default.PluginError('gulp-mstest', 'Streaming not supported'));
43+
44+
_gulpUtil2.default.log(_gulpUtil2.default.colors.italic(_gulpUtil2.default.colors.bold('Running tests in ' + file.path)));
45+
46+
try {
47+
msTest.testContainer = file.path;
48+
if (opts.workingDir === '!source') {
49+
var index = file.path.lastIndexOf('/');
50+
if (index === -1) index = file.path.lastIndexOf('\\');
51+
52+
var dir = file.path.substr(0, index);
53+
if (dir.length === 0) dir = '.';
54+
55+
msTest.workingDir = dir;
56+
_gulpUtil2.default.log(_gulpUtil2.default.colors.italic(_gulpUtil2.default.colors.bold('Setting working directory to "' + dir + '".')));
57+
}
58+
59+
msTest.runTests({
60+
eachTest: function eachTest(test) {
61+
if (opts.outputEachResult) {
62+
if (test.passed) {
63+
_gulpUtil2.default.log(_gulpUtil2.default.colors.bgGreen(test.status + ' - ' + test.name));
64+
} else {
65+
_gulpUtil2.default.log(_gulpUtil2.default.colors.bgRed(test.status + ' - ' + test.name));
66+
if (opts.errorMessage) _gulpUtil2.default.log(_gulpUtil2.default.colors.bgRed(test.errorMessage));
67+
if (opts.errorStackTrace) _gulpUtil2.default.log(_gulpUtil2.default.colors.bgRed(test.errorStackTrace));
68+
}
69+
}
70+
},
71+
done: function done(results, passed, failed) {
72+
if (opts.outputFinalCount) {
73+
_gulpUtil2.default.log(_gulpUtil2.default.colors.underline('Passed ' + _gulpUtil2.default.colors.green(passed.length) + '/' + _gulpUtil2.default.colors.blue(results.length) + ' tests.'));
74+
}
75+
76+
var error = null;
77+
78+
if (opts.quitOnFailed && failed.length > 0) {
79+
var errorMessage = _gulpUtil2.default.colors.red('Tests failed');
80+
if (opts.errorMessage || opts.errorStackTrace) {
81+
errorMessage += ':\n\t';
82+
errorMessage += failed.map(function (test) {
83+
var msg = _gulpUtil2.default.colors.underline(_gulpUtil2.default.colors.bold(_gulpUtil2.default.colors.yellow(test.name)));
84+
if (opts.errorMessage) msg += '\n\t\tError Message: ' + _gulpUtil2.default.colors.yellow(test.errorMessage);
85+
if (opts.errorStackTrace) msg += '\n\t\tStack Trace: ' + _gulpUtil2.default.colors.magenta(test.errorStackTrace);
86+
return msg;
87+
}).join('\n\t');
88+
}
89+
error = new _gulpUtil2.default.PluginError('gulp-mstest', errorMessage);
90+
}
91+
92+
cb(error, {
93+
results: results,
94+
passed: passed,
95+
failed: failed
96+
});
97+
}
98+
});
99+
} catch (err) {
100+
this.emit('error', new _gulpUtil2.default.PluginError('gulp-mstest', err, {
101+
fileName: file.path,
102+
showProperties: false
103+
}));
104+
}
105+
});
106+
}

index.js

-80
This file was deleted.

package.json

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
{
22
"name": "gulp-mstest",
3-
"version": "0.1.1",
3+
"version": "1.0.0",
44
"description": "Gulp wrapper for executing mstest",
5-
"main": "index.js",
5+
"main": "bin/index.js",
66
"dependencies": {
7-
"gulp-util": "^3.0.6",
8-
"mstest": "^0.2.0",
9-
"through2": "^2.0.0"
7+
"gulp-util": "3.0.6",
8+
"mstest": "0.2.2",
9+
"through2": "2.0.0"
10+
},
11+
"devDependencies": {
12+
"babel-cli": "6.14.0",
13+
"babel-preset-es2015": "6.14.0",
14+
"eslint": "3.5.0",
15+
"rimraf": "2.5.4"
1016
},
11-
"devDependencies": {},
1217
"scripts": {
13-
"test": "echo \"Error: no test specified\" && exit 1"
18+
"test": "echo \"Error: no test specified\" && exit 1",
19+
"clean": "rimraf ./bin/*",
20+
"lint": "eslint ./src",
21+
"prebuild": "npm run clean && npm run lint",
22+
"build": "babel src --out-dir bin"
1423
},
1524
"repository": {
1625
"type": "git",

src/index.js

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import gutil from 'gulp-util';
2+
import through from 'through2';
3+
import MSTest from 'mstest';
4+
5+
export default function RunTests(opts = {}) {
6+
var msTest = new MSTest();
7+
msTest.details.errorMessage = true;
8+
msTest.details.errorStackTrace = true;
9+
msTest.language = opts.language;
10+
11+
if(opts.workingDir && !opts.workingDir === '!source')
12+
msTest.workingDir = opts.workingDir;
13+
14+
msTest.noIsolation = opts.noIsolation;
15+
msTest.testSettings = opts.testSettings;
16+
msTest.runConfig = opts.runConfig;
17+
msTest.resultsFile = opts.resultsFile;
18+
msTest.debugLog = opts.debugLog;
19+
msTest.useStdErr = opts.useStdErr;
20+
21+
return through.obj(function (file, enc, cb) {
22+
if(file.isNull())
23+
return cb(null, file);
24+
25+
if(file.isStream())
26+
return cb(new gutil.PluginError('gulp-mstest', 'Streaming not supported'));
27+
28+
gutil.log(gutil.colors.italic(gutil.colors.bold(`Running tests in ${file.path}`)));
29+
30+
try {
31+
msTest.testContainer = file.path;
32+
if(opts.workingDir === '!source') {
33+
let index = file.path.lastIndexOf('/');
34+
if(index === -1)
35+
index = file.path.lastIndexOf('\\');
36+
37+
let dir = file.path.substr(0, index);
38+
if(dir.length === 0)
39+
dir = '.';
40+
41+
msTest.workingDir = dir;
42+
gutil.log(gutil.colors.italic(gutil.colors.bold(`Setting working directory to "${dir}".`)));
43+
}
44+
45+
msTest.runTests({
46+
eachTest: test => {
47+
if(opts.outputEachResult) {
48+
if(test.passed) {
49+
gutil.log(gutil.colors.bgGreen(`${test.status} - ${test.name}`));
50+
}
51+
else {
52+
gutil.log(gutil.colors.bgRed(`${test.status} - ${test.name}`));
53+
if(opts.errorMessage)
54+
gutil.log(gutil.colors.bgRed(test.errorMessage));
55+
if(opts.errorStackTrace)
56+
gutil.log(gutil.colors.bgRed(test.errorStackTrace));
57+
}
58+
}
59+
},
60+
done: (results, passed, failed) => {
61+
if(opts.outputFinalCount) {
62+
gutil.log(gutil.colors.underline(`Passed ${gutil.colors.green(passed.length)}/${gutil.colors.blue(results.length)} tests.`));
63+
}
64+
65+
var error = null;
66+
67+
if(opts.quitOnFailed && failed.length > 0) {
68+
var errorMessage = gutil.colors.red('Tests failed');
69+
if(opts.errorMessage || opts.errorStackTrace) {
70+
errorMessage += ':\n\t';
71+
errorMessage += failed.map(function (test) {
72+
var msg = gutil.colors.underline(gutil.colors.bold(gutil.colors.yellow(test.name)));
73+
if(opts.errorMessage)
74+
msg += `\n\t\tError Message: ${gutil.colors.yellow(test.errorMessage)}`;
75+
if(opts.errorStackTrace)
76+
msg += `\n\t\tStack Trace: ${gutil.colors.magenta(test.errorStackTrace)}`;
77+
return msg;
78+
}).join('\n\t');
79+
}
80+
error = new gutil.PluginError('gulp-mstest', errorMessage);
81+
}
82+
83+
cb(error, {
84+
results: results,
85+
passed: passed,
86+
failed: failed
87+
});
88+
}
89+
});
90+
}
91+
catch (err) {
92+
this.emit('error', new gutil.PluginError('gulp-mstest', err, {
93+
fileName: file.path,
94+
showProperties: false
95+
}));
96+
}
97+
});
98+
}

0 commit comments

Comments
 (0)