Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jul 15, 2021
1 parent 9b42b23 commit 5ff9650
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions test/node-unit/cli/run-helpers.spec.js
@@ -1,6 +1,7 @@
'use strict';

const {validateLegacyPlugin, list} = require('../../../lib/cli/run-helpers');
const Mocha = require('../../../lib/mocha');

describe('helpers', function() {
describe('validateLegacyPlugin()', function() {
Expand All @@ -25,24 +26,19 @@ describe('helpers', function() {
});
});

describe('when used with an "interfaces" key', function() {
describe('when used with an "ui" key', function() {
it('should disallow an array of names', function() {
expect(
() => validateLegacyPlugin({interface: ['bar']}, 'interface'),
'to throw',
{
code: 'ERR_MOCHA_INVALID_INTERFACE',
message: /can only be specified once/i
}
);
expect(() => validateLegacyPlugin({ui: ['bar']}, 'ui'), 'to throw', {
code: 'ERR_MOCHA_INVALID_INTERFACE',
message: /can only be specified once/i
});
});

it('should fail to recognize an unknown interface', function() {
expect(
() => validateLegacyPlugin({interface: 'bar'}, 'interface'),
'to throw',
{code: 'ERR_MOCHA_INVALID_INTERFACE', message: /cannot find module/i}
);
expect(() => validateLegacyPlugin({ui: 'bar'}, 'ui'), 'to throw', {
code: 'ERR_MOCHA_INVALID_INTERFACE',
message: /cannot find module/i
});
});
});

Expand All @@ -56,6 +52,17 @@ describe('helpers', function() {
});
});

describe('when used with a third-party interface', function() {
it('should add the interface to "Mocha.interfaces"', function() {
// let's suppose that `glob` is an interface
const opts = {ui: 'glob'};
validateLegacyPlugin(opts, 'ui', Mocha.interfaces);
expect(opts.ui, 'to equal', 'glob');
expect(Mocha.interfaces, 'to satisfy', {glob: require('glob')});
delete Mocha.interfaces.glob;
});
});

describe('when a plugin throws an exception upon load', function() {
it('should fail and report the original error', function() {
expect(
Expand Down

0 comments on commit 5ff9650

Please sign in to comment.