@thi.ng/axidraw 1.1.39 → 1.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/serial.js CHANGED
@@ -1,42 +1,36 @@
1
1
  import { illegalState } from "@thi.ng/errors/illegal-state";
2
2
  import { SerialPort } from "serialport";
3
- /**
4
- * Default connection using the actual serial port.
5
- */
6
- export const SERIAL_PORT = {
7
- list: () => SerialPort.list(),
8
- ctor: (path, baudRate) => new SerialPort({ path, baudRate }),
3
+ const SERIAL_PORT = {
4
+ list: () => SerialPort.list(),
5
+ ctor: (path, baudRate) => new SerialPort({ path, baudRate })
9
6
  };
10
- /**
11
- * Mock serial connection which uses a in-memory logger to record all draw
12
- * commands. Only intended for testing/dev purposes.
13
- */
14
- export const MOCK_SERIAL = {
15
- list: async (path) => [{ path }],
16
- ctor: () => new MockSerial(),
7
+ const MOCK_SERIAL = {
8
+ list: async (path) => [{ path }],
9
+ ctor: () => new MockSerial()
17
10
  };
18
- /**
19
- * Minimal mock "serial port" implementation for testing purposes. Records all
20
- * sent messages into an internal string array for later analysis.
21
- */
22
- export class MockSerial {
23
- sent = [];
24
- isClosed = false;
25
- /**
26
- * Clears internal log of "sent" message.
27
- */
28
- clear() {
29
- this.sent = [];
30
- }
31
- close() {
32
- this.isClosed = true;
33
- }
34
- /**
35
- * Appends
36
- * @param msg
37
- */
38
- write(msg) {
39
- this.isClosed && illegalState("connection already closed");
40
- this.sent.push(msg);
41
- }
11
+ class MockSerial {
12
+ sent = [];
13
+ isClosed = false;
14
+ /**
15
+ * Clears internal log of "sent" message.
16
+ */
17
+ clear() {
18
+ this.sent = [];
19
+ }
20
+ close() {
21
+ this.isClosed = true;
22
+ }
23
+ /**
24
+ * Appends
25
+ * @param msg
26
+ */
27
+ write(msg) {
28
+ this.isClosed && illegalState("connection already closed");
29
+ this.sent.push(msg);
30
+ }
42
31
  }
32
+ export {
33
+ MOCK_SERIAL,
34
+ MockSerial,
35
+ SERIAL_PORT
36
+ };