Skip to content

Commit 4924437

Browse files
committed
Update Mocha and require Node.js and Gulp 4
1 parent cde8dc2 commit 4924437

File tree

6 files changed

+64
-79
lines changed

6 files changed

+64
-79
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
22
node_js:
3+
- '12'
34
- '10'
45
- '8'
5-
- '6'

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const gulp = require('gulp');
33
const mocha = require('.');
44

5-
gulp.task('default', () =>
5+
exports.default = () => (
66
gulp.src('test/fixtures/fixture-pass.js', {read: false})
77
.pipe(mocha())
88
);

index.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,33 @@ const execa = require('execa');
44
const PluginError = require('plugin-error');
55
const supportsColor = require('supports-color');
66
const through = require('through2');
7-
// TODO: Use execa localDir option when available
8-
const npmRunPath = require('npm-run-path');
97
const utils = require('./utils');
108

11-
const HUNDRED_MEGABYTES = 1000 * 1000 * 100;
12-
139
// Mocha options that can be specified multiple times
1410
const MULTIPLE_OPTS = new Set([
1511
'require'
1612
]);
1713

18-
module.exports = opts => {
19-
opts = Object.assign({
14+
module.exports = options => {
15+
options = {
2016
colors: Boolean(supportsColor.stdout),
21-
suppress: false
22-
}, opts);
23-
24-
for (const key of Object.keys(opts)) {
25-
const val = opts[key];
17+
suppress: false,
18+
...options
19+
};
2620

27-
if (Array.isArray(val)) {
21+
for (const [key, value] of Object.entries(options)) {
22+
if (Array.isArray(value)) {
2823
if (!MULTIPLE_OPTS.has(key)) {
2924
// Convert arrays into comma separated lists
30-
opts[key] = val.join(',');
25+
options[key] = value.join(',');
3126
}
32-
} else if (typeof val === 'object') {
27+
} else if (typeof value === 'object') {
3328
// Convert an object into comma separated list
34-
opts[key] = utils.convertObjectToList(val);
29+
options[key] = utils.convertObjectToList(value);
3530
}
3631
}
3732

38-
const args = dargs(opts, {
33+
const args = dargs(options, {
3934
excludes: ['suppress'],
4035
ignoreFalse: true
4136
});
@@ -54,26 +49,25 @@ module.exports = opts => {
5449
}
5550

5651
function flush(done) {
57-
const env = npmRunPath.env({cwd: __dirname});
58-
const proc = execa('mocha', files.concat(args), {
59-
env,
60-
maxBuffer: HUNDRED_MEGABYTES
61-
});
52+
(async () => {
53+
const subprocess = execa('mocha', files.concat(args), {
54+
localDir: __dirname
55+
});
56+
57+
if (!options.suppress) {
58+
subprocess.stdout.pipe(subprocess.stdout);
59+
subprocess.stderr.pipe(subprocess.stderr);
60+
}
6261

63-
proc
64-
.then(result => {
62+
try {
63+
const result = await subprocess;
6564
this.emit('_result', result);
66-
done();
67-
})
68-
.catch(err => {
69-
this.emit('error', new PluginError('gulp-mocha', err.code > 0 ? 'There were test failures' : err));
70-
done();
71-
});
65+
} catch (error) {
66+
this.emit('error', new PluginError('gulp-mocha', error.exitCode > 0 ? 'There were test failures' : error));
67+
}
7268

73-
if (!opts.suppress) {
74-
proc.stdout.pipe(process.stdout);
75-
proc.stderr.pipe(process.stderr);
76-
}
69+
done();
70+
})();
7771
}
7872

7973
return through.obj(aggregate, flush);

package.json

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=6"
13+
"node": ">=8"
1414
},
1515
"scripts": {
1616
"test": "xo && ava"
@@ -34,19 +34,34 @@
3434
"tap"
3535
],
3636
"dependencies": {
37-
"dargs": "^5.1.0",
38-
"execa": "^0.10.0",
39-
"mocha": "^5.2.0",
40-
"npm-run-path": "^2.0.2",
37+
"dargs": "^7.0.0",
38+
"execa": "^2.0.4",
39+
"mocha": "^6.2.0",
4140
"plugin-error": "^1.0.1",
42-
"supports-color": "^5.4.0",
43-
"through2": "^2.0.3"
41+
"supports-color": "^7.0.0",
42+
"through2": "^3.0.1"
4443
},
4544
"devDependencies": {
46-
"ava": "*",
47-
"gulp": "^3.9.1",
48-
"p-event": "^1.0.0",
45+
"ava": "^2.3.0",
46+
"gulp": "^4.0.2",
47+
"p-event": "^4.1.0",
4948
"vinyl": "^2.1.0",
50-
"xo": "*"
49+
"xo": "^0.24.0"
50+
},
51+
"peerDependencies": {
52+
"gulp": ">=4"
53+
},
54+
"xo": {
55+
"ignores": [
56+
"test/fixtures"
57+
],
58+
"rules": {
59+
"ava/no-ignored-test-files": "off"
60+
}
61+
},
62+
"ava": {
63+
"files": [
64+
"test/test.js"
65+
]
5166
}
5267
}

readme.md

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
**[Maintainer needed](https://github.com/sindresorhus/gulp-mocha/issues/128)**
88

9-
---
10-
11-
<p align="center"><b>🔥 Want to strengthen your core JavaScript skills and master ES6?</b><br>I would personally recommend this awesome <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos. You might also like his <a href="https://ReactForBeginners.com/friend/AWESOME">React course</a>.</p>
12-
13-
---
14-
159

1610
## Install
1711

@@ -26,7 +20,7 @@ $ npm install --save-dev gulp-mocha
2620
const gulp = require('gulp');
2721
const mocha = require('gulp-mocha');
2822

29-
gulp.task('default', () =>
23+
exports.default = () => (
3024
gulp.src('test.js', {read: false})
3125
// `gulp-mocha` needs filepaths so you can't have any plugins before it
3226
.pipe(mocha({reporter: 'nyan'}))
@@ -36,15 +30,14 @@ gulp.task('default', () =>
3630

3731
## API
3832

39-
### mocha([options])
33+
### mocha(options?)
4034

4135
#### options
4236

43-
Type: `Object`
37+
Type: `object`
4438

4539
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:
4640

47-
4841
##### ui
4942

5043
Type: `string`<br>
@@ -65,14 +58,14 @@ This option can also be used to utilize third-party reporters. For example, if y
6558

6659
##### reporterOptions
6760

68-
Type: `Object`<br>
61+
Type: `object`<br>
6962
Example: `{reportFilename: 'index.html'}`
7063

7164
Reporter specific options.
7265

7366
##### globals
7467

75-
Type: `Array`
68+
Type: `string[]`
7669

7770
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).
7871

@@ -105,7 +98,7 @@ Only run tests matching the given pattern which is internally compiled to a RegE
10598

10699
##### require
107100

108-
Type: `Array`
101+
Type: `string[]`
109102

110103
Require custom modules before tests are run.
111104

@@ -124,7 +117,7 @@ Specify a compiler.
124117
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:
125118

126119
```js
127-
gulp.task('default', () =>
120+
exports.default = () => (
128121
gulp.src('test.js')
129122
.pipe(mocha())
130123
.once('error', err => {
@@ -140,14 +133,9 @@ gulp.task('default', () =>
140133
Or you might just need to pass the `exit` option:
141134

142135
```js
143-
gulp.task('test', () =>
136+
exports.test = () => (
144137
gulp.src(['test/**/*.js'], {read: false})
145138
.pipe(mocha({reporter: 'list', exit: true}))
146139
.on('error', console.error)
147140
);
148141
```
149-
150-
151-
## License
152-
153-
MIT © [Sindre Sorhus](https://sindresorhus.com)

utils.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
'use strict';
22

3-
// TODO: Use `Object.entries` when targeting Node.js 8
4-
function objectEntries(object) {
5-
const entries = [];
6-
7-
for (const key of Object.keys(object)) {
8-
const value = object[key];
9-
entries.push([key, value]);
10-
}
11-
12-
return entries;
13-
}
14-
153
function convertObjectToList(object) {
16-
return objectEntries(object)
4+
return Object.entries(object)
175
.reduce((result, current) => result.concat(`${current[0]}=${current[1]}`), [])
186
.join(',');
197
}

0 commit comments

Comments
 (0)