@risleylima/escpos 0.0.13 → 0.1.0

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.
@@ -0,0 +1,98 @@
1
+ # Test Coverage Analysis
2
+
3
+ ## Current Coverage Status
4
+
5
+ - **Statements**: 100% ✅
6
+ - **Branches**: 100% ✅ (was 88.09%, improved to 100%)
7
+ - **Functions**: 100% ✅
8
+ - **Lines**: 100% ✅
9
+
10
+ **Status**: ✅ **100% Coverage Achieved!**
11
+
12
+ ## Uncovered Branches
13
+
14
+ ### 1. `commands.js` - `numToHexString` function (Line 12)
15
+
16
+ ```javascript
17
+ if (!isNaN(num)) {
18
+ // This branch is covered
19
+ }
20
+ // Missing: else branch when isNaN(num) === true
21
+ ```
22
+
23
+ **Issue**: The function doesn't test the case when `Number(value)` results in `NaN`.
24
+
25
+ **Current Test**: None - this function is only tested indirectly through other functions.
26
+
27
+ **Fix Needed**: Test with invalid input (e.g., `numToHexString('invalid')` or `numToHexString(NaN)`).
28
+
29
+ ### 2. `commands.js` - `TXT_CUSTOM_SIZE` function (Lines 77-80)
30
+
31
+ ```javascript
32
+ width = width > 8 ? 8 : width; // Branch: width > 8 not tested
33
+ width = width < 1 ? 1 : width; // Branch: width < 1 not tested
34
+ height = height > 8 ? 8 : height; // Branch: height > 8 not tested
35
+ height = height < 1 ? 1 : height; // Branch: height < 1 not tested
36
+ ```
37
+
38
+ **Issue**: The `size()` method is only tested with normal values (2, 2), not edge cases.
39
+
40
+ **Current Test**:
41
+ ```javascript
42
+ it('should set text size', () => {
43
+ printer.size(2, 2);
44
+ // Only tests normal case
45
+ });
46
+ ```
47
+
48
+ **Missing Tests**:
49
+ - `printer.size(10, 2)` - width > 8 (should clamp to 8)
50
+ - `printer.size(0, 2)` - width < 1 (should clamp to 1)
51
+ - `printer.size(2, 10)` - height > 8 (should clamp to 8)
52
+ - `printer.size(2, 0)` - height < 1 (should clamp to 1)
53
+ - `printer.size(10, 10)` - both > 8
54
+ - `printer.size(0, 0)` - both < 1
55
+
56
+ ## Impact
57
+
58
+ The uncovered branches are **edge case validations** that:
59
+ - Clamp values to valid ranges (1-8 for width/height)
60
+ - Handle invalid input gracefully
61
+
62
+ While these branches are defensive code, they should be tested to ensure:
63
+ 1. The clamping logic works correctly
64
+ 2. Invalid inputs don't cause errors
65
+ 3. The behavior is documented through tests
66
+
67
+ ## ✅ Resolution
68
+
69
+ Tests have been added for all uncovered branches:
70
+
71
+ 1. **`numToHexString` tests** (`tests/unit/printer/commands.test.js`):
72
+ - ✅ NaN input handling
73
+ - ✅ Invalid input handling
74
+ - ✅ Edge cases (zero, large numbers, odd-length hex)
75
+
76
+ 2. **`TXT_CUSTOM_SIZE` tests** (`tests/unit/printer/commands.test.js`):
77
+ - ✅ Width clamping (> 8, < 1)
78
+ - ✅ Height clamping (> 8, < 1)
79
+ - ✅ Both parameters out of range
80
+ - ✅ Boundary values (1 and 8)
81
+ - ✅ Valid range values
82
+
83
+ 3. **`size()` method tests** (`tests/unit/printer/printer.test.js`):
84
+ - ✅ Width > 8 clamping
85
+ - ✅ Width < 1 clamping
86
+ - ✅ Height > 8 clamping
87
+ - ✅ Height < 1 clamping
88
+ - ✅ Both out of range
89
+
90
+ ## Results
91
+
92
+ - **Before**: 88.09% branch coverage (50% in commands.js)
93
+ - **After**: 100% branch coverage ✅
94
+ - **New Tests Added**: 19 tests
95
+ - **Total Tests**: 145 (was 126)
96
+
97
+ All edge cases are now properly tested and documented!
98
+
@@ -0,0 +1,127 @@
1
+ # Dependencies Review
2
+
3
+ ## Current Dependencies Status
4
+
5
+ ### Production Dependencies
6
+
7
+ | Package | Current | Latest | Status | Notes |
8
+ |---------|---------|--------|--------|-------|
9
+ | `debug` | `^4.4.3` | `4.4.3` | ✅ Up to date | Updated from 4.3.1 |
10
+ | `get-pixels` | `https://github.com/risleylima/get-pixels` | N/A | ✅ Custom | Custom fork, version not tracked |
11
+ | `iconv-lite` | `^0.7.0` | `0.7.0` | ✅ Up to date | Updated from 0.6.3 |
12
+ | `serialport` | `^13.0.0` | `13.0.0` | ✅ Up to date | Updated from 12.0.0 |
13
+ | `usb` | `^2.16.0` | `2.16.0` | ✅ Up to date | Updated from 1.9.1 |
14
+
15
+ ### Development Dependencies
16
+
17
+ | Package | Current | Latest | Status | Notes |
18
+ |---------|---------|--------|--------|-------|
19
+ | `jest` | `^30.2.0` | `30.2.0` | ✅ Up to date | Updated from 29.7.0 |
20
+
21
+ ## Detailed Analysis
22
+
23
+ ### 1. `debug` (4.3.1 → 4.4.3)
24
+ - **Type**: Minor update
25
+ - **Risk**: Low
26
+ - **Breaking Changes**: None expected
27
+ - **Recommendation**: ✅ Safe to update
28
+ - **Changes**: Bug fixes and minor improvements
29
+
30
+ ### 2. `iconv-lite` (0.6.3 → 0.7.0)
31
+ - **Type**: Major update
32
+ - **Risk**: Medium
33
+ - **Breaking Changes**: Possible
34
+ - **Recommendation**: ⚠️ Review before updating
35
+ - **Notes**:
36
+ - Major version jump indicates potential breaking changes
37
+ - Need to verify API compatibility
38
+ - Check changelog for breaking changes
39
+
40
+ ### 3. `serialport` (12.0.0 → 13.0.0)
41
+ - **Type**: Major update
42
+ - **Risk**: High
43
+ - **Breaking Changes**: Likely
44
+ - **Recommendation**: ⚠️ Review carefully before updating
45
+ - **Notes**:
46
+ - Major version jump (12 → 13)
47
+ - Serial adapter code may need updates
48
+ - Check migration guide
49
+ - Test thoroughly with hardware
50
+
51
+ ### 4. `jest` (29.7.0 → 30.2.0)
52
+ - **Type**: Major update
53
+ - **Risk**: Low to Medium
54
+ - **Breaking Changes**: Possible
55
+ - **Recommendation**: ⚠️ Review before updating
56
+ - **Notes**:
57
+ - Major version jump (29 → 30)
58
+ - Test configuration may need updates
59
+ - Check Jest 30 migration guide
60
+ - All tests should still work, but config might need tweaks
61
+
62
+ ### 5. `usb` (2.16.0)
63
+ - **Status**: ✅ Already updated
64
+ - **Notes**: Recently migrated from 1.9.1 to 2.16.0
65
+
66
+ ## Update Recommendations
67
+
68
+ ### Priority 1: Safe Updates (Low Risk)
69
+ 1. **`debug`** → `^4.4.3`
70
+ - Minor version update
71
+ - No breaking changes expected
72
+ - Quick win
73
+
74
+ ### Priority 2: Review Required (Medium Risk)
75
+ 2. **`iconv-lite`** → `^0.7.0`
76
+ - Check changelog for breaking changes
77
+ - Test encoding functionality
78
+ - Verify all text encoding still works
79
+
80
+ 3. **`jest`** → `^30.2.0`
81
+ - Review Jest 30 release notes
82
+ - Check if test configuration needs updates
83
+ - Run all tests after update
84
+
85
+ ### Priority 3: Careful Review (High Risk)
86
+ 4. **`serialport`** → `^13.0.0`
87
+ - Major version jump
88
+ - Review migration guide
89
+ - Update serial adapter code if needed
90
+ - Test with real hardware
91
+ - May require significant code changes
92
+
93
+ ## Update Strategy
94
+
95
+ ### Option 1: Conservative (Recommended)
96
+ - Update `debug` only (safe)
97
+ - Keep others at current versions
98
+ - Monitor for issues
99
+
100
+ ### Option 2: Moderate
101
+ - Update `debug` and `iconv-lite`
102
+ - Review and test `iconv-lite` changes
103
+ - Keep `serialport` and `jest` for now
104
+
105
+ ### Option 3: Aggressive
106
+ - Update all dependencies
107
+ - Requires thorough testing
108
+ - May need code changes for `serialport`
109
+ - Higher risk of breaking changes
110
+
111
+ ## Testing Checklist (After Updates)
112
+
113
+ - [ ] Run all unit tests
114
+ - [ ] Run integration tests
115
+ - [ ] Test USB adapter with real hardware
116
+ - [ ] Test Serial adapter with real hardware
117
+ - [ ] Test text encoding with various character sets
118
+ - [ ] Verify all examples work
119
+ - [ ] Check for deprecation warnings
120
+
121
+ ## Notes
122
+
123
+ - `get-pixels` is a custom fork, version tracking not applicable
124
+ - All major updates should be tested thoroughly
125
+ - Consider updating one at a time to isolate issues
126
+ - Keep backup of working `package-lock.json` before updates
127
+
@@ -0,0 +1,122 @@
1
+ # JSDoc Documentation Review
2
+
3
+ ## Overview
4
+
5
+ This document reviews the JSDoc documentation coverage across the library.
6
+
7
+ ## Documentation Status
8
+
9
+ ### ✅ Fully Documented Modules
10
+
11
+ #### 1. **Adapter Class** (`src/adapter/index.js`)
12
+ - ✅ Class documentation with `@class` and `@classdesc`
13
+ - ✅ Constructor with `@param` documentation
14
+ - ✅ All abstract methods documented with `@abstract` and `@throws`
15
+
16
+ #### 2. **Printer Class** (`src/printer/index.js`)
17
+ - ✅ Class documentation with `@class` and `@classdesc`
18
+ - ✅ Constructor with detailed `@param` documentation
19
+ - ✅ All public methods have JSDoc with:
20
+ - `@param` for parameters
21
+ - `@return` or `@returns` for return values
22
+ - Method descriptions
23
+
24
+ #### 3. **Image Class** (`src/printer/image.js`)
25
+ - ✅ Class documentation with `@class` and `@classdesc`
26
+ - ✅ Constructor with `@param` documentation
27
+ - ✅ `toBitmap()` method documented
28
+ - ✅ `toRaster()` method documented
29
+ - ✅ `load()` static method documented with `@example`
30
+
31
+ #### 4. **Utils Module** (`src/printer/utils.js`)
32
+ - ✅ All exported functions have JSDoc:
33
+ - `getParityBit()` - with description
34
+ - `codeLength()` - with description
35
+ - `textLength()` - with description
36
+ - `textSubstring()` - with `@param` and `@returns`
37
+ - ✅ Internal `charLength()` function documented
38
+
39
+ #### 5. **Commands Module** (`src/printer/commands.js`)
40
+ - ✅ `numToHexString()` function documented with `@example`
41
+
42
+ ### ✅ Recently Added Documentation
43
+
44
+ #### 6. **USB Adapter** (`src/usb-adapter/index.js`)
45
+ - ✅ `listUSB()` - `@async`, `@returns`
46
+ - ✅ `connect()` - `@async`, `@param`, `@returns`, `@throws`, `@fires`
47
+ - ✅ `open()` - `@async`, `@returns`, `@throws`, `@fires`
48
+ - ✅ `close()` - `@async`, `@returns`, `@fires`
49
+ - ✅ `disconnect()` - `@async`, `@returns`, `@fires`
50
+ - ✅ `write()` - `@async`, `@param`, `@returns`, `@throws`
51
+ - ✅ Private `getDescriptor()` function documented
52
+
53
+ #### 7. **Serial Adapter** (`src/serial-adapter/index.js`)
54
+ - ✅ `connect()` - `@async`, `@param`, `@returns`, `@throws`, `@fires`
55
+ - ✅ `open()` - `@async`, `@returns`, `@throws`
56
+ - ✅ `write()` - `@async`, `@param`, `@returns`, `@throws`
57
+ - ✅ `close()` - `@async`, `@param`, `@returns`, `@fires`
58
+ - ✅ `disconnect()` - `@param`, `@returns`
59
+ - ✅ `read()` - `@returns`
60
+ - ✅ Private `verifyPort()` function documented
61
+
62
+ ## Documentation Quality
63
+
64
+ ### Standards Applied
65
+
66
+ 1. **Class Documentation**:
67
+ - `@class` tag
68
+ - `@classdesc` for description
69
+ - `@extends` for inheritance
70
+
71
+ 2. **Method Documentation**:
72
+ - `@async` for async methods
73
+ - `@param {Type} name - Description` for parameters
74
+ - `@returns {Type} Description` for return values
75
+ - `@throws {Error} Description` for errors
76
+ - `@fires EventName` for events emitted
77
+ - `@example` for usage examples
78
+
79
+ 3. **Function Documentation**:
80
+ - Parameter types and descriptions
81
+ - Return types and descriptions
82
+ - Usage examples where helpful
83
+
84
+ ## Coverage Summary
85
+
86
+ | Module | Classes | Methods | Functions | Coverage |
87
+ |--------|---------|---------|-----------|----------|
88
+ | `adapter/index.js` | 1 | 5 | 0 | 100% ✅ |
89
+ | `usb-adapter/index.js` | 0 | 6 | 1 | 100% ✅ |
90
+ | `serial-adapter/index.js` | 0 | 6 | 1 | 100% ✅ |
91
+ | `printer/index.js` | 2 | 30+ | 0 | 100% ✅ |
92
+ | `printer/image.js` | 1 | 3 | 0 | 100% ✅ |
93
+ | `printer/utils.js` | 0 | 0 | 5 | 100% ✅ |
94
+ | `printer/commands.js` | 0 | 0 | 1 | 100% ✅ |
95
+
96
+ **Overall JSDoc Coverage: 100%** ✅
97
+
98
+ ## Benefits
99
+
100
+ 1. **IDE Support**: Better autocomplete and type hints
101
+ 2. **Documentation Generation**: Can generate HTML docs with tools like JSDoc
102
+ 3. **Type Safety**: Helps catch errors during development
103
+ 4. **Developer Experience**: Clear API documentation for users
104
+ 5. **Maintainability**: Self-documenting code
105
+
106
+ ## Notes
107
+
108
+ - All public APIs are fully documented
109
+ - Private/internal functions are marked with `@private` where appropriate
110
+ - Event emissions are documented with `@fires`
111
+ - Async methods are marked with `@async`
112
+ - Error conditions are documented with `@throws`
113
+
114
+ ## Recommendations
115
+
116
+ The library now has comprehensive JSDoc documentation. Consider:
117
+
118
+ 1. **Documentation Generation**: Use tools like `jsdoc` or `typedoc` to generate HTML documentation
119
+ 2. **Type Checking**: Consider adding TypeScript or using JSDoc with type checking tools
120
+ 3. **Examples**: Add more `@example` tags for complex methods
121
+ 4. **Event Documentation**: Document all events that adapters can emit
122
+