Test vom GCode

This commit is contained in:
ChK
2026-04-08 08:35:42 +02:00
parent ff7cde40ac
commit 249f7447bb
6 changed files with 202 additions and 2 deletions

93
test/GCode.speed.test.js Normal file
View File

@@ -0,0 +1,93 @@
const GCode = require('../robot/GCode.js');
const Robot = require('../robot/Robot.js');
const TelnetSender = require('../robot/TelnetSenderGRBL.js');
describe('GCode Speed Tests', () => {
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => {});
});
afterAll(() => {
jest.restoreAllMocks();
});
test('G1 with Feedrate F300 - TelnetSender1 should include f300', () => {
const L1 = 300;
const L2 = 300;
const L3 = 20;
const robot = new Robot(L1, L2, L3);
const telnetSender1 = new TelnetSender("test.test", 2300, "x", "y", "z");
const telnetSender2 = new TelnetSender("test.test", 5000, "a", null, null);
const telnetSender3 = new TelnetSender("test.test", 5000, "c", "e", "b");
robot.cmdReceivers.push(telnetSender1);
robot.cmdReceivers.push(telnetSender2);
robot.cmdReceivers.push(telnetSender3);
// G1 with F300
GCode.receiveGCode(robot, "G1 x120 y100 z50 f300");
// Check telnetSender1 (x,y,z axes)
expect(telnetSender1.tSocket.written).toContain('G1');
expect(telnetSender1.tSocket.written).toContain('f300');
expect(telnetSender1.tSocket.written).toMatch(/f300\.00/); // Exact format
// telnetSender2 and telnetSender3 might not have output if no changes
// But since x,y,z changed, telnetSender1 should have the command
});
test('G1 without Feedrate - should use default f200', () => {
const L1 = 300;
const L2 = 300;
const L3 = 20;
const robot = new Robot(L1, L2, L3);
const telnetSender1 = new TelnetSender("test.test", 2300, "x", "y", "z");
robot.cmdReceivers.push(telnetSender1);
// G1 without F
GCode.receiveGCode(robot, "G1 x120 y100 z50");
// Check default feedrate
expect(telnetSender1.tSocket.written).toContain('G1');
expect(telnetSender1.tSocket.written).toContain('f200');
expect(telnetSender1.tSocket.written).toMatch(/f200\.00/);
});
test('G1 with different Feedrate F500 - multiple senders', () => {
const L1 = 300;
const L2 = 300;
const L3 = 20;
const robot = new Robot(L1, L2, L3);
const telnetSender1 = new TelnetSender("test.test", 2300, "x", "y", "z");
const telnetSender2 = new TelnetSender("test.test", 5000, "a", null, null);
const telnetSender3 = new TelnetSender("test.test", 5000, "c", "e", "b");
robot.cmdReceivers.push(telnetSender1);
robot.cmdReceivers.push(telnetSender2);
robot.cmdReceivers.push(telnetSender3);
// G1 with F500
GCode.receiveGCode(robot, "G1 x120 y100 z50 a10 b20 c30 f500");
// telnetSender1 should have f500
expect(telnetSender1.tSocket.written).toContain('f500');
expect(telnetSender1.tSocket.written).toMatch(/f500\.00/);
// telnetSender2 (a axis) should have f500 if a changed
if (telnetSender2.tSocket.written.length > 0) {
expect(telnetSender2.tSocket.written).toContain('f500');
}
// telnetSender3 (c,e,b axes) should have f500 if changed
if (telnetSender3.tSocket.written.length > 0) {
expect(telnetSender3.tSocket.written).toContain('f500');
}
});
});