gulp-mocha
Advanced tools
Comparing version 9.0.0 to 10.0.0
77
index.js
@@ -1,19 +0,27 @@ | ||
'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.js'); | ||
import process from 'node:process'; | ||
import {fileURLToPath} from 'node:url'; | ||
import path from 'node:path'; | ||
import dargs from 'dargs'; | ||
import {execa} from 'execa'; | ||
import supportsColor from 'supports-color'; | ||
import {gulpPlugin} from 'gulp-plugin-extras'; | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
// Mocha options that can be specified multiple times | ||
const MULTIPLE_OPTS = new Set([ | ||
'require' | ||
const MULTIPLE_OPTIONS = new Set([ | ||
'require', | ||
]); | ||
module.exports = options => { | ||
function convertObjectToList(object) { | ||
return Object.entries(object) | ||
.map(([key, value]) => `${key}=${value}`) | ||
.join(','); | ||
} | ||
export default function gulpMocha(options) { | ||
options = { | ||
colors: Boolean(supportsColor.stdout), | ||
suppress: false, | ||
...options | ||
...options, | ||
}; | ||
@@ -23,3 +31,3 @@ | ||
if (Array.isArray(value)) { | ||
if (!MULTIPLE_OPTS.has(key)) { | ||
if (!MULTIPLE_OPTIONS.has(key)) { | ||
// Convert arrays into comma separated lists | ||
@@ -30,9 +38,9 @@ options[key] = value.join(','); | ||
// Convert an object into comma separated list | ||
options[key] = utils.convertObjectToList(value); | ||
options[key] = convertObjectToList(value); | ||
} | ||
} | ||
const args = dargs(options, { | ||
const arguments_ = dargs(options, { | ||
excludes: ['suppress'], | ||
ignoreFalse: true | ||
ignoreFalse: true, | ||
}); | ||
@@ -42,18 +50,9 @@ | ||
function aggregate(file, encoding, done) { | ||
if (file.isStream()) { | ||
done(new PluginError('gulp-mocha', 'Streaming not supported')); | ||
return; | ||
} | ||
return gulpPlugin('gulp-mocha', file => { | ||
files.push(file.path); | ||
done(); | ||
} | ||
function flush(done) { | ||
(async () => { | ||
const subprocess = execa('mocha', files.concat(args), { | ||
}, { | ||
async * onFinish(stream) { // eslint-disable-line require-yield | ||
const subprocess = execa('mocha', [...files, ...arguments_], { | ||
localDir: __dirname, | ||
preferLocal: true | ||
preferLocal: true, | ||
}); | ||
@@ -68,12 +67,14 @@ | ||
const result = await subprocess; | ||
this.emit('_result', result); | ||
stream.emit('_result', result); | ||
} catch (error) { | ||
this.emit('error', new PluginError('gulp-mocha', error.exitCode > 0 ? 'There were test failures' : error)); | ||
if (error.exitCode > 0) { | ||
const error = new Error('There were test failures'); | ||
error.isPresentable = true; | ||
throw error; | ||
} | ||
throw error; | ||
} | ||
done(); | ||
})(); | ||
} | ||
return through.obj(aggregate, flush); | ||
}; | ||
}, | ||
}); | ||
} |
{ | ||
"name": "gulp-mocha", | ||
"version": "9.0.0", | ||
"version": "10.0.0", | ||
"description": "Run Mocha tests", | ||
@@ -13,2 +13,3 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
@@ -22,4 +23,3 @@ "engines": { | ||
"files": [ | ||
"index.js", | ||
"utils.js" | ||
"index.js" | ||
], | ||
@@ -41,15 +41,14 @@ "keywords": [ | ||
"dependencies": { | ||
"dargs": "^7.0.0", | ||
"execa": "^5.0.0", | ||
"dargs": "^8.1.0", | ||
"execa": "^8.0.1", | ||
"gulp-plugin-extras": "^0.3.0", | ||
"mocha": "^10.2.0", | ||
"plugin-error": "^1.0.1", | ||
"supports-color": "^8.1.1", | ||
"through2": "^4.0.2" | ||
"supports-color": "^9.4.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.3.0", | ||
"ava": "^5.3.1", | ||
"gulp": "^4.0.2", | ||
"p-event": "^4.2.0", | ||
"p-event": "^6.0.0", | ||
"vinyl": "^3.0.0", | ||
"xo": "^0.37.1" | ||
"xo": "^0.56.0" | ||
}, | ||
@@ -56,0 +55,0 @@ "peerDependencies": { |
@@ -7,19 +7,17 @@ # gulp-mocha | ||
## Install | ||
```sh | ||
npm install --save-dev gulp-mocha | ||
``` | ||
$ npm install --save-dev gulp-mocha | ||
``` | ||
## Usage | ||
```js | ||
const gulp = require('gulp'); | ||
const mocha = require('gulp-mocha'); | ||
import gulp from 'gulp'; | ||
import mocha from 'gulp-mocha'; | ||
exports.default = () => ( | ||
export default () => ( | ||
gulp.src('test.js', {read: false}) | ||
// `gulp-mocha` needs filepaths so you can't have any plugins before it | ||
// `gulp-mocha` needs file paths so you cannot have any plugins before it. | ||
.pipe(mocha({reporter: 'nyan'})) | ||
@@ -29,3 +27,2 @@ ); | ||
## API | ||
@@ -43,15 +40,15 @@ | ||
Type: `string`<br> | ||
Default: `bdd`<br> | ||
Values: `bdd` `tdd` `qunit` `exports` | ||
Type: `string`\ | ||
Default: `'bdd'`\ | ||
Values: `'bdd' | 'tdd' | 'qunit' | 'exports'` | ||
Interface to use. | ||
The interface to use. | ||
##### reporter | ||
Type: `string`<br> | ||
Default: `spec` | ||
Type: `string`\ | ||
Default: `spec`\ | ||
Values: [Reporters](https://github.com/mochajs/mocha/tree/master/lib/reporters) | ||
Reporter that will be used. | ||
The reporter that will be used. | ||
@@ -62,3 +59,3 @@ 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. | ||
Type: `object`<br> | ||
Type: `object`\ | ||
Example: `{reportFilename: 'index.html'}` | ||
@@ -76,3 +73,3 @@ | ||
Type: `number`<br> | ||
Type: `number`\ | ||
Default: `2000` | ||
@@ -84,3 +81,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `false` | ||
@@ -92,3 +89,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `false` | ||
@@ -112,3 +109,3 @@ | ||
Type: `string`<br> | ||
Type: `string`\ | ||
Example: `js:babel-core/register` | ||
@@ -118,3 +115,2 @@ | ||
## FAQ | ||
@@ -127,3 +123,3 @@ | ||
```js | ||
exports.default = () => ( | ||
export default () => ( | ||
gulp.src('test.js') | ||
@@ -144,3 +140,3 @@ .pipe(mocha()) | ||
```js | ||
exports.test = () => ( | ||
export const test = () => ( | ||
gulp.src(['test/**/*.js'], {read: false}) | ||
@@ -147,0 +143,0 @@ .pipe(mocha({reporter: 'list', exit: true})) |
6
Yes
6922
4
65
136
+ Addedgulp-plugin-extras@^0.3.0
+ Added@types/expect@1.20.4(transitive)
+ Added@types/node@22.13.1(transitive)
+ Added@types/vinyl@2.0.12(transitive)
+ Addedchalk@5.4.1(transitive)
+ Addeddargs@8.1.0(transitive)
+ Addedeasy-transform-stream@1.0.1(transitive)
+ Addedexeca@8.0.1(transitive)
+ Addedget-stream@8.0.1(transitive)
+ Addedgulp-plugin-extras@0.3.0(transitive)
+ Addedhuman-signals@5.0.0(transitive)
+ Addedis-stream@3.0.0(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addednpm-run-path@5.3.0(transitive)
+ Addedonetime@6.0.0(transitive)
+ Addedpath-key@4.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstrip-final-newline@3.0.0(transitive)
+ Addedsupports-color@9.4.0(transitive)
+ Addedundici-types@6.20.0(transitive)
- Removedplugin-error@^1.0.1
- Removedthrough2@^4.0.2
- Removedansi-colors@1.1.0(transitive)
- Removedansi-wrap@0.1.0(transitive)
- Removedarr-diff@4.0.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removeddargs@7.0.0(transitive)
- Removedexeca@5.1.1(transitive)
- Removedextend-shallow@3.0.2(transitive)
- Removedget-stream@6.0.1(transitive)
- Removedhuman-signals@2.1.0(transitive)
- Removedis-extendable@1.0.1(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-stream@2.0.1(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removednpm-run-path@4.0.1(transitive)
- Removedonetime@5.1.2(transitive)
- Removedplugin-error@1.0.1(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-final-newline@2.0.0(transitive)
- Removedthrough2@4.0.2(transitive)
Updateddargs@^8.1.0
Updatedexeca@^8.0.1
Updatedsupports-color@^9.4.0