From 9d5e3faa8f5563912ac7db7fcde94f7789b6b60b Mon Sep 17 00:00:00 2001 From: AlCalzone Date: Thu, 12 Dec 2024 14:54:31 +0100 Subject: [PATCH] refactor: move mock behaviors to improve tree shaking (#7487) --- packages/zwave-js/src/Testing.ts | 2 ++ packages/zwave-js/src/Utils.ts | 2 -- .../src/lib/controller/Controller.nodes.getOrThrow.test.ts | 2 +- packages/zwave-js/src/lib/node/Endpoint.test.ts | 2 +- packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts | 2 +- packages/zwave-js/src/lib/test/cc/API.test.ts | 2 +- .../src/lib/test/cc/CommandClass.persistValues.test.ts | 2 +- .../zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts | 2 +- .../src/lib/test/driver/computeNetCCPayloadSize.test.ts | 2 +- .../zwave-js/src/lib/test/driver/hasPendingMessages.test.ts | 2 +- packages/zwave-js/src/lib/test/integrationTestSuiteShared.ts | 2 +- packages/zwave-js/src/lib/test/node/Node.ccVersions.test.ts | 2 +- packages/zwave-js/src/lib/test/node/Node.constructor.test.ts | 2 +- .../zwave-js/src/lib/test/node/Node.createCCInstance.test.ts | 2 +- packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts | 2 +- packages/zwave-js/src/lib/test/node/Node.getSetValue.test.ts | 2 +- packages/zwave-js/src/lib/test/node/Node.status.test.ts | 2 +- .../zwave-js/src/lib/test/node/Node.updateNodeInfo.test.ts | 2 +- packages/zwave-js/src/lib/test/node/Node.valueEvents.test.ts | 2 +- .../zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts | 2 +- packages/zwave-js/src/mockServer.ts | 4 ++-- 21 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/zwave-js/src/Testing.ts b/packages/zwave-js/src/Testing.ts index cdbd8d65f23e..0e259be36f5e 100644 --- a/packages/zwave-js/src/Testing.ts +++ b/packages/zwave-js/src/Testing.ts @@ -1,4 +1,6 @@ +export { createDefaultBehaviors as createDefaultMockControllerBehaviors } from "./lib/controller/MockControllerBehaviors.js"; export { createAndStartDriverWithMockPort } from "./lib/driver/DriverMock.js"; +export { createDefaultBehaviors as createDefaultMockNodeBehaviors } from "./lib/node/MockNodeBehaviors.js"; export { MockServer, createMockNodeOptionsFromDump } from "./mockServer.js"; export type { MockServerControllerOptions, diff --git a/packages/zwave-js/src/Utils.ts b/packages/zwave-js/src/Utils.ts index 23803c2a7f16..6e252d7b7892 100644 --- a/packages/zwave-js/src/Utils.ts +++ b/packages/zwave-js/src/Utils.ts @@ -24,7 +24,6 @@ export { getEnumMemberName, num2hex, } from "@zwave-js/shared/safe"; -export { createDefaultBehaviors as createDefaultMockControllerBehaviors } from "./lib/controller/MockControllerBehaviors.js"; export { driverPresets } from "./lib/driver/ZWaveOptions.js"; export { formatLifelineHealthCheckRound, @@ -33,4 +32,3 @@ export { formatRouteHealthCheckSummary, healthCheckRatingToWord, } from "./lib/node/HealthCheck.js"; -export { createDefaultBehaviors as createDefaultMockNodeBehaviors } from "./lib/node/MockNodeBehaviors.js"; diff --git a/packages/zwave-js/src/lib/controller/Controller.nodes.getOrThrow.test.ts b/packages/zwave-js/src/lib/controller/Controller.nodes.getOrThrow.test.ts index e00599bce6de..f864722a1a68 100644 --- a/packages/zwave-js/src/lib/controller/Controller.nodes.getOrThrow.test.ts +++ b/packages/zwave-js/src/lib/controller/Controller.nodes.getOrThrow.test.ts @@ -2,7 +2,7 @@ import { ZWaveErrorCodes, assertZWaveError } from "@zwave-js/core"; import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../Testing.js"; import type { Driver } from "../driver/Driver.js"; import { createAndStartTestingDriver } from "../driver/DriverMock.js"; import { ZWaveNode } from "../node/Node.js"; diff --git a/packages/zwave-js/src/lib/node/Endpoint.test.ts b/packages/zwave-js/src/lib/node/Endpoint.test.ts index abb41b83391b..9cc87d04e791 100644 --- a/packages/zwave-js/src/lib/node/Endpoint.test.ts +++ b/packages/zwave-js/src/lib/node/Endpoint.test.ts @@ -8,7 +8,7 @@ import { } from "@zwave-js/core"; import { MockController } from "@zwave-js/testing"; import { afterEach, test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../Testing.js"; import type { Driver } from "../driver/Driver.js"; import { createAndStartTestingDriver } from "../driver/DriverMock.js"; import { Endpoint } from "./Endpoint.js"; diff --git a/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts b/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts index dc9c1fae957b..214b8526ee8b 100644 --- a/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts +++ b/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts @@ -25,7 +25,7 @@ import { test as baseTest } from "vitest"; import { createDefaultMockControllerBehaviors, createDefaultMockNodeBehaviors, -} from "../../Utils.js"; +} from "../../Testing.js"; import type { Driver } from "../driver/Driver.js"; import { createAndStartTestingDriver } from "../driver/DriverMock.js"; import { ZWaveNode } from "./Node.js"; diff --git a/packages/zwave-js/src/lib/test/cc/API.test.ts b/packages/zwave-js/src/lib/test/cc/API.test.ts index 7f8c5f4f1469..f1ec103ee63e 100644 --- a/packages/zwave-js/src/lib/test/cc/API.test.ts +++ b/packages/zwave-js/src/lib/test/cc/API.test.ts @@ -3,7 +3,7 @@ import { NOT_KNOWN } from "@zwave-js/core"; import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts index 7d480168bcf9..d723c8f59c22 100644 --- a/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts +++ b/packages/zwave-js/src/lib/test/cc/CommandClass.persistValues.test.ts @@ -6,7 +6,7 @@ import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import sinon from "sinon"; import { afterEach, beforeEach, test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts index 31a3db51005f..e0a895f4ae5b 100644 --- a/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts @@ -8,7 +8,7 @@ import { CommandClasses, ZWaveError, ZWaveErrorCodes } from "@zwave-js/core"; import { ApplicationCommandRequest } from "@zwave-js/serial/serialapi"; import { MockController, MockNode } from "@zwave-js/testing"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; diff --git a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts index 2ed04bc0ab50..3346a3c0eee1 100644 --- a/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts +++ b/packages/zwave-js/src/lib/test/driver/computeNetCCPayloadSize.test.ts @@ -5,7 +5,7 @@ import { EncapsulationFlags, TransmitOptions } from "@zwave-js/core"; import { SendDataRequest } from "@zwave-js/serial/serialapi"; import { MockController } from "@zwave-js/testing"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; diff --git a/packages/zwave-js/src/lib/test/driver/hasPendingMessages.test.ts b/packages/zwave-js/src/lib/test/driver/hasPendingMessages.test.ts index 0aabc8b5e00d..e69e52262c30 100644 --- a/packages/zwave-js/src/lib/test/driver/hasPendingMessages.test.ts +++ b/packages/zwave-js/src/lib/test/driver/hasPendingMessages.test.ts @@ -1,7 +1,7 @@ import { CommandClasses, type ValueID } from "@zwave-js/core"; import { MockController } from "@zwave-js/testing"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/integrationTestSuiteShared.ts b/packages/zwave-js/src/lib/test/integrationTestSuiteShared.ts index be056da04225..e9f679567a59 100644 --- a/packages/zwave-js/src/lib/test/integrationTestSuiteShared.ts +++ b/packages/zwave-js/src/lib/test/integrationTestSuiteShared.ts @@ -12,7 +12,7 @@ import { fileURLToPath } from "node:url"; import { createDefaultMockControllerBehaviors, createDefaultMockNodeBehaviors, -} from "../../Utils.js"; +} from "../../Testing.js"; import { type CreateAndStartDriverWithMockPortResult, createAndStartDriverWithMockPort, diff --git a/packages/zwave-js/src/lib/test/node/Node.ccVersions.test.ts b/packages/zwave-js/src/lib/test/node/Node.ccVersions.test.ts index 3de80e476d64..b342c4542e11 100644 --- a/packages/zwave-js/src/lib/test/node/Node.ccVersions.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.ccVersions.test.ts @@ -1,7 +1,7 @@ import { CommandClasses } from "@zwave-js/core"; import { MockController } from "@zwave-js/testing"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts b/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts index 107aba8e94ad..b93b84bf48ea 100644 --- a/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.constructor.test.ts @@ -4,7 +4,7 @@ import "@zwave-js/cc"; import { CommandClasses, ValueDB } from "@zwave-js/core"; import { MockController } from "@zwave-js/testing"; import { afterEach, test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { DeviceClass } from "../../node/DeviceClass.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.createCCInstance.test.ts b/packages/zwave-js/src/lib/test/node/Node.createCCInstance.test.ts index e9eacf4edcc9..a9d1812e43d5 100644 --- a/packages/zwave-js/src/lib/test/node/Node.createCCInstance.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.createCCInstance.test.ts @@ -7,7 +7,7 @@ import { import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts b/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts index c75006241c8c..34aa1bfb4493 100644 --- a/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.getEndpoint.test.ts @@ -6,7 +6,7 @@ import { import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import { afterEach, beforeEach, test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { DeviceClass } from "../../node/DeviceClass.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.getSetValue.test.ts b/packages/zwave-js/src/lib/test/node/Node.getSetValue.test.ts index 0bec8b59c777..6a5b80f298c7 100644 --- a/packages/zwave-js/src/lib/test/node/Node.getSetValue.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.getSetValue.test.ts @@ -5,7 +5,7 @@ import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import sinon from "sinon"; import { type TaskContext, test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.status.test.ts b/packages/zwave-js/src/lib/test/node/Node.status.test.ts index c2d29f3fe47d..d78f14be5dc8 100644 --- a/packages/zwave-js/src/lib/test/node/Node.status.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.status.test.ts @@ -2,7 +2,7 @@ import { NodeStatus } from "@zwave-js/core"; import { MockController } from "@zwave-js/testing"; import sinon from "sinon"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.updateNodeInfo.test.ts b/packages/zwave-js/src/lib/test/node/Node.updateNodeInfo.test.ts index f5d38df33d84..1e198a99992a 100644 --- a/packages/zwave-js/src/lib/test/node/Node.updateNodeInfo.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.updateNodeInfo.test.ts @@ -5,7 +5,7 @@ import { CommandClasses, InterviewStage, NodeStatus } from "@zwave-js/core"; import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import { afterEach, test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.valueEvents.test.ts b/packages/zwave-js/src/lib/test/node/Node.valueEvents.test.ts index 674855a34305..e46afd3c4167 100644 --- a/packages/zwave-js/src/lib/test/node/Node.valueEvents.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.valueEvents.test.ts @@ -3,7 +3,7 @@ import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import sinon from "sinon"; import { afterEach, beforeEach, test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts b/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts index ae8ba10ee0f9..530870daa38d 100644 --- a/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts @@ -7,7 +7,7 @@ import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; import { wait } from "alcalzone-shared/async"; import { test as baseTest } from "vitest"; -import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; +import { createDefaultMockControllerBehaviors } from "../../../Testing.js"; import type { Driver } from "../../driver/Driver.js"; import { createAndStartTestingDriver } from "../../driver/DriverMock.js"; import { ZWaveNode } from "../../node/Node.js"; diff --git a/packages/zwave-js/src/mockServer.ts b/packages/zwave-js/src/mockServer.ts index 09e5e3594530..0d410985efe2 100644 --- a/packages/zwave-js/src/mockServer.ts +++ b/packages/zwave-js/src/mockServer.ts @@ -48,10 +48,10 @@ import { import { createDeferredPromise } from "alcalzone-shared/deferred-promise"; import { type AddressInfo, type Server, createServer } from "node:net"; import { - ProtocolVersion, createDefaultMockControllerBehaviors, createDefaultMockNodeBehaviors, -} from "./Utils.js"; +} from "./Testing.js"; +import { ProtocolVersion } from "./Utils.js"; import { type CommandClassDump, type NodeDump } from "./lib/node/Dump.js"; export type MockServerControllerOptions =