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

Revert deprecation of 'EVENT_SUITE_ADD_*' events #4764

Merged
merged 2 commits into from Oct 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 15 additions & 44 deletions lib/suite.js
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
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