Interface Exposure and Unit Testing?

  node.js, question

https://github.com/DophinL/baidu-ocr-idcard/blob/master/lib/baidu-ocr- …
Previously, unit testing was only for exposed interfaces.IDCardOCR.prototype.scan.
But when I looked at the code just now, I found a functionextractValidPeriodNeed to change, and then I changed it and then conducted manual tests, so I wonder if I can include this in the unit tests.
However, this function function is not needed by the user. Is there any problem when it is exposed?
If it is not exposed, how can the unit test of this function be carried out?

I have some ideas, for example, the create function is exposed, and the method to be tested can be directly added to create function object.create.extractValidPeriod = .... But it doesn’t feel very elegant.

Is there a better way to solve this problem?
By the way, what will the unit tests measure?

Your question is divided into three parts.

Should private code be tested?

This is my opinion: it should be tested. Private methods can be very complicated. It should be covered separately.

Does public testing Code Affect Packaging?

It must be affected, because you must disclose this method before testing is possible.

However, these methods can only be disclosed in the TEST phase by setting environment variables or something. such as

module.exports.public_method1 = your_public_method1
 if (process.env["in_testing"]){
 module.exports.testing_method1 = your_test_method1
 module.exports.testing_method2 = your_test_method2
 bracket

These methods will only be disclosed if the environment variable is set. In this way, people who love encapsulation will feel better.