pax_global_header00006660000000000000000000000064135455777450014540gustar00rootroot0000000000000052 comment=6ab007b4ab7ee15459c9b9dcd9cf7a8fbd3ae227 gulp-mocha-7.0.2/000077500000000000000000000000001354557774500136025ustar00rootroot00000000000000gulp-mocha-7.0.2/.editorconfig000066400000000000000000000002571354557774500162630ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 gulp-mocha-7.0.2/.gitattributes000066400000000000000000000000231354557774500164700ustar00rootroot00000000000000* text=auto eol=lf gulp-mocha-7.0.2/.gitignore000066400000000000000000000000271354557774500155710ustar00rootroot00000000000000node_modules yarn.lock gulp-mocha-7.0.2/.npmrc000066400000000000000000000000231354557774500147150ustar00rootroot00000000000000package-lock=false gulp-mocha-7.0.2/.travis.yml000066400000000000000000000000651354557774500157140ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' gulp-mocha-7.0.2/gulpfile.js000066400000000000000000000002611354557774500157460ustar00rootroot00000000000000'use strict'; const gulp = require('gulp'); const mocha = require('.'); exports.default = () => ( gulp.src('test/fixtures/fixture-pass.js', {read: false}) .pipe(mocha()) ); gulp-mocha-7.0.2/index.js000066400000000000000000000032241354557774500152500ustar00rootroot00000000000000'use strict'; const dargs = require('dargs'); const execa = require('execa'); const PluginError = require('plugin-error'); const supportsColor = require('supports-color'); const through = require('through2'); const utils = require('./utils'); // Mocha options that can be specified multiple times const MULTIPLE_OPTS = new Set([ 'require' ]); module.exports = options => { options = { colors: Boolean(supportsColor.stdout), suppress: false, ...options }; for (const [key, value] of Object.entries(options)) { if (Array.isArray(value)) { if (!MULTIPLE_OPTS.has(key)) { // Convert arrays into comma separated lists options[key] = value.join(','); } } else if (typeof value === 'object') { // Convert an object into comma separated list options[key] = utils.convertObjectToList(value); } } const args = dargs(options, { excludes: ['suppress'], ignoreFalse: true }); const files = []; function aggregate(file, encoding, done) { if (file.isStream()) { done(new PluginError('gulp-mocha', 'Streaming not supported')); return; } files.push(file.path); done(); } function flush(done) { (async () => { const subprocess = execa('mocha', files.concat(args), { localDir: __dirname, preferLocal: true }); if (!options.suppress) { subprocess.stdout.pipe(process.stdout); subprocess.stderr.pipe(process.stderr); } try { const result = await subprocess; this.emit('_result', result); } catch (error) { this.emit('error', new PluginError('gulp-mocha', error.exitCode > 0 ? 'There were test failures' : error)); } done(); })(); } return through.obj(aggregate, flush); }; gulp-mocha-7.0.2/license000066400000000000000000000021251354557774500151470ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gulp-mocha-7.0.2/package.json000066400000000000000000000020721354557774500160710ustar00rootroot00000000000000{ "name": "gulp-mocha", "version": "7.0.2", "description": "Run Mocha tests", "license": "MIT", "repository": "sindresorhus/gulp-mocha", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js", "utils.js" ], "keywords": [ "gulpplugin", "mocha", "test", "testing", "unit", "framework", "runner", "tdd", "bdd", "qunit", "spec", "tap" ], "dependencies": { "dargs": "^7.0.0", "execa": "^2.0.4", "mocha": "^6.2.0", "plugin-error": "^1.0.1", "supports-color": "^7.0.0", "through2": "^3.0.1" }, "devDependencies": { "ava": "^2.3.0", "gulp": "^4.0.2", "p-event": "^4.1.0", "vinyl": "^2.1.0", "xo": "^0.24.0" }, "peerDependencies": { "gulp": ">=4" }, "peerDependenciesMeta": { "gulp": { "optional": true } }, "xo": { "ignores": [ "test/fixtures" ], "rules": { "ava/no-ignored-test-files": "off" } }, "ava": { "files": [ "test/test.js" ] } } gulp-mocha-7.0.2/readme.md000066400000000000000000000057521354557774500153720ustar00rootroot00000000000000# gulp-mocha [![Build Status](https://travis-ci.org/sindresorhus/gulp-mocha.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-mocha) > Run [Mocha](https://github.com/mochajs/mocha) tests *Keep in mind that this is just a thin wrapper around Mocha and your issue is most likely with Mocha.* **[Maintainer needed](https://github.com/sindresorhus/gulp-mocha/issues/128)** ## Install ``` $ npm install --save-dev gulp-mocha ``` ## Usage ```js const gulp = require('gulp'); const mocha = require('gulp-mocha'); exports.default = () => ( gulp.src('test.js', {read: false}) // `gulp-mocha` needs filepaths so you can't have any plugins before it .pipe(mocha({reporter: 'nyan'})) ); ``` ## API ### mocha(options?) #### options Type: `object` Options are passed directly to the `mocha` binary, so you can use any its [command-line options](http://mochajs.org/#usage) in a camelCased form. Arrays and key/value objects are correctly converted to the comma separated list format Mocha expects. Listed below are some of the more commonly used options: ##### ui Type: `string`
Default: `bdd`
Values: `bdd` `tdd` `qunit` `exports` Interface to use. ##### reporter Type: `string`
Default: `spec` Values: [Reporters](https://github.com/mochajs/mocha/tree/master/lib/reporters) Reporter that will be used. This option can also be used to utilize third-party reporters. For example, if you `npm install mocha-lcov-reporter` you can then do use `mocha-lcov-reporter` as value. ##### reporterOptions Type: `object`
Example: `{reportFilename: 'index.html'}` Reporter specific options. ##### globals Type: `string[]` List of accepted global variable names, example `['YUI']`. Accepts wildcards to match multiple global variables, e.g. `['gulp*']` or even `['*']`. See [Mocha globals option](http://mochajs.org/#globals-option). ##### timeout Type: `number`
Default: `2000` Test-case timeout in milliseconds. ##### bail Type: `boolean`
Default: `false` Bail on the first test failure. ##### checkLeaks Type: `boolean`
Default: `false` Check for global variable leaks. ##### grep Type: `string` Only run tests matching the given pattern which is internally compiled to a RegExp. ##### require Type: `string[]` Require custom modules before tests are run. ##### compilers Type: `string`
Example: `js:babel-core/register` Specify a compiler. ## FAQ ### Test suite not exiting If your test suite is not exiting it might be because you still have a lingering callback, most often caused by an open database connection. You should close this connection or do the following: ```js exports.default = () => ( gulp.src('test.js') .pipe(mocha()) .once('error', err => { console.error(err); process.exit(1); }) .once('end', () => { process.exit(); }) ); ``` Or you might just need to pass the `exit` option: ```js exports.test = () => ( gulp.src(['test/**/*.js'], {read: false}) .pipe(mocha({reporter: 'list', exit: true})) .on('error', console.error) ); ``` gulp-mocha-7.0.2/test/000077500000000000000000000000001354557774500145615ustar00rootroot00000000000000gulp-mocha-7.0.2/test/fixtures/000077500000000000000000000000001354557774500164325ustar00rootroot00000000000000gulp-mocha-7.0.2/test/fixtures/fixture-async.js000066400000000000000000000002151354557774500215670ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('should fail after timeout', done => { setTimeout(() => { assert(false); }, 10); }); gulp-mocha-7.0.2/test/fixtures/fixture-fail.js000066400000000000000000000001371354557774500213700ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('should fail', () => { assert(false); }); gulp-mocha-7.0.2/test/fixtures/fixture-pass.js000066400000000000000000000001361354557774500214220ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('should pass', () => { assert(true); }); gulp-mocha-7.0.2/test/fixtures/fixture-require1.js000066400000000000000000000000161354557774500222060ustar00rootroot00000000000000'use strict'; gulp-mocha-7.0.2/test/fixtures/fixture-require2.js000066400000000000000000000000161354557774500222070ustar00rootroot00000000000000'use strict'; gulp-mocha-7.0.2/test/fixtures/fixture-throws-uncaught.js000066400000000000000000000002511354557774500236140ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('throws after timeout', () => { setTimeout(() => { throw new Error('Exception in delayed function'); }, 10); }); gulp-mocha-7.0.2/test/fixtures/fixture-throws.js000066400000000000000000000001511354557774500217770ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('contains syntax errors', () => { assert false; }); gulp-mocha-7.0.2/test/test.js000066400000000000000000000025521354557774500161020ustar00rootroot00000000000000import fs from 'fs'; import path from 'path'; import test from 'ava'; import Vinyl from 'vinyl'; import pEvent from 'p-event'; import mocha from '..'; function fixture(name) { const fileName = path.join(__dirname, 'fixtures', name); return new Vinyl({ path: fileName, contents: fs.existsSync(fileName) ? fs.readFileSync(fileName) : null }); } test('run unit test and pass', async t => { const stream = mocha({suppress: true}); const result = pEvent(stream, '_result'); stream.end(fixture('fixture-pass.js')); t.regex((await result).stdout, /1 passing/); }); test('run unit test and fail', async t => { const stream = mocha({suppress: true}); const error = pEvent(stream, 'error'); stream.end(fixture('fixture-fail.js')); t.regex((await error).message, /There were test failures/); }); test('pass async AssertionError to mocha', async t => { const stream = mocha({suppress: true}); const event = pEvent(stream, 'error'); stream.end(fixture('fixture-async.js')); const error = await event; t.regex(error.message, /There were test failures/); }); test('require two files', async t => { const stream = mocha({ suppress: true, require: [ 'test/fixtures/fixture-require1.js', 'test/fixtures/fixture-require2.js' ] }); const result = pEvent(stream, '_result'); stream.end(fixture('fixture-pass.js')); t.regex((await result).stdout, /1 passing/); }); gulp-mocha-7.0.2/test/utils.js000066400000000000000000000004051354557774500162560ustar00rootroot00000000000000import test from 'ava'; import m from '../utils'; test('convertObjectToList produces a comma separated string of k=v', t => { t.is( m.convertObjectToList({key1: 'value1', key2: 'value2', key99: 'value99'}), 'key1=value1,key2=value2,key99=value99' ); }); gulp-mocha-7.0.2/utils.js000066400000000000000000000003421354557774500152770ustar00rootroot00000000000000'use strict'; function convertObjectToList(object) { return Object.entries(object) .reduce((result, current) => result.concat(`${current[0]}=${current[1]}`), []) .join(','); } module.exports = { convertObjectToList };