punctilio 1.4.1 → 1.4.2
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/package.json +1 -1
- package/src/tests/utils.test.ts +23 -34
package/package.json
CHANGED
package/src/tests/utils.test.ts
CHANGED
|
@@ -59,9 +59,26 @@ describe("assertSeparatorCountPreserved", () => {
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
describe("formatErrorString", () => {
|
|
62
|
+
let originalWrite: typeof process.stderr.write
|
|
63
|
+
let stderrOutput: string[]
|
|
64
|
+
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
originalWrite = process.stderr.write
|
|
67
|
+
stderrOutput = []
|
|
68
|
+
process.stderr.write = ((chunk: string) => {
|
|
69
|
+
stderrOutput.push(chunk)
|
|
70
|
+
return true
|
|
71
|
+
}) as typeof process.stderr.write
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
afterEach(() => {
|
|
75
|
+
process.stderr.write = originalWrite
|
|
76
|
+
})
|
|
77
|
+
|
|
62
78
|
it("returns JSON-stringified content for short strings", () => {
|
|
63
79
|
const result = formatErrorString("short text", "test")
|
|
64
80
|
expect(result).toBe('"short text"')
|
|
81
|
+
expect(stderrOutput).toHaveLength(0)
|
|
65
82
|
})
|
|
66
83
|
|
|
67
84
|
it("truncates strings over 2000 chars with label and length", () => {
|
|
@@ -77,52 +94,24 @@ describe("formatErrorString", () => {
|
|
|
77
94
|
const longText = "a".repeat(1500) + "b".repeat(1000)
|
|
78
95
|
const result = formatErrorString(longText, "mixed")
|
|
79
96
|
|
|
80
|
-
// Should contain all 1500 a's and first 500 b's (2000 total)
|
|
81
97
|
const expected2000 = "a".repeat(1500) + "b".repeat(500)
|
|
82
98
|
expect(result).toContain(JSON.stringify(expected2000))
|
|
83
99
|
expect(result).toContain("2500 chars total")
|
|
84
100
|
})
|
|
85
101
|
|
|
86
102
|
it("writes full content to stderr in Node.js for long strings", () => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
process.stderr.write = ((chunk: string) => {
|
|
90
|
-
written.push(chunk)
|
|
91
|
-
return true
|
|
92
|
-
}) as typeof process.stderr.write
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const longText = "z".repeat(2001)
|
|
96
|
-
formatErrorString(longText, "stderr-test")
|
|
97
|
-
|
|
98
|
-
expect(written.length).toBe(1)
|
|
99
|
-
expect(written[0]).toContain("punctilio stderr-test full content")
|
|
100
|
-
expect(written[0]).toContain(longText)
|
|
101
|
-
} finally {
|
|
102
|
-
process.stderr.write = originalWrite
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it("does not write to stderr for short strings", () => {
|
|
107
|
-
const originalWrite = process.stderr.write
|
|
108
|
-
const written: string[] = []
|
|
109
|
-
process.stderr.write = ((chunk: string) => {
|
|
110
|
-
written.push(chunk)
|
|
111
|
-
return true
|
|
112
|
-
}) as typeof process.stderr.write
|
|
103
|
+
const longText = "z".repeat(2001)
|
|
104
|
+
formatErrorString(longText, "stderr-test")
|
|
113
105
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
} finally {
|
|
118
|
-
process.stderr.write = originalWrite
|
|
119
|
-
}
|
|
106
|
+
expect(stderrOutput).toHaveLength(1)
|
|
107
|
+
expect(stderrOutput[0]).toContain("punctilio stderr-test full content")
|
|
108
|
+
expect(stderrOutput[0]).toContain(longText)
|
|
120
109
|
})
|
|
121
110
|
|
|
122
111
|
it("handles strings at exactly the threshold", () => {
|
|
123
112
|
const exactText = "x".repeat(2000)
|
|
124
113
|
const result = formatErrorString(exactText, "exact")
|
|
125
|
-
// At threshold, should return JSON-stringified (not truncated)
|
|
126
114
|
expect(result).toBe(JSON.stringify(exactText))
|
|
115
|
+
expect(stderrOutput).toHaveLength(0)
|
|
127
116
|
})
|
|
128
117
|
})
|