Skip to content

Commit

Permalink
fix: mock-server would not start due to ESM/CJS confusion (#7401)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Nov 14, 2024
1 parent a89bcf7 commit b7b2a82
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// @ts-check
const { MockServer, createMockNodeOptionsFromDump } = require(
"../build/mockServer",
"../build/cjs/mockServer.js",
);
const { readFileSync, statSync, readdirSync } = require("fs");
const path = require("path");
Expand Down Expand Up @@ -85,7 +85,7 @@ Each node ID may only be used once in mock configs. Node ID ${nodeConfig.id} is
* @param {string} filename
*/
function getConfig(filename) {
if (filename.endsWith(".js")) {
if (filename.endsWith(".js") || filename.endsWith(".cjs")) {
// The export can either be a static config object or a function that accepts a require
let config = require(filename).default;
if (typeof config === "function") {
Expand Down Expand Up @@ -156,7 +156,7 @@ No config files found in ${absolutePath}
const interfaceIndex = args.findIndex(
(arg) => arg === "--interface" || arg === "-i",
);
const interface = interfaceIndex === -1 ? undefined : args[interfaceIndex + 1];
const iface = interfaceIndex === -1 ? undefined : args[interfaceIndex + 1];

// Parse port
const portIndex = args.findIndex((arg) => arg === "--port" || arg === "-p");
Expand All @@ -166,7 +166,7 @@ if (Number.isNaN(port)) port = undefined;
let server;
(async () => {
server = new MockServer({
interface,
interface: iface,
port,
config,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/zwave-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"build/**/package.json"
],
"bin": {
"mock-server": "bin/mock-server.js"
"mock-server": "bin/mock-server.cjs"
},
"author": {
"name": "AlCalzone",
Expand Down
58 changes: 58 additions & 0 deletions server_config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// @ts-check
const { CommandClasses, ConfigValueFormat, SupervisionStatus } = require(
"@zwave-js/core",
);
const { ccCaps, MockZWaveFrameType, createMockZWaveRequestFrame } = require(
"@zwave-js/testing",
);
const { wait } = require("alcalzone-shared/async");
const {
SupervisionCCGet,
SupervisionCCReport,
ConfigurationCCSet,
SwitchType,
} = require(
"zwave-js",
);

/** @type {import("zwave-js/Testing").MockServerOptions["config"]} */
module.exports.default = {
nodes: [
{
id: 2,
capabilities: {
commandClasses: [
CommandClasses.Version,
// CommandClasses.Supervision,
ccCaps({
ccId: CommandClasses["Multilevel Switch"],
isSupported: true,
version: 4,
defaultValue: 0,
primarySwitchType: SwitchType["Down/Up"],
}),
],
},
// behaviors: [
// {
// async handleCC(controller, self, receivedCC) {
// if (
// receivedCC instanceof SupervisionCCGet
// && receivedCC.encapsulated
// instanceof ConfigurationCCSet
// ) {
// const cc = new SupervisionCCReport({
// nodeId: controller.ownNodeId,
// sessionId: receivedCC.sessionId,
// moreUpdatesFollow: false,
// status: SupervisionStatus.Fail,
// });

// return { action: "sendCC", cc };
// }
// },
// },
// ],
},
],
};
72 changes: 0 additions & 72 deletions server_config.js

This file was deleted.

2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10109,6 +10109,6 @@ __metadata:
winston: "npm:^3.15.0"
xstate: "npm:4.38.3"
bin:
mock-server: bin/mock-server.js
mock-server: bin/mock-server.cjs
languageName: unknown
linkType: soft

0 comments on commit b7b2a82

Please sign in to comment.