Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix --ui issues, closes #3746 #3756

Merged
merged 1 commit into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions lib/mocha.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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