Skip to content

Commit

Permalink
fix --ui issues, closes #3746
Browse files Browse the repository at this point in the history
move all ui-related tests into `test/integration/options/ui.spec.js`
  • Loading branch information
boneskull committed Feb 21, 2019
1 parent 00f2ed9 commit 7926f47
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
31 changes: 18 additions & 13 deletions lib/mocha.js
Expand Up @@ -260,25 +260,30 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
* @public
* @see {@link https://mochajs.org/#-u---ui-name|CLI option}
* @see {@link https://mochajs.org/#interfaces|Interface DSLs}
* @param {string} [name=bdd] - Interface name.
* @param {string|Function} [ui=bdd] - Interface name or class.
* @returns {Mocha} this
* @chainable
* @throws {Error} if requested interface cannot be loaded
*/
Mocha.prototype.ui = function(name) {
name = name || 'bdd';
this._ui = exports.interfaces[name];
if (!this._ui) {
try {
this._ui = require(name);
} catch (err) {
throw createInvalidInterfaceError(
'invalid interface ' + sQuote(name),
name
);
Mocha.prototype.ui = function(ui) {
var bindInterface;
if (typeof ui === 'function') {
bindInterface = ui;
} else {
ui = ui || 'bdd';
bindInterface = exports.interfaces[ui];
if (!bindInterface) {
try {
bindInterface = require(ui);
} catch (err) {
throw createInvalidInterfaceError(
'invalid interface ' + sQuote(ui),
ui
);
}
}
}
this._ui = this._ui(this.suite);
bindInterface(this.suite);

this.suite.on(EVENT_FILE_PRE_REQUIRE, function(context) {
exports.afterEach = context.afterEach || context.teardown;
Expand Down
@@ -1,6 +1,6 @@
'use strict';

var Mocha = require('../../../../../lib/mocha');
var Mocha = require('../../../lib/mocha');
var Test = Mocha.Test;
var EVENT_FILE_PRE_REQUIRE = Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE;

Expand All @@ -13,7 +13,7 @@ module.exports = Mocha.interfaces['simple-ui'] = function(suite) {
file,
mocha
) {
var common = require('../../../../../lib/interfaces/common')(
var common = require('../../../lib/interfaces/common')(
[suite],
context
);
Expand Down
34 changes: 34 additions & 0 deletions test/integration/options/ui.spec.js
@@ -0,0 +1,34 @@
'use strict';

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

describe('--ui', function() {
var simpleUiPath = require.resolve('../fixtures/simple-ui.fixture');

it('should load interface and run it', function(done) {
runMocha('test-for-simple-ui', ['--ui', simpleUiPath], function(err, res) {
if (err) {
done(err);
return;
}
expect(res, 'to have passed');
done();
});
});

it("should work if required and name added to Mocha's `interfaces` prop", function(done) {
runMocha(
'test-for-simple-ui',
['--require', simpleUiPath, '--ui', 'simple-ui'],
function(err, res) {
if (err) {
done(err);
return;
}
expect(res, 'to have passed');
done();
}
);
});
});
20 changes: 0 additions & 20 deletions test/integration/regression.spec.js
@@ -1,6 +1,5 @@
'use strict';

var path = require('path');
var run = require('./helpers').runMocha;
var runJSON = require('./helpers').runMochaJSON;

Expand All @@ -25,25 +24,6 @@ describe('regressions', function() {
});
});

it("issue-1794: Can't --require custom UI and use it", function(done) {
var simpleUiPath = path.join(
__dirname,
'fixtures',
'regression',
'1794',
'simple-ui.fixture.js'
);
var args = ['--require', simpleUiPath, '--ui', 'simple-ui'];
run('regression/1794/issue-1794.fixture.js', args, function(err, res) {
if (err) {
done(err);
return;
}
expect(res, 'to have passed');
done();
});
});

it('issue-1991: Declarations do not get cleaned up unless you set them to `null` - Memory Leak', function(done) {
// on a modern MBP takes ±5 seconds on node 4.0, but on older laptops with node 0.12 ±40 seconds.
// Could easily take longer on even weaker machines (Travis-CI containers for example).
Expand Down

0 comments on commit 7926f47

Please sign in to comment.