@thegetty/quire-cli 1.0.0-rc.36 → 1.0.0-rc.38

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.
Files changed (91) hide show
  1. package/package.json +3 -2
  2. package/src/commands/build.js +3 -4
  3. package/src/commands/build.test.js +2 -7
  4. package/src/commands/clean.js +10 -2
  5. package/src/commands/clean.spec.js +10 -0
  6. package/src/commands/clean.test.js +122 -0
  7. package/src/commands/config.js +3 -1
  8. package/src/commands/config.test.js +42 -1
  9. package/src/commands/doctor.js +251 -0
  10. package/src/commands/doctor.spec.js +115 -0
  11. package/src/commands/doctor.test.js +1409 -0
  12. package/src/commands/epub.js +9 -2
  13. package/src/commands/info.js +79 -71
  14. package/src/commands/info.spec.js +8 -0
  15. package/src/commands/info.test.js +173 -76
  16. package/src/commands/pdf.js +10 -3
  17. package/src/commands/preview.js +8 -2
  18. package/src/commands/validate.js +39 -7
  19. package/src/commands/validate.spec.js +8 -0
  20. package/src/commands/validate.test.js +144 -0
  21. package/src/lib/11ty/api.js +25 -6
  22. package/src/lib/11ty/cli.js +17 -5
  23. package/src/lib/README.md +77 -22
  24. package/src/lib/conf/README.md +6 -0
  25. package/src/lib/conf/build-status.js +103 -0
  26. package/src/lib/conf/build-status.test.js +247 -0
  27. package/src/lib/conf/defaults.js +14 -0
  28. package/src/lib/conf/format.js +1 -1
  29. package/src/lib/conf/schema.js +46 -1
  30. package/src/lib/constants.js +28 -0
  31. package/src/lib/doctor/README.md +667 -0
  32. package/src/lib/doctor/checks/environment/cli-version.js +62 -0
  33. package/src/lib/doctor/checks/environment/cli-version.test.js +132 -0
  34. package/src/lib/doctor/checks/environment/git-available.js +77 -0
  35. package/src/lib/doctor/checks/environment/git-available.test.js +52 -0
  36. package/src/lib/doctor/checks/environment/index.js +13 -0
  37. package/src/lib/doctor/checks/environment/node-version.js +66 -0
  38. package/src/lib/doctor/checks/environment/node-version.test.js +17 -0
  39. package/src/lib/doctor/checks/environment/npm-available.js +66 -0
  40. package/src/lib/doctor/checks/environment/npm-available.test.js +52 -0
  41. package/src/lib/doctor/checks/environment/os-info.js +48 -0
  42. package/src/lib/doctor/checks/environment/os-info.test.js +81 -0
  43. package/src/lib/doctor/checks/environment/runtime-info.js +51 -0
  44. package/src/lib/doctor/checks/environment/runtime-info.test.js +132 -0
  45. package/src/lib/doctor/checks/outputs/epub-output.js +119 -0
  46. package/src/lib/doctor/checks/outputs/epub-output.test.js +277 -0
  47. package/src/lib/doctor/checks/outputs/index.js +10 -0
  48. package/src/lib/doctor/checks/outputs/pdf-output.js +144 -0
  49. package/src/lib/doctor/checks/outputs/pdf-output.test.js +377 -0
  50. package/src/lib/doctor/checks/outputs/stale-build.js +122 -0
  51. package/src/lib/doctor/checks/outputs/stale-build.test.js +282 -0
  52. package/src/lib/doctor/checks/project/data-files.js +56 -0
  53. package/src/lib/doctor/checks/project/data-files.test.js +125 -0
  54. package/src/lib/doctor/checks/project/dependencies.js +53 -0
  55. package/src/lib/doctor/checks/project/dependencies.test.js +71 -0
  56. package/src/lib/doctor/checks/project/index.js +11 -0
  57. package/src/lib/doctor/checks/project/quire-11ty.js +98 -0
  58. package/src/lib/doctor/checks/project/quire-11ty.test.js +170 -0
  59. package/src/lib/doctor/checks/project/quire-project.js +38 -0
  60. package/src/lib/doctor/checks/project/quire-project.test.js +47 -0
  61. package/src/lib/doctor/checks/tools/index.js +10 -0
  62. package/src/lib/doctor/checks/tools/pandoc-available.js +82 -0
  63. package/src/lib/doctor/checks/tools/pandoc-available.test.js +73 -0
  64. package/src/lib/doctor/checks/tools/prince-available.js +81 -0
  65. package/src/lib/doctor/checks/tools/prince-available.test.js +73 -0
  66. package/src/lib/doctor/constants.js +39 -0
  67. package/src/lib/doctor/formatDuration.js +108 -0
  68. package/src/lib/doctor/formatDuration.test.js +76 -0
  69. package/src/lib/doctor/formatters/human.js +257 -0
  70. package/src/lib/doctor/formatters/human.test.js +463 -0
  71. package/src/lib/doctor/formatters/index.js +8 -0
  72. package/src/lib/doctor/formatters/json.js +78 -0
  73. package/src/lib/doctor/formatters/json.test.js +174 -0
  74. package/src/lib/doctor/formatters/shared.js +129 -0
  75. package/src/lib/doctor/formatters/shared.test.js +194 -0
  76. package/src/lib/doctor/index.js +271 -0
  77. package/src/lib/doctor/index.test.js +797 -0
  78. package/src/lib/logger/debug.js +43 -1
  79. package/src/lib/logger/debug.test.js +128 -0
  80. package/src/lib/platform.js +95 -0
  81. package/src/lib/project/build.js +44 -25
  82. package/src/lib/project/build.test.js +30 -8
  83. package/src/lib/project/detect.js +16 -2
  84. package/src/lib/project/index.js +18 -2
  85. package/src/lib/project/output-paths.js +87 -0
  86. package/src/lib/project/output-paths.test.js +66 -0
  87. package/src/lib/project/paths.js +48 -0
  88. package/src/main.js +24 -2
  89. package/src/packageConfig.js +17 -0
  90. package/src/validators/validate-data-files.js +154 -0
  91. package/src/validators/validate-data-files.test.js +217 -0
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Tests for JSON formatter
3
+ */
4
+ import test from 'ava'
5
+ import { formatJson } from './json.js'
6
+
7
+ const mockSections = [
8
+ {
9
+ section: 'Environment',
10
+ results: [
11
+ { id: 'os', name: 'Operating system', ok: true, message: 'macOS 14' },
12
+ { id: 'node', name: 'Node.js', ok: false, level: 'error', message: 'v18 (requires v22)', remediation: 'Upgrade Node.js', docsUrl: 'https://example.com/docs' },
13
+ ],
14
+ },
15
+ {
16
+ section: 'Project',
17
+ results: [
18
+ { id: 'deps', name: 'Dependencies', ok: false, level: 'warn', message: 'Outdated' },
19
+ { id: 'build', name: 'Build', ok: true, level: 'na', message: 'No build yet' },
20
+ { id: 'data', name: 'Data', ok: false, level: 'timeout', message: 'Timed out' },
21
+ ],
22
+ },
23
+ ]
24
+
25
+ test('formatJson returns valid JSON string', (t) => {
26
+ const { json } = formatJson(mockSections)
27
+ t.notThrows(() => JSON.parse(json))
28
+ })
29
+
30
+ test('formatJson includes summary counts', (t) => {
31
+ const { json } = formatJson(mockSections)
32
+ const output = JSON.parse(json)
33
+ t.deepEqual(output.summary, {
34
+ passed: 1,
35
+ failed: 1,
36
+ warnings: 1,
37
+ timeouts: 1,
38
+ na: 1,
39
+ total: 5,
40
+ })
41
+ })
42
+
43
+ test('formatJson includes all results with correct structure', (t) => {
44
+ const { json } = formatJson(mockSections)
45
+ const output = JSON.parse(json)
46
+ t.is(output.results.length, 5)
47
+
48
+ const osCheck = output.results.find((c) => c.id === 'os')
49
+ t.deepEqual(osCheck, {
50
+ id: 'os',
51
+ name: 'Operating system',
52
+ section: 'Environment',
53
+ status: 'passed',
54
+ message: 'macOS 14',
55
+ })
56
+ })
57
+
58
+ test('formatJson includes remediation and docsUrl for failed checks', (t) => {
59
+ const { json } = formatJson(mockSections)
60
+ const output = JSON.parse(json)
61
+
62
+ const nodeCheck = output.results.find((c) => c.id === 'node')
63
+ t.is(nodeCheck.remediation, 'Upgrade Node.js')
64
+ t.is(nodeCheck.docsUrl, 'https://example.com/docs')
65
+ })
66
+
67
+ test('formatJson returns exitCode 1 when checks fail', (t) => {
68
+ const { exitCode } = formatJson(mockSections)
69
+ t.is(exitCode, 1)
70
+ })
71
+
72
+ test('formatJson returns exitCode 0 when no checks fail', (t) => {
73
+ const healthySections = [
74
+ {
75
+ section: 'Environment',
76
+ results: [{ id: 'os', name: 'OS', ok: true }],
77
+ },
78
+ ]
79
+ const { exitCode } = formatJson(healthySections)
80
+ t.is(exitCode, 0)
81
+ })
82
+
83
+ test('formatJson with errors filter includes only failed checks', (t) => {
84
+ const { json } = formatJson(mockSections, { errors: true })
85
+ const output = JSON.parse(json)
86
+ t.is(output.results.length, 1)
87
+ t.is(output.results[0].id, 'node')
88
+ t.is(output.results[0].status, 'failed')
89
+ })
90
+
91
+ test('formatJson with warnings filter includes only warning checks', (t) => {
92
+ const { json } = formatJson(mockSections, { warnings: true })
93
+ const output = JSON.parse(json)
94
+ t.is(output.results.length, 1)
95
+ t.is(output.results[0].id, 'deps')
96
+ t.is(output.results[0].status, 'warning')
97
+ })
98
+
99
+ test('formatJson summary reflects unfiltered counts when --errors filter is active', (t) => {
100
+ const { json, exitCode } = formatJson(mockSections, { errors: true })
101
+ const output = JSON.parse(json)
102
+ // results array is filtered to errors only
103
+ t.is(output.results.length, 1)
104
+ // summary counts reflect all results
105
+ t.is(output.summary.passed, 1)
106
+ t.is(output.summary.failed, 1)
107
+ t.is(output.summary.warnings, 1)
108
+ t.is(output.summary.total, 5)
109
+ t.is(exitCode, 1)
110
+ })
111
+
112
+ test('formatJson summary reflects unfiltered counts when --warnings filter is active', (t) => {
113
+ const { json, exitCode } = formatJson(mockSections, { warnings: true })
114
+ const output = JSON.parse(json)
115
+ // results array is filtered to warnings only
116
+ t.is(output.results.length, 1)
117
+ // summary counts reflect all results, including the error
118
+ t.is(output.summary.failed, 1)
119
+ t.is(output.summary.warnings, 1)
120
+ t.is(output.summary.total, 5)
121
+ t.is(exitCode, 1)
122
+ })
123
+
124
+ test('formatJson omits filter property when no filter is active', (t) => {
125
+ const { json } = formatJson(mockSections)
126
+ const output = JSON.parse(json)
127
+ t.is(output.filter, undefined)
128
+ })
129
+
130
+ test('formatJson includes filter property with --errors', (t) => {
131
+ const { json } = formatJson(mockSections, { errors: true })
132
+ const output = JSON.parse(json)
133
+ t.deepEqual(output.filter, ['errors'])
134
+ })
135
+
136
+ test('formatJson includes filter property with --warnings', (t) => {
137
+ const { json } = formatJson(mockSections, { warnings: true })
138
+ const output = JSON.parse(json)
139
+ t.deepEqual(output.filter, ['warnings'])
140
+ })
141
+
142
+ test('formatJson includes filter property with both --errors and --warnings', (t) => {
143
+ const { json } = formatJson(mockSections, { errors: true, warnings: true })
144
+ const output = JSON.parse(json)
145
+ t.deepEqual(output.filter, ['errors', 'warnings'])
146
+ })
147
+
148
+ test('formatJson with verbose includes details', (t) => {
149
+ const sectionsWithDetails = [
150
+ {
151
+ section: 'Environment',
152
+ results: [
153
+ { id: 'os', name: 'OS', ok: true, message: 'macOS', details: '/usr/bin' },
154
+ ],
155
+ },
156
+ ]
157
+ const { json } = formatJson(sectionsWithDetails, { verbose: true })
158
+ const output = JSON.parse(json)
159
+ t.is(output.results[0].details, '/usr/bin')
160
+ })
161
+
162
+ test('formatJson without verbose excludes details', (t) => {
163
+ const sectionsWithDetails = [
164
+ {
165
+ section: 'Environment',
166
+ results: [
167
+ { id: 'os', name: 'OS', ok: true, message: 'macOS', details: '/usr/bin' },
168
+ ],
169
+ },
170
+ ]
171
+ const { json } = formatJson(sectionsWithDetails, { verbose: false })
172
+ const output = JSON.parse(json)
173
+ t.is(output.results[0].details, undefined)
174
+ })
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Shared utilities for doctor output formatters
3
+ *
4
+ * @module lib/doctor/formatters/shared
5
+ */
6
+ import chalk from 'chalk'
7
+
8
+ /**
9
+ * Default terminal width when stdout is not a TTY (piped/redirected)
10
+ * @type {number}
11
+ */
12
+ const DEFAULT_COLUMNS = 80
13
+
14
+ /**
15
+ * Get the current terminal width
16
+ *
17
+ * Falls back to DEFAULT_COLUMNS when stdout is not a TTY
18
+ * (e.g., piped to a file or another process).
19
+ *
20
+ * @returns {number} Terminal width in columns
21
+ */
22
+ export function getTerminalWidth() {
23
+ return process.stdout.columns || DEFAULT_COLUMNS
24
+ }
25
+
26
+ /**
27
+ * Status types for check results
28
+ * @typedef {'passed'|'failed'|'warning'|'timeout'|'na'} CheckStatus
29
+ */
30
+
31
+ /**
32
+ * Colored status icons for check results (for terminal output)
33
+ */
34
+ export const STATUS_ICONS = {
35
+ passed: chalk.green('✓'),
36
+ failed: chalk.red('✗'),
37
+ warning: chalk.yellow('⚠'),
38
+ timeout: chalk.magenta('⏱'),
39
+ na: chalk.gray('○'),
40
+ }
41
+
42
+ /**
43
+ * Determine the status string for a check result
44
+ * @param {Object} result - Check result with ok and level properties
45
+ * @returns {CheckStatus}
46
+ */
47
+ export function getStatus(result) {
48
+ if (result.level === 'na') return 'na'
49
+ if (result.level === 'timeout') return 'timeout'
50
+ if (result.ok) return 'passed'
51
+ if (result.level === 'warn') return 'warning'
52
+ return 'failed'
53
+ }
54
+
55
+ /**
56
+ * Count results by status
57
+ * @param {Array} sections - Check results organized by section
58
+ * @param {Object} [options] - Filter options
59
+ * @param {boolean} [options.errors] - Only count failed checks
60
+ * @param {boolean} [options.warnings] - Only count warning checks
61
+ * @returns {{passed: number, failed: number, warnings: number, timeouts: number, na: number, total: number}}
62
+ */
63
+ export function countResults(sections, options = {}) {
64
+ let passed = 0
65
+ let failed = 0
66
+ let warnings = 0
67
+ let timeouts = 0
68
+ let na = 0
69
+
70
+ for (const { results } of sections) {
71
+ for (const result of results) {
72
+ const status = getStatus(result)
73
+
74
+ // Apply filters
75
+ if (options.errors && options.warnings) {
76
+ if (status !== 'failed' && status !== 'warning') continue
77
+ } else {
78
+ if (options.errors && status !== 'failed') continue
79
+ if (options.warnings && status !== 'warning') continue
80
+ }
81
+
82
+ // Count by status
83
+ if (status === 'passed') passed++
84
+ else if (status === 'failed') failed++
85
+ else if (status === 'warning') warnings++
86
+ else if (status === 'timeout') timeouts++
87
+ else if (status === 'na') na++
88
+ }
89
+ }
90
+
91
+ return {
92
+ passed,
93
+ failed,
94
+ warnings,
95
+ timeouts,
96
+ na,
97
+ total: passed + failed + warnings + timeouts + na,
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Filter results based on options
103
+ * @param {Array} sections - Check results organized by section
104
+ * @param {Object} [options] - Filter options
105
+ * @param {boolean} [options.errors] - Only include failed checks
106
+ * @param {boolean} [options.warnings] - Only include warning checks
107
+ * @returns {Array} Filtered sections (only sections with results after filtering)
108
+ */
109
+ export function filterResults(sections, options = {}) {
110
+ const filtered = []
111
+
112
+ for (const { section, results } of sections) {
113
+ const filteredResults = results.filter((result) => {
114
+ const status = getStatus(result)
115
+ if (options.errors && options.warnings) {
116
+ return status === 'failed' || status === 'warning'
117
+ }
118
+ if (options.errors && status !== 'failed') return false
119
+ if (options.warnings && status !== 'warning') return false
120
+ return true
121
+ })
122
+
123
+ if (filteredResults.length > 0) {
124
+ filtered.push({ section, results: filteredResults })
125
+ }
126
+ }
127
+
128
+ return filtered
129
+ }
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Tests for shared formatter utilities
3
+ */
4
+ import test from 'ava'
5
+ import { getStatus, STATUS_ICONS, countResults, filterResults, getTerminalWidth } from './shared.js'
6
+
7
+ // =============================================================================
8
+ // getStatus tests
9
+ // =============================================================================
10
+
11
+ test('getStatus returns "na" for level na', (t) => {
12
+ t.is(getStatus({ ok: true, level: 'na' }), 'na')
13
+ t.is(getStatus({ ok: false, level: 'na' }), 'na')
14
+ })
15
+
16
+ test('getStatus returns "timeout" for level timeout', (t) => {
17
+ t.is(getStatus({ ok: false, level: 'timeout' }), 'timeout')
18
+ })
19
+
20
+ test('getStatus returns "passed" when ok is true', (t) => {
21
+ t.is(getStatus({ ok: true }), 'passed')
22
+ t.is(getStatus({ ok: true, level: 'error' }), 'passed')
23
+ })
24
+
25
+ test('getStatus returns "warning" for level warn when not ok', (t) => {
26
+ t.is(getStatus({ ok: false, level: 'warn' }), 'warning')
27
+ })
28
+
29
+ test('getStatus returns "failed" for level error when not ok', (t) => {
30
+ t.is(getStatus({ ok: false, level: 'error' }), 'failed')
31
+ t.is(getStatus({ ok: false }), 'failed')
32
+ })
33
+
34
+ // =============================================================================
35
+ // STATUS_ICONS tests
36
+ // =============================================================================
37
+
38
+ test('STATUS_ICONS has all required status types', (t) => {
39
+ t.truthy(STATUS_ICONS.passed)
40
+ t.truthy(STATUS_ICONS.failed)
41
+ t.truthy(STATUS_ICONS.warning)
42
+ t.truthy(STATUS_ICONS.timeout)
43
+ t.truthy(STATUS_ICONS.na)
44
+ })
45
+
46
+ test('STATUS_ICONS are strings containing expected characters', (t) => {
47
+ // Strip ANSI codes to check actual characters
48
+ const stripAnsi = (str) => str.replace(/\u001b\[[0-9;]*m/g, '')
49
+ t.is(stripAnsi(STATUS_ICONS.passed), '✓')
50
+ t.is(stripAnsi(STATUS_ICONS.failed), '✗')
51
+ t.is(stripAnsi(STATUS_ICONS.warning), '⚠')
52
+ t.is(stripAnsi(STATUS_ICONS.timeout), '⏱')
53
+ t.is(stripAnsi(STATUS_ICONS.na), '○')
54
+ })
55
+
56
+ // =============================================================================
57
+ // countResults tests
58
+ // =============================================================================
59
+
60
+ const mockSections = [
61
+ {
62
+ section: 'Environment',
63
+ results: [
64
+ { id: 'os', ok: true },
65
+ { id: 'cli', ok: true },
66
+ { id: 'node', ok: false, level: 'error' },
67
+ ],
68
+ },
69
+ {
70
+ section: 'Project',
71
+ results: [
72
+ { id: 'project', ok: false, level: 'warn' },
73
+ { id: 'deps', ok: true, level: 'na' },
74
+ { id: 'data', ok: false, level: 'timeout' },
75
+ ],
76
+ },
77
+ ]
78
+
79
+ test('countResults counts all status types correctly', (t) => {
80
+ const counts = countResults(mockSections)
81
+ t.is(counts.passed, 2)
82
+ t.is(counts.failed, 1)
83
+ t.is(counts.warnings, 1)
84
+ t.is(counts.timeouts, 1)
85
+ t.is(counts.na, 1)
86
+ t.is(counts.total, 6)
87
+ })
88
+
89
+ test('countResults with errors filter counts only failed', (t) => {
90
+ const counts = countResults(mockSections, { errors: true })
91
+ t.is(counts.failed, 1)
92
+ t.is(counts.passed, 0)
93
+ t.is(counts.warnings, 0)
94
+ t.is(counts.total, 1)
95
+ })
96
+
97
+ test('countResults with warnings filter counts only warnings', (t) => {
98
+ const counts = countResults(mockSections, { warnings: true })
99
+ t.is(counts.warnings, 1)
100
+ t.is(counts.passed, 0)
101
+ t.is(counts.failed, 0)
102
+ t.is(counts.total, 1)
103
+ })
104
+
105
+ // =============================================================================
106
+ // filterResults tests
107
+ // =============================================================================
108
+
109
+ test('filterResults returns all results when no filter applied', (t) => {
110
+ const filtered = filterResults(mockSections)
111
+ t.is(filtered.length, 2)
112
+ t.is(filtered[0].results.length, 3)
113
+ t.is(filtered[1].results.length, 3)
114
+ })
115
+
116
+ test('filterResults with errors filter returns only failed checks', (t) => {
117
+ const filtered = filterResults(mockSections, { errors: true })
118
+ t.is(filtered.length, 1) // Only Environment section has failed check
119
+ t.is(filtered[0].section, 'Environment')
120
+ t.is(filtered[0].results.length, 1)
121
+ t.is(filtered[0].results[0].id, 'node')
122
+ })
123
+
124
+ test('filterResults with warnings filter returns only warning checks', (t) => {
125
+ const filtered = filterResults(mockSections, { warnings: true })
126
+ t.is(filtered.length, 1) // Only Project section has warning check
127
+ t.is(filtered[0].section, 'Project')
128
+ t.is(filtered[0].results.length, 1)
129
+ t.is(filtered[0].results[0].id, 'project')
130
+ })
131
+
132
+ test('countResults with both errors and warnings filter counts failed and warnings', (t) => {
133
+ const counts = countResults(mockSections, { errors: true, warnings: true })
134
+ t.is(counts.failed, 1)
135
+ t.is(counts.warnings, 1)
136
+ t.is(counts.passed, 0)
137
+ t.is(counts.timeouts, 0)
138
+ t.is(counts.na, 0)
139
+ t.is(counts.total, 2)
140
+ })
141
+
142
+ test('filterResults with both errors and warnings returns failed and warning checks', (t) => {
143
+ const filtered = filterResults(mockSections, { errors: true, warnings: true })
144
+ t.is(filtered.length, 2) // Both sections have matching checks
145
+ // Environment has failed check
146
+ t.is(filtered[0].section, 'Environment')
147
+ t.is(filtered[0].results.length, 1)
148
+ t.is(filtered[0].results[0].id, 'node')
149
+ // Project has warning check
150
+ t.is(filtered[1].section, 'Project')
151
+ t.is(filtered[1].results.length, 1)
152
+ t.is(filtered[1].results[0].id, 'project')
153
+ })
154
+
155
+ test('filterResults excludes empty sections', (t) => {
156
+ const sections = [
157
+ { section: 'A', results: [{ ok: true }] },
158
+ { section: 'B', results: [{ ok: true }] },
159
+ ]
160
+ const filtered = filterResults(sections, { errors: true })
161
+ t.is(filtered.length, 0)
162
+ })
163
+
164
+ // =============================================================================
165
+ // getTerminalWidth tests
166
+ // =============================================================================
167
+
168
+ test('getTerminalWidth returns a positive number', (t) => {
169
+ const width = getTerminalWidth()
170
+ t.is(typeof width, 'number')
171
+ t.true(width > 0)
172
+ })
173
+
174
+ test('getTerminalWidth returns at least 80 when not a TTY', (t) => {
175
+ // In test environments stdout is typically not a TTY,
176
+ // so columns is undefined and the fallback (80) is used
177
+ const original = process.stdout.columns
178
+ process.stdout.columns = undefined
179
+ try {
180
+ t.is(getTerminalWidth(), 80)
181
+ } finally {
182
+ process.stdout.columns = original
183
+ }
184
+ })
185
+
186
+ test('getTerminalWidth returns stdout.columns when available', (t) => {
187
+ const original = process.stdout.columns
188
+ process.stdout.columns = 120
189
+ try {
190
+ t.is(getTerminalWidth(), 120)
191
+ } finally {
192
+ process.stdout.columns = original
193
+ }
194
+ })