Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into issue/2755
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jan 5, 2019
2 parents 59709f6 + cb1c6b0 commit 3388c9b
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/_includes/head.html
Expand Up @@ -2,6 +2,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{{ page.title }}</title>
<meta name="description" content="{{ page.description }}">
<link rel="preconnect" href="https://opencollective.com">
<link rel="preconnect" href="https://www.google-analytics.com">
<link rel="preconnect" href="https://stats.g.doubleclick.net">
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
@@ -1,6 +1,7 @@
---
layout: default
title: 'Mocha - the fun, simple, flexible JavaScript test framework'
description: 'Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun.'
---
Mocha is a feature-rich JavaScript test framework running on [Node.js](https://nodejs.org) and in the browser, making asynchronous testing *simple* and *fun*. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. Hosted on [GitHub](https://github.com/mochajs/mocha).

Expand Down
14 changes: 11 additions & 3 deletions lib/cli/run-helpers.js
Expand Up @@ -14,7 +14,6 @@ const path = require('path');
const utils = require('../utils');
const minimatch = require('minimatch');
const ansi = require('ansi-colors');
const symbols = require('log-symbols');

const cwd = (exports.cwd = process.cwd());

Expand Down Expand Up @@ -138,13 +137,14 @@ exports.handleFiles = ({
spec = []
} = {}) => {
let files = [];
const errors = [];
spec.forEach(arg => {
let newFiles;
try {
newFiles = utils.lookupFiles(arg, extension, recursive);
} catch (err) {
if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') {
console.warn('Warning: %s: %O', err.message, err.pattern);
errors.push(err.message);
return;
}

Expand All @@ -164,8 +164,16 @@ exports.handleFiles = ({
});

if (!files.length) {
console.error(ansi.red(`${symbols.error} No test files found`));
// print messages as an error
errors.forEach(message => {
console.error(ansi.red(`Error: ${message}`));
});
process.exit(1);
} else {
// print messages as an warning
errors.forEach(message => {
console.warn(ansi.yellow(`Warning: ${message}`));
});
}

const fileArgs = file.map(filepath => path.resolve(filepath));
Expand Down
7 changes: 0 additions & 7 deletions lib/mocha.js
Expand Up @@ -238,13 +238,6 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
}
}
}
if (!_reporter && reporter === 'teamcity') {
console.warn(
'The Teamcity reporter was moved to a package named ' +
'mocha-teamcity-reporter ' +
'(https://npmjs.org/package/mocha-teamcity-reporter).'
);
}
if (!_reporter) {
throw createInvalidReporterError(
'invalid reporter "' + reporter + '"',
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Expand Up @@ -520,7 +520,7 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
files = glob.sync(filepath);
if (!files.length) {
throw createNoFilesMatchPatternError(
'cannot find any files matching pattern "' + filepath + '"',
'Cannot find any files matching pattern "' + filepath + '"',
filepath
);
}
Expand Down
59 changes: 59 additions & 0 deletions test/integration/events.spec.js
@@ -0,0 +1,59 @@
'use strict';

var helpers = require('./helpers');
var runMochaJSON = helpers.runMochaJSON;

describe('event order', function() {
describe('trivial test case', function() {
it('should assert trivial event order', function(done) {
runMochaJSON('runner/events-basic.fixture.js', [], function(err, res) {
if (err) {
done(err);
return;
}
expect(res, 'to have passed')
.and('to have passed test count', 2)
.and('to have passed test order', 'test A', 'test B')
.and('to have failed test count', 0);
done();
});
});
});

describe('--bail test case', function() {
it('should assert --bail event order', function(done) {
runMochaJSON('runner/events-bail.fixture.js', ['--bail'], function(
err,
res
) {
if (err) {
done(err);
return;
}
expect(res, 'to have failed with error', 'error test A')
.and('to have failed test count', 1)
.and('to have passed test count', 0);
done();
});
});
});

describe('--retries test case', function() {
it('should assert --retries event order', function(done) {
runMochaJSON(
'runner/events-retries.fixture.js',
['--retries', '1'],
function(err, res) {
if (err) {
done(err);
return;
}
expect(res, 'to have failed with error', 'error test A')
.and('to have failed test count', 1)
.and('to have passed test count', 0);
done();
}
);
});
});
});
29 changes: 29 additions & 0 deletions test/integration/fixtures/runner/events-bail.fixture.js
@@ -0,0 +1,29 @@
'use strict';
var Runner = require('../../../../lib/runner.js');
var assert = require('assert');

var emitOrder = [
'suite'/* incorrect order*/, 'start', 'suite',
'hook', 'hook end', 'test', 'hook', 'hook end', 'fail', 'test end', 'hook', 'hook end',
'hook', 'hook end', 'suite end', 'suite end', 'end'
];

var realEmit = Runner.prototype.emit;
Runner.prototype.emit = function(event, ...args) {
// console.log(`emit: ${event}`);
assert.strictEqual(event, emitOrder.shift());
return realEmit.call(this, event, ...args);
};

describe('suite A', function() {
before('before', function() {});
beforeEach('beforeEach', function() {});
it('test A', function() {
throw new Error('error test A');
});
describe('suite B', function() {
it('test B', function() {});
});
afterEach('afterEach', function() {});
after('after', function() {});
});
28 changes: 28 additions & 0 deletions test/integration/fixtures/runner/events-basic.fixture.js
@@ -0,0 +1,28 @@
'use strict';
var Runner = require('../../../../lib/runner.js');
var assert = require('assert');

var emitOrder = [
'suite'/* incorrect order*/, 'start', 'suite',
'hook', 'hook end', 'test', 'hook', 'hook end', 'pass', 'test end', 'hook', 'hook end',
'suite', 'test', 'hook', 'hook end', 'pass', 'test end', 'hook', 'hook end',
'suite end', 'hook', 'hook end', 'suite end', 'suite end', 'end'
];

var realEmit = Runner.prototype.emit;
Runner.prototype.emit = function(event, ...args) {
// console.log(`emit: ${event}`);
assert.strictEqual(event, emitOrder.shift());
return realEmit.call(this, event, ...args);
};

describe('suite A', function() {
before('before', function() {});
beforeEach('beforeEach', function() {});
it('test A', function() {});
describe('suite B', function() {
it('test B', function() {});
});
afterEach('afterEach', function() {});
after('after', function() {});
});
27 changes: 27 additions & 0 deletions test/integration/fixtures/runner/events-retries.fixture.js
@@ -0,0 +1,27 @@
'use strict';
var Runner = require('../../../../lib/runner.js');
var assert = require('assert');

var emitOrder = [
'suite'/* incorrect order*/, 'start', 'suite',
'hook', 'hook end', 'test', 'hook', 'hook end', 'retry', 'hook', 'hook end',
'test', 'hook', 'hook end', 'fail', 'test end', 'hook', 'hook end', 'hook', 'hook end',
'suite end', 'suite end', 'end'
];

var realEmit = Runner.prototype.emit;
Runner.prototype.emit = function(event, ...args) {
// console.log(`emit: ${event}`);
assert.strictEqual(event, emitOrder.shift());
return realEmit.call(this, event, ...args);
};

describe('suite A', function() {
before('before', function() {});
beforeEach('beforeEach', function() {});
it('test A', function() {
throw new Error('error test A');
});
afterEach('afterEach', function() {});
after('after', function() {});
});
12 changes: 6 additions & 6 deletions test/integration/glob.spec.js
Expand Up @@ -28,7 +28,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern "./*-none.js"'
'Error: Cannot find any files matching pattern "./*-none.js"'
);
},
done
Expand All @@ -47,7 +47,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern'
'Warning: Cannot find any files matching pattern'
);
},
done
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern'
'Error: Cannot find any files matching pattern "./*-none.js"'
);
},
done
Expand All @@ -96,7 +96,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern'
'Warning: Cannot find any files matching pattern'
);
},
done
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern'
'Error: Cannot find any files matching pattern "./**/*-none.js"'
);
},
done
Expand All @@ -144,7 +144,7 @@ describe('globbing', function() {
expect(
results.stderr,
'to contain',
'cannot find any files matching pattern'
'Warning: Cannot find any files matching pattern'
);
},
done
Expand Down
2 changes: 1 addition & 1 deletion test/node-unit/cli/run-helpers.spec.js
Expand Up @@ -19,7 +19,7 @@ describe('cli "run" command', function() {
it('should disallow an array of module names', function() {
expect(
() => validatePlugin({foo: ['bar']}, 'foo'),
'to throw',
'to throw a',
TypeError
);
});
Expand Down

0 comments on commit 3388c9b

Please sign in to comment.