Specification
I want to refactor the conditional test utilities to use boolean conditional parameter again, but instead reify the conditions into things like isWindows, isLinux... etc, then you can combine them up easily with isWindows || isLinux... etc. String parameters are not obvious.
Furthermore, it's apparent now that we have situations where a test should run normally, and also under a particular platform, but no other platforms are allowed. And there are tests that we want to run only for a given platform. This behaviour should be standardised.
A standard set of functions should be used:
The condition should be testIf(boolean, ...args) where ...args is sent to test. This makes it easily extendable.
An alternative is testIf(() => bool, ...args) where it's a function. A unary function by itself is sort of useless, but it can be useful if we do testIf((meta: Metadata) => bool, ...args), where metadata is actually passed into the predicate which is derived from the usage of the test. However I cannot think of any metadata right now that would be useful. Maybe the test name, test location, __dirname... etc.
A predicate can also be asynchronous, which allows it to do runtime side-effects (mostly queries).
However @tegefaulkes says it's annoying to have to write os.platform() === 'linux' all the time, so to avoid this, we can "reify" the booleans. This is more obvious and is better for performance as it eliminates a bunch of checks. Basically we can have isPlatformLinux and hasNsenter... etc. This is already used in js-logger under hasCaptureStackTrace and hasStackTraceLimit. See: https://dev.to/michi/tips-on-naming-boolean-variables-cleaner-code-35ig and https://www.serendipidata.com/posts/naming-guidelines-for-boolean-variables.
Finally this means that through anyone's interpretation:
testIf(isPlatformLinux, ...)
Should only run if the platform is Linux.
Therefore if we want to run without a platform requirement, then:
testIf(isPlatformEmpty || isPlatformLinux, ...args)
Which means that you can run under any platform and under platform linux.
Finally for and conditions:
testIf(hasNsenter && isPlatformLinux, ...args)
Which allows us to wire up conditions.
All of this is lot easier to understand, and isn't that much more to write than what is done already.
Additional context
Tasks
Specification
I want to refactor the conditional test utilities to use boolean conditional parameter again, but instead reify the conditions into things like
isWindows,isLinux... etc, then you can combine them up easily withisWindows || isLinux... etc. String parameters are not obvious.Furthermore, it's apparent now that we have situations where a test should run normally, and also under a particular platform, but no other platforms are allowed. And there are tests that we want to run only for a given platform. This behaviour should be standardised.
A standard set of functions should be used:
The condition should be
testIf(boolean, ...args)where...argsis sent totest. This makes it easily extendable.An alternative is
testIf(() => bool, ...args)where it's a function. A unary function by itself is sort of useless, but it can be useful if we dotestIf((meta: Metadata) => bool, ...args), where metadata is actually passed into the predicate which is derived from the usage of the test. However I cannot think of any metadata right now that would be useful. Maybe the test name, test location,__dirname... etc.A predicate can also be asynchronous, which allows it to do runtime side-effects (mostly queries).
However @tegefaulkes says it's annoying to have to write
os.platform() === 'linux'all the time, so to avoid this, we can "reify" the booleans. This is more obvious and is better for performance as it eliminates a bunch of checks. Basically we can haveisPlatformLinuxandhasNsenter... etc. This is already used injs-loggerunderhasCaptureStackTraceandhasStackTraceLimit. See: https://dev.to/michi/tips-on-naming-boolean-variables-cleaner-code-35ig and https://www.serendipidata.com/posts/naming-guidelines-for-boolean-variables.Finally this means that through anyone's interpretation:
Should only run if the platform is Linux.
Therefore if we want to run without a platform requirement, then:
Which means that you can run under any platform and under platform linux.
Finally for and conditions:
Which allows us to wire up conditions.
All of this is lot easier to understand, and isn't that much more to write than what is done already.
Additional context
Tasks
tests/utils.tstotests/utils/utils.tsand addtests/utils/index.ts.runTestIfto usetestIfwith reifyed booleans.runTestIfPlatformandrunDescribeIfPlatform, replace with reifyed booleans andtestIf