Skip to content

Commit

Permalink
fix(integration): revert deprecation of 'EVENT_SUITE_ADD_*' events (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor authored Oct 3, 2021
1 parent 0ea732c commit 111467f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 54 deletions.
59 changes: 15 additions & 44 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var {
assignNewMochaID,
clamp,
constants: utilsConstants,
createMap,
defineConstants,
getMochaID,
inherits,
Expand Down Expand Up @@ -92,16 +91,6 @@ function Suite(title, parentContext, isRoot) {
});

this.reset();

this.on('newListener', function(event) {
if (deprecatedEvents[event]) {
errors.deprecate(
'Event "' +
event +
'" is deprecated. Please let the Mocha team know about your use case: https://git.io/v6Lwm'
);
}
});
}

/**
Expand Down Expand Up @@ -614,7 +603,7 @@ var constants = defineConstants(
*/
{
/**
* Event emitted after a test file has been loaded Not emitted in browser.
* Event emitted after a test file has been loaded. Not emitted in browser.
*/
EVENT_FILE_POST_REQUIRE: 'post-require',
/**
Expand All @@ -626,70 +615,52 @@ var constants = defineConstants(
*/
EVENT_FILE_REQUIRE: 'require',
/**
* Event emitted when `global.run()` is called (use with `delay` option)
* Event emitted when `global.run()` is called (use with `delay` option).
*/
EVENT_ROOT_SUITE_RUN: 'run',

/**
* Namespace for collection of a `Suite`'s "after all" hooks
* Namespace for collection of a `Suite`'s "after all" hooks.
*/
HOOK_TYPE_AFTER_ALL: 'afterAll',
/**
* Namespace for collection of a `Suite`'s "after each" hooks
* Namespace for collection of a `Suite`'s "after each" hooks.
*/
HOOK_TYPE_AFTER_EACH: 'afterEach',
/**
* Namespace for collection of a `Suite`'s "before all" hooks
* Namespace for collection of a `Suite`'s "before all" hooks.
*/
HOOK_TYPE_BEFORE_ALL: 'beforeAll',
/**
* Namespace for collection of a `Suite`'s "before all" hooks
* Namespace for collection of a `Suite`'s "before each" hooks.
*/
HOOK_TYPE_BEFORE_EACH: 'beforeEach',

// the following events are all deprecated

/**
* Emitted after an "after all" `Hook` has been added to a `Suite`. Deprecated
* Emitted after a child `Suite` has been added to a `Suite`.
*/
EVENT_SUITE_ADD_SUITE: 'suite',
/**
* Emitted after an "after all" `Hook` has been added to a `Suite`.
*/
EVENT_SUITE_ADD_HOOK_AFTER_ALL: 'afterAll',
/**
* Emitted after an "after each" `Hook` has been added to a `Suite` Deprecated
* Emitted after an "after each" `Hook` has been added to a `Suite`.
*/
EVENT_SUITE_ADD_HOOK_AFTER_EACH: 'afterEach',
/**
* Emitted after an "before all" `Hook` has been added to a `Suite` Deprecated
* Emitted after an "before all" `Hook` has been added to a `Suite`.
*/
EVENT_SUITE_ADD_HOOK_BEFORE_ALL: 'beforeAll',
/**
* Emitted after an "before each" `Hook` has been added to a `Suite` Deprecated
* Emitted after an "before each" `Hook` has been added to a `Suite`.
*/
EVENT_SUITE_ADD_HOOK_BEFORE_EACH: 'beforeEach',
/**
* Emitted after a child `Suite` has been added to a `Suite`. Deprecated
*/
EVENT_SUITE_ADD_SUITE: 'suite',
/**
* Emitted after a `Test` has been added to a `Suite`. Deprecated
* Emitted after a `Test` has been added to a `Suite`.
*/
EVENT_SUITE_ADD_TEST: 'test'
}
);

/**
* @summary There are no known use cases for these events.
* @desc This is a `Set`-like object having all keys being the constant's string value and the value being `true`.
* @todo Remove eventually
* @type {Object<string,boolean>}
* @ignore
*/
var deprecatedEvents = Object.keys(constants)
.filter(function(constant) {
return constant.substring(0, 15) === 'EVENT_SUITE_ADD';
})
.reduce(function(acc, constant) {
acc[constants[constant]] = true;
return acc;
}, createMap());

Suite.constants = constants;
10 changes: 0 additions & 10 deletions test/unit/suite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,16 +548,6 @@ describe('Suite', function() {
new Suite('Bdd suite', 'root');
}, 'not to throw');
});

it('should report listened-for deprecated events as deprecated', function() {
new Suite('foo').on(
Suite.constants.EVENT_SUITE_ADD_TEST,
function() {}
);
expect(errors.deprecate, 'to have a call satisfying', [
/Event "[^"]+" is deprecated/i
]);
});
});

describe('timeout()', function() {
Expand Down

0 comments on commit 111467f

Please sign in to comment.