pax_global_header00006660000000000000000000000064140134115210014502gustar00rootroot0000000000000052 comment=2f0b8108fb7a892cb658e5fb15fb003e0c40545f gulp-mocha-8.0.0/000077500000000000000000000000001401341152100135435ustar00rootroot00000000000000gulp-mocha-8.0.0/.editorconfig000066400000000000000000000002571401341152100162240ustar00rootroot00000000000000root = 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-8.0.0/.gitattributes000066400000000000000000000000231401341152100164310ustar00rootroot00000000000000* text=auto eol=lf gulp-mocha-8.0.0/.github/000077500000000000000000000000001401341152100151035ustar00rootroot00000000000000gulp-mocha-8.0.0/.github/workflows/000077500000000000000000000000001401341152100171405ustar00rootroot00000000000000gulp-mocha-8.0.0/.github/workflows/main.yml000066400000000000000000000007021401341152100206060ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 - 10 - 8 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test gulp-mocha-8.0.0/.gitignore000066400000000000000000000000271401341152100155320ustar00rootroot00000000000000node_modules yarn.lock gulp-mocha-8.0.0/.npmrc000066400000000000000000000000231401341152100146560ustar00rootroot00000000000000package-lock=false gulp-mocha-8.0.0/gulpfile.js000066400000000000000000000002611401341152100157070ustar00rootroot00000000000000'use strict'; const gulp = require('gulp'); const mocha = require('.'); exports.default = () => ( gulp.src('test/fixtures/fixture-pass.js', {read: false}) .pipe(mocha()) ); gulp-mocha-8.0.0/index.js000066400000000000000000000032241401341152100152110ustar00rootroot00000000000000'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-8.0.0/license000066400000000000000000000021251401341152100151100ustar00rootroot00000000000000MIT 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-8.0.0/package.json000066400000000000000000000021731401341152100160340ustar00rootroot00000000000000{ "name": "gulp-mocha", "version": "8.0.0", "description": "Run Mocha tests", "license": "MIT", "repository": "sindresorhus/gulp-mocha", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "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": "^5.0.0", "mocha": "^8.3.0", "plugin-error": "^1.0.1", "supports-color": "^8.1.1", "through2": "^4.0.2" }, "devDependencies": { "ava": "^2.3.0", "gulp": "^4.0.2", "p-event": "^4.2.0", "vinyl": "^2.2.1", "xo": "^0.37.1" }, "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-8.0.0/readme.md000066400000000000000000000054301401341152100153240ustar00rootroot00000000000000# 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.* ## 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-8.0.0/test/000077500000000000000000000000001401341152100145225ustar00rootroot00000000000000gulp-mocha-8.0.0/test/fixtures/000077500000000000000000000000001401341152100163735ustar00rootroot00000000000000gulp-mocha-8.0.0/test/fixtures/fixture-async.js000066400000000000000000000002151401341152100215300ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('should fail after timeout', done => { setTimeout(() => { assert(false); }, 10); }); gulp-mocha-8.0.0/test/fixtures/fixture-fail.js000066400000000000000000000001371401341152100213310ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('should fail', () => { assert(false); }); gulp-mocha-8.0.0/test/fixtures/fixture-pass.js000066400000000000000000000001361401341152100213630ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('should pass', () => { assert(true); }); gulp-mocha-8.0.0/test/fixtures/fixture-require1.js000066400000000000000000000000161401341152100221470ustar00rootroot00000000000000'use strict'; gulp-mocha-8.0.0/test/fixtures/fixture-require2.js000066400000000000000000000000161401341152100221500ustar00rootroot00000000000000'use strict'; gulp-mocha-8.0.0/test/fixtures/fixture-throws-uncaught.js000066400000000000000000000002511401341152100235550ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('throws after timeout', () => { setTimeout(() => { throw new Error('Exception in delayed function'); }, 10); }); gulp-mocha-8.0.0/test/fixtures/fixture-throws.js000066400000000000000000000001511401341152100217400ustar00rootroot00000000000000'use strict'; const assert = require('assert'); it('contains syntax errors', () => { assert false; }); gulp-mocha-8.0.0/test/test.js000066400000000000000000000025631401341152100160450ustar00rootroot00000000000000import fs from 'fs'; import path from 'path'; import test from 'ava'; import Vinyl from 'vinyl'; import pEvent from 'p-event'; import mocha from '../index.js'; 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-8.0.0/test/utils.js000066400000000000000000000004201401341152100162140ustar00rootroot00000000000000import test from 'ava'; import utils from '../utils.js'; test('convertObjectToList produces a comma separated string of k=v', t => { t.is( utils.convertObjectToList({key1: 'value1', key2: 'value2', key99: 'value99'}), 'key1=value1,key2=value2,key99=value99' ); }); gulp-mocha-8.0.0/utils.js000066400000000000000000000004701401341152100152420ustar00rootroot00000000000000'use strict'; function convertObjectToList(object) { return Object.entries(object) // TODO: Stop using `.reduce` // eslint-disable-next-line unicorn/no-array-reduce .reduce((result, current) => result.concat(`${current[0]}=${current[1]}`), []) .join(','); } module.exports = { convertObjectToList };