Punkt 2 implementieren GitHub CoPilot

This commit is contained in:
chk
2026-06-08 17:28:43 +02:00
parent 172606c7a3
commit 0109066946
14 changed files with 1239 additions and 518 deletions

View File

@@ -1,76 +1,72 @@
var Sender = require('../robot/WSSenderGrbl.js')
describe("WS-SenderGRBL.execCommand", () => {
test("writes correct G-code to mocked WS tSocket", () => {
// Create instance (will try real connection, but we override tSocket immediately)
const sender = new Sender(urlGRBL = "test.test", maxSpeedF = 2300, xAxisGrbl = "x", yAxisGrbl = "y", zAxisGrbl = "z");
// Mock tSocket.write
sender.tSocket = {
written: "",
write: function(txt) {
this.written = txt; // store what was written
}
};
// Provide some sample motion data
const mOld = { x: 0, y: 0, z: 0, a:0, b:0, c:0, e:0 }; // not used in your code
const mNew = { x: 12.34, y: 1.0, z: 2.0, a:0, b:0, c:0, e:0 };
sender.execCommand("G1", mOld, mNew);
// ✅ verify output
expect(sender.tSocket.written).toBe("G90 G1 x12.34 y57.30 z57.30 f2300.00\r\n");
});
test("writes correct G-code to mocked tSocket Ellbow", () => {
// Create instance (will try real connection, but we override tSocket immediately)
const sender = new Sender(urlGRBL = "test.test", maxSpeedF = 2300, xAxisGrbl = "a", yAxisGrbl = null, zAxisGrbl = null );
// Mock tSocket.write
sender.tSocket = {
written: "",
write: function(txt) {
this.written = txt; // store what was written
}
};
// Provide some sample motion data
const mOld = { x: 0, y: 0, z: 0, a:Math.PI, b:0, c:0, e:0 }; // not used in your code
const mNew = { x: 12.34, y: Math.PI/2, z: 0, a:Math.PI/8, b:0, c:0, e:0 };
sender.execCommand("G1", mOld, mNew);
// ✅ verify output
expect(sender.tSocket.written).toBe("G90 G1 x22.50 f2300.00\r\n");
});
test("writes correct G-code G92 to mocked WS tSocket", () => {
// Create instance (will try real connection, but we override tSocket immediately)
const sender = new Sender(urlGRBL = "test.test", maxSpeedF = 2300, xAxisGrbl = "x", yAxisGrbl = "y", zAxisGrbl = "z");
// Mock tSocket.write
sender.tSocket = {
written: "",
write: function(txt) {
this.written = txt; // store what was written
}
};
// Provide some sample motion data
const mOld = { x: 0, y: 0, z: 0, a:0, b:0, c:0, e:0 }; // not used in your code
const mNew = { x: 12.34, y: 1.0, z: 2.0, a:0, b:0, c:0, e:0 };
sender.execCommand("G92", mOld, mNew);
// ✅ verify output
expect(sender.tSocket.written.replace("G90 ","")).toBe("G92 x12.34 y57.30 z57.30 f2300.00\r\n");
});
});
const WSSenderGrbl = require('../robot/WSSenderGrbl.js');
describe("WSSenderGrbl implements SenderInterface", () => {
test("is an instance of SenderInterface and exposes required methods", () => {
const SenderInterface = require('../robot/SenderInterface');
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
expect(sender).toBeInstanceOf(SenderInterface);
expect(typeof sender.connect).toBe('function');
expect(typeof sender.send).toBe('function');
expect(typeof sender.getStatus).toBe('function');
expect(typeof sender.disconnect).toBe('function');
});
test("test mode has connected status", () => {
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
expect(sender.getStatus()).toMatchObject({ state: 'connected', isTestMode: true });
});
test("send() returns false when not connected, true in test mode", () => {
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
expect(sender.send("G1 x1")).toBe(true);
sender.ws = null;
expect(sender.send("G1 x1")).toBe(false);
});
test("disconnect() transitions to disconnected state", () => {
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
sender.disconnect();
expect(sender.getStatus()).toMatchObject({ state: 'disconnected' });
});
});
describe("WSSenderGrbl.execCommand writes correct G-code via send()", () => {
test("writes correct G-code for xyz axes", () => {
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
const mOld = { x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0 };
const mNew = { x: 12.34, y: 1.0, z: 2.0, a: 0, b: 0, c: 0, e: 0 };
sender.execCommand("G1", mOld, mNew);
expect(sender.ws.written).toBe("G90 G1 x12.34 y57.30 z57.30 f2300.00\n");
});
test("writes correct G-code for elbow (a axis)", () => {
const sender = new WSSenderGrbl("test.test", 2300, "a", null, null);
const mOld = { x: 0, y: 0, z: 0, a: Math.PI, b: 0, c: 0, e: 0 };
const mNew = { x: 12.34, y: Math.PI / 2, z: 0, a: Math.PI / 8, b: 0, c: 0, e: 0 };
sender.execCommand("G1", mOld, mNew);
expect(sender.ws.written).toBe("G90 G1 x22.50 f2300.00\n");
});
test("G92 command is sent without extra G90 prefix", () => {
const sender = new WSSenderGrbl("test.test", 2300, "x", "y", "z");
const mOld = { x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0 };
const mNew = { x: 12.34, y: 1.0, z: 2.0, a: 0, b: 0, c: 0, e: 0 };
sender.execCommand("G92", mOld, mNew);
expect(sender.ws.written.replace("G90 ", "")).toBe("G92 x12.34 y57.30 z57.30 f2300.00\n");
});
});