Skip to content

🛠️ Repo: Refactor to fix encapsulation issues #3689

Open

Description

There are many places throughout the codebase (mostly in the main classes) where we modify data via assignment in some object (e.g., a Suite) directly from some other class. this includes properties which are ostensibly "private" (e.g. Suite#_onlyTests).

This breaks encapsulation/information-hiding. Refactor these instances by creating methods within the classes having these properties, and call those methods from whatever code is currently doing direct assignment.

Example:

test: {
/**
* Exclusive test-case.
*
* @param {Object} mocha
* @param {Function} test
* @returns {*}
*/
only: function(mocha, test) {
test.parent._onlyTests = test.parent._onlyTests.concat(test);
return test;
},

Instead, Suite could expose an instance method (e.g., appendOnlyTest) which appends the test to its _onlyTests array. The consuming code would call test.parent.appendOnlyTest(test). Going a step further, the Test class could expose an instance method (e.g. markOnly()) which would make the call.

These changes can be incremental; we don't have to do it all at once. Any new methods will need unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions