Add unit tests

This commit is contained in:
Nick O'Leary
2025-04-24 15:26:29 +01:00
parent 7d4d604aa2
commit 0f3d25252b
6 changed files with 158 additions and 7 deletions

View File

@@ -106,16 +106,16 @@ function isTelemetryEnabled () {
return undefined
}
// If there are telemetry settings, use what it says
if (telemetrySettings && telemetrySettings.enabled !== undefined) {
return telemetrySettings.enabled
}
// User has made a choice; defer to that
if (runtimeTelemetryEnabled !== undefined) {
return runtimeTelemetryEnabled
}
// If there are telemetry settings, use what it says
if (telemetrySettings && telemetrySettings.enabled !== undefined) {
return telemetrySettings.enabled
}
// At this point, we have no sign the user has consented to telemetry, so
// keep disabled - but return undefined as a false-like value to distinguish
// it from the explicit disable above
@@ -157,6 +157,7 @@ function stopTelemetry () {
module.exports = {
init: (_runtime) => {
runtime = _runtime
if (isTelemetryEnabled()) {
startTelemetry()
}
@@ -185,5 +186,12 @@ module.exports = {
* Get telemetry enabled status
* @returns {boolean} true if telemetry is enabled, false if disabled, undefined if not set
*/
isEnabled: isTelemetryEnabled
isEnabled: isTelemetryEnabled,
stop: () => {
if (scheduleTask) {
scheduleTask.stop()
scheduleTask = null
}
}
}

View File

@@ -1,6 +1,6 @@
const process = require('process')
module.exports = async (runtime) => {
module.exports = (runtime) => {
return {
'env.nodejs': process.version.replace(/^v/, ''),
'env.node-red': runtime.settings.version