-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e55175
commit f9de4ec
Showing
11 changed files
with
123 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* text=auto | ||
*.js text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '4' | ||
- '6' | ||
- '7' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
'use strict'; | ||
|
||
const dargs = require('dargs'); | ||
const execa = require('execa'); | ||
const gutil = require('gulp-util'); | ||
const through = require('through2'); | ||
|
||
module.exports = options => { | ||
const defaults = {colors: true, suppress: false}; | ||
|
||
options = Object.assign(defaults, options); | ||
|
||
if (Object.prototype.toString.call(options.globals) === '[object Array]') { | ||
// typically wouldn't modify passed options, but mocha requires a comma- | ||
// separated list of names, http://mochajs.org/#globals-names, whereas dargs | ||
// will treat arrays differently. | ||
options.globals = options.globals.join(','); | ||
} | ||
|
||
// exposing args for testing | ||
const args = dargs(options, {excludes: ['suppress'], ignoreFalse: true}); | ||
const files = []; | ||
|
||
function aggregate(file, encoding, done) { | ||
if (file.isNull()) { | ||
return done(null, file); | ||
} | ||
|
||
if (file.isStream()) { | ||
return done(new gutil.PluginError('gulp-mocha', 'Streaming not supported')); | ||
} | ||
|
||
files.push(file.path); | ||
|
||
return done(); | ||
} | ||
|
||
function flush(done) { | ||
execa('mocha', files.concat(args)) | ||
.then(result => { | ||
if (!options.suppress) { | ||
process.stdout.write(result.stdout); | ||
} | ||
|
||
this.emit('result', result); | ||
done(); | ||
}) | ||
.catch(err => { | ||
this.emit('error', new gutil.PluginError('gulp-mocha', err)); | ||
done(); | ||
}); | ||
} | ||
|
||
return through.obj(aggregate, flush); | ||
module.exports = opts => { | ||
opts = Object.assign({ | ||
colors: true, | ||
suppress: false | ||
}, opts); | ||
|
||
if (Array.isArray(opts.globals)) { | ||
// `globals` option should end up as a comma-separated list | ||
opts.globals = opts.globals.join(','); | ||
} | ||
|
||
const args = dargs(opts, { | ||
excludes: ['suppress'], | ||
ignoreFalse: true | ||
}); | ||
|
||
const files = []; | ||
|
||
function aggregate(file, encoding, done) { | ||
if (file.isNull()) { | ||
done(null, file); | ||
return; | ||
} | ||
|
||
if (file.isStream()) { | ||
done(new gutil.PluginError('gulp-mocha', 'Streaming not supported')); | ||
return; | ||
} | ||
|
||
files.push(file.path); | ||
|
||
done(); | ||
} | ||
|
||
function flush(done) { | ||
execa('mocha', files.concat(args)) | ||
.then(result => { | ||
if (!opts.suppress) { | ||
process.stdout.write(result.stdout); | ||
} | ||
|
||
// For testing | ||
this.emit('_result', result); | ||
|
||
done(); | ||
}) | ||
.catch(err => { | ||
this.emit('error', new gutil.PluginError('gulp-mocha', err)); | ||
done(); | ||
}); | ||
} | ||
|
||
return through.obj(aggregate, flush); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,6 @@ | |
"envs": [ | ||
"node", | ||
"mocha" | ||
], | ||
"space": true | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
/* global it */ | ||
'use strict'; | ||
var assert = require('assert'); | ||
const assert = require('assert'); | ||
|
||
it('should fail after timeout', function (done) { | ||
setTimeout(function () { | ||
assert(false); | ||
}, 10); | ||
it('should fail after timeout', (done) => { | ||
setTimeout(() => { | ||
assert(false); | ||
}, 10); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
const assert = require('assert'); | ||
|
||
it('should fail', function () { | ||
assert(false); | ||
it('should fail', () => { | ||
assert(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
const assert = require('assert'); | ||
|
||
it('should pass', function () { | ||
assert(true); | ||
it('should pass', () => { | ||
assert(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
const assert = require('assert'); | ||
|
||
it('throws after timeout', function (done) { | ||
setTimeout(function () { | ||
throw new Error('Exception in delayed function'); | ||
}, 10); | ||
it('throws after timeout', () => { | ||
setTimeout(() => { | ||
throw new Error('Exception in delayed function'); | ||
}, 10); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
const assert = require('assert'); | ||
|
||
it('contains syntax errors', function () { | ||
assert false; | ||
it('contains syntax errors', () => { | ||
assert false; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,64 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const gutil = require('gulp-util'); | ||
const mocha = require('../'); | ||
const mocha = require('..'); | ||
|
||
function fixture(name) { | ||
let fileName = path.join(__dirname, 'fixtures', name); | ||
const fileName = path.join(__dirname, 'fixtures', name); | ||
|
||
return new gutil.File({ | ||
path: fileName, | ||
contents: fs.existsSync(fileName) ? fs.readFileSync(fileName) : null | ||
}); | ||
return new gutil.File({ | ||
path: fileName, | ||
contents: fs.existsSync(fileName) ? fs.readFileSync(fileName) : null | ||
}); | ||
} | ||
|
||
describe('mocha()', () => { | ||
it('should run unit test and pass', done => { | ||
let stream = mocha({suppress: true}); | ||
it('should run unit test and pass', done => { | ||
const stream = mocha({suppress: true}); | ||
|
||
stream.once('result', result => { | ||
assert(/1 passing/.test(result.stdout)); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-pass.js')); | ||
stream.end(); | ||
}); | ||
stream.once('_result', result => { | ||
assert(/1 passing/.test(result.stdout)); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-pass.js')); | ||
stream.end(); | ||
}); | ||
|
||
it('should run unit test and fail', done => { | ||
let stream = mocha({suppress: true}); | ||
it('should run unit test and fail', done => { | ||
const stream = mocha({suppress: true}); | ||
|
||
stream.once('error', function (err) { | ||
assert(/1 failing/.test(err.stdout)); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-fail.js')); | ||
stream.end(); | ||
}); | ||
stream.once('error', err => { | ||
assert(/1 failing/.test(err.stdout)); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-fail.js')); | ||
stream.end(); | ||
}); | ||
|
||
it('should pass async AssertionError to mocha', function (done) { | ||
let stream = mocha({suppress: true}); | ||
it('should pass async AssertionError to mocha', done => { | ||
const stream = mocha({suppress: true}); | ||
|
||
stream.once('error', function (err) { | ||
let throws = /throws after timeout/.test(err.stdout); | ||
let uncaught = /Uncaught AssertionError: false == true/.test(err.stdout); | ||
stream.once('error', err => { | ||
const throws = /throws after timeout/.test(err.stdout); | ||
const uncaught = /Uncaught AssertionError: false == true/.test(err.stdout); | ||
|
||
assert(throws || uncaught); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-async.js')); | ||
stream.end(); | ||
}); | ||
assert(throws || uncaught); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-async.js')); | ||
stream.end(); | ||
}); | ||
|
||
it('should not suppress output', done => { | ||
let stream = mocha(); | ||
it('should not suppress output', done => { | ||
const stream = mocha(); | ||
|
||
stream.once('result', result => { | ||
assert(/should pass/.test(result.stdout)); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-pass.js')); | ||
stream.end(); | ||
}); | ||
stream.once('_result', result => { | ||
assert(/should pass/.test(result.stdout)); | ||
done(); | ||
}); | ||
stream.write(fixture('fixture-pass.js')); | ||
stream.end(); | ||
}); | ||
}); |