@thegetty/quire-cli 1.0.0-rc.45 → 1.0.0-rc.47

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 (245) hide show
  1. package/CHANGELOG.md +0 -36
  2. package/README.md +0 -9
  3. package/bin/cli.js +1 -46
  4. package/package.json +10 -27
  5. package/src/Command.js +6 -26
  6. package/src/commands/README.md +122 -213
  7. package/src/commands/build.js +37 -45
  8. package/src/commands/clean.js +19 -33
  9. package/src/commands/conf.js +43 -0
  10. package/src/commands/create.js +14 -42
  11. package/src/commands/epub.js +31 -67
  12. package/src/commands/index.js +2 -9
  13. package/src/commands/info.js +86 -88
  14. package/src/commands/pdf.js +82 -63
  15. package/src/commands/preview.js +31 -32
  16. package/src/commands/validate.js +20 -64
  17. package/src/commands/version.js +43 -0
  18. package/src/errors/validation/validation-error.js +11 -20
  19. package/src/helpers/clean.js +1 -1
  20. package/src/helpers/is-quire.js +31 -0
  21. package/src/helpers/test-cwd.js +6 -5
  22. package/src/helpers/which.js +4 -10
  23. package/src/lib/11ty/README.md +19 -135
  24. package/src/lib/11ty/api.js +93 -235
  25. package/src/lib/11ty/cli.js +37 -112
  26. package/src/lib/11ty/index.js +5 -64
  27. package/src/lib/11ty/paths.js +103 -0
  28. package/src/lib/README.md +0 -330
  29. package/src/lib/conf/README.md +69 -86
  30. package/src/lib/conf/config.js +3 -5
  31. package/src/lib/conf/defaults.js +0 -65
  32. package/src/lib/conf/schema.js +9 -103
  33. package/src/lib/epub/README.md +2 -133
  34. package/src/lib/epub/epub.js +11 -36
  35. package/src/lib/epub/index.js +21 -111
  36. package/src/lib/epub/pandoc.js +4 -33
  37. package/src/lib/git/README.md +2 -151
  38. package/src/lib/git/index.js +13 -217
  39. package/src/lib/i18n/README.md +3 -0
  40. package/src/lib/i18n/config.js +53 -0
  41. package/src/lib/i18n/index.js +43 -0
  42. package/src/lib/i18n/localeService.js +58 -0
  43. package/src/lib/pdf/README.md +0 -131
  44. package/src/lib/pdf/index.js +21 -124
  45. package/src/lib/pdf/paged.js +52 -100
  46. package/src/lib/pdf/prince.js +37 -115
  47. package/src/lib/pdf/split.js +33 -61
  48. package/src/lib/quire/README.md +19 -0
  49. package/src/lib/quire/index.js +353 -0
  50. package/src/lib/reporter/README.md +2 -211
  51. package/src/lib/reporter/index.js +0 -607
  52. package/src/main.js +48 -221
  53. package/src/packageConfig.js +0 -17
  54. package/src/validators/utils.js +1 -2
  55. package/man/quire.1 +0 -341
  56. package/man/quire.1.md +0 -232
  57. package/schemas/config.schema.json +0 -194
  58. package/schemas/figures.schema.json +0 -56
  59. package/schemas/layout.schema.json +0 -5
  60. package/schemas/objects.schema.json +0 -62
  61. package/schemas/publication.schema.json +0 -140
  62. package/schemas/references.schema.json +0 -29
  63. package/src/Command.spec.js +0 -99
  64. package/src/commands/build.spec.js +0 -113
  65. package/src/commands/build.test.js +0 -397
  66. package/src/commands/clean.spec.js +0 -118
  67. package/src/commands/clean.test.js +0 -382
  68. package/src/commands/config.js +0 -238
  69. package/src/commands/config.spec.js +0 -107
  70. package/src/commands/config.test.js +0 -845
  71. package/src/commands/create.spec.js +0 -112
  72. package/src/commands/create.test.js +0 -415
  73. package/src/commands/doctor.js +0 -251
  74. package/src/commands/doctor.spec.js +0 -115
  75. package/src/commands/doctor.test.js +0 -1409
  76. package/src/commands/epub.spec.js +0 -114
  77. package/src/commands/epub.test.js +0 -503
  78. package/src/commands/help.js +0 -60
  79. package/src/commands/help.test.js +0 -132
  80. package/src/commands/info.spec.js +0 -72
  81. package/src/commands/info.test.js +0 -512
  82. package/src/commands/pdf.spec.js +0 -114
  83. package/src/commands/pdf.test.js +0 -464
  84. package/src/commands/preview.spec.js +0 -97
  85. package/src/commands/preview.test.js +0 -250
  86. package/src/commands/use.js +0 -56
  87. package/src/commands/use.spec.js +0 -61
  88. package/src/commands/use.test.js +0 -280
  89. package/src/commands/validate.spec.js +0 -90
  90. package/src/commands/validate.test.js +0 -378
  91. package/src/commands/workflows.js +0 -70
  92. package/src/errors/build/build-failed-error.js +0 -19
  93. package/src/errors/build/config-field-missing-error.js +0 -20
  94. package/src/errors/build/config-file-not-found-error.js +0 -20
  95. package/src/errors/build/index.js +0 -11
  96. package/src/errors/help/help-topic-not-found-error.js +0 -30
  97. package/src/errors/help/index.js +0 -8
  98. package/src/errors/index.js +0 -58
  99. package/src/errors/input/index.js +0 -8
  100. package/src/errors/input/invalid-input-error.js +0 -21
  101. package/src/errors/install/dependency-install-error.js +0 -19
  102. package/src/errors/install/directory-not-empty-error.js +0 -25
  103. package/src/errors/install/index.js +0 -12
  104. package/src/errors/install/invalid-path-error.js +0 -31
  105. package/src/errors/install/invalid-starter-error.js +0 -27
  106. package/src/errors/install/version-not-found-error.js +0 -35
  107. package/src/errors/output/epub-generation-error.js +0 -19
  108. package/src/errors/output/index.js +0 -14
  109. package/src/errors/output/invalid-epub-library-error.js +0 -20
  110. package/src/errors/output/invalid-pdf-library-error.js +0 -20
  111. package/src/errors/output/missing-build-output-error.js +0 -21
  112. package/src/errors/output/pdf-generation-error.js +0 -24
  113. package/src/errors/output/tool-not-found-error.js +0 -37
  114. package/src/errors/project/index.js +0 -10
  115. package/src/errors/project/not-in-project-error.js +0 -20
  116. package/src/errors/project/project-create-error.js +0 -21
  117. package/src/errors/quire-error.js +0 -27
  118. package/src/errors/validation/index.js +0 -3
  119. package/src/errors/validation/unknown-config-key-error.js +0 -27
  120. package/src/errors/validation/unknown-config-operation-error.js +0 -24
  121. package/src/helpers/docs-url.js +0 -32
  122. package/src/helpers/pager.js +0 -59
  123. package/src/helpers/pager.test.js +0 -85
  124. package/src/helpers/suggest-similar.js +0 -124
  125. package/src/helpers/suggest-similar.test.js +0 -108
  126. package/src/helpers/test-cwd.test.js +0 -192
  127. package/src/lib/11ty/index.test.js +0 -655
  128. package/src/lib/commander/index.js +0 -103
  129. package/src/lib/commander/index.test.js +0 -86
  130. package/src/lib/commander/options.js +0 -237
  131. package/src/lib/commander/options.test.js +0 -205
  132. package/src/lib/conf/build-status.js +0 -103
  133. package/src/lib/conf/build-status.test.js +0 -247
  134. package/src/lib/conf/config.test.js +0 -281
  135. package/src/lib/conf/format.js +0 -60
  136. package/src/lib/conf/format.test.js +0 -106
  137. package/src/lib/conf/helpers.js +0 -91
  138. package/src/lib/conf/helpers.test.js +0 -136
  139. package/src/lib/conf/index.js +0 -22
  140. package/src/lib/constants.js +0 -28
  141. package/src/lib/doctor/README.md +0 -667
  142. package/src/lib/doctor/checks/environment/cli-version.js +0 -62
  143. package/src/lib/doctor/checks/environment/cli-version.test.js +0 -132
  144. package/src/lib/doctor/checks/environment/git-available.js +0 -77
  145. package/src/lib/doctor/checks/environment/git-available.test.js +0 -52
  146. package/src/lib/doctor/checks/environment/index.js +0 -13
  147. package/src/lib/doctor/checks/environment/node-version.js +0 -66
  148. package/src/lib/doctor/checks/environment/node-version.test.js +0 -17
  149. package/src/lib/doctor/checks/environment/npm-available.js +0 -66
  150. package/src/lib/doctor/checks/environment/npm-available.test.js +0 -52
  151. package/src/lib/doctor/checks/environment/os-info.js +0 -48
  152. package/src/lib/doctor/checks/environment/os-info.test.js +0 -81
  153. package/src/lib/doctor/checks/environment/runtime-info.js +0 -51
  154. package/src/lib/doctor/checks/environment/runtime-info.test.js +0 -132
  155. package/src/lib/doctor/checks/outputs/epub-output.js +0 -119
  156. package/src/lib/doctor/checks/outputs/epub-output.test.js +0 -277
  157. package/src/lib/doctor/checks/outputs/index.js +0 -10
  158. package/src/lib/doctor/checks/outputs/pdf-output.js +0 -144
  159. package/src/lib/doctor/checks/outputs/pdf-output.test.js +0 -377
  160. package/src/lib/doctor/checks/outputs/stale-build.js +0 -122
  161. package/src/lib/doctor/checks/outputs/stale-build.test.js +0 -282
  162. package/src/lib/doctor/checks/project/data-files.js +0 -56
  163. package/src/lib/doctor/checks/project/data-files.test.js +0 -125
  164. package/src/lib/doctor/checks/project/dependencies.js +0 -53
  165. package/src/lib/doctor/checks/project/dependencies.test.js +0 -71
  166. package/src/lib/doctor/checks/project/index.js +0 -11
  167. package/src/lib/doctor/checks/project/quire-11ty.js +0 -98
  168. package/src/lib/doctor/checks/project/quire-11ty.test.js +0 -170
  169. package/src/lib/doctor/checks/project/quire-project.js +0 -38
  170. package/src/lib/doctor/checks/project/quire-project.test.js +0 -47
  171. package/src/lib/doctor/checks/tools/index.js +0 -10
  172. package/src/lib/doctor/checks/tools/pandoc-available.js +0 -82
  173. package/src/lib/doctor/checks/tools/pandoc-available.test.js +0 -73
  174. package/src/lib/doctor/checks/tools/prince-available.js +0 -81
  175. package/src/lib/doctor/checks/tools/prince-available.test.js +0 -73
  176. package/src/lib/doctor/constants.js +0 -39
  177. package/src/lib/doctor/formatDuration.js +0 -108
  178. package/src/lib/doctor/formatDuration.test.js +0 -76
  179. package/src/lib/doctor/formatters/human.js +0 -257
  180. package/src/lib/doctor/formatters/human.test.js +0 -463
  181. package/src/lib/doctor/formatters/index.js +0 -8
  182. package/src/lib/doctor/formatters/json.js +0 -78
  183. package/src/lib/doctor/formatters/json.test.js +0 -174
  184. package/src/lib/doctor/formatters/shared.js +0 -129
  185. package/src/lib/doctor/formatters/shared.test.js +0 -194
  186. package/src/lib/doctor/index.js +0 -271
  187. package/src/lib/doctor/index.test.js +0 -797
  188. package/src/lib/epub/engines.js +0 -46
  189. package/src/lib/epub/index.test.js +0 -518
  190. package/src/lib/epub/pandoc.test.js +0 -122
  191. package/src/lib/epub/schema.js +0 -21
  192. package/src/lib/error/README.md +0 -170
  193. package/src/lib/error/handler.js +0 -107
  194. package/src/lib/git/index.spec.js +0 -80
  195. package/src/lib/git/index.test.js +0 -453
  196. package/src/lib/help/frontmatter.js +0 -77
  197. package/src/lib/help/frontmatter.test.js +0 -139
  198. package/src/lib/help/index.js +0 -146
  199. package/src/lib/help/index.test.js +0 -188
  200. package/src/lib/help/topics/configuration.md +0 -77
  201. package/src/lib/help/topics/debugging.md +0 -69
  202. package/src/lib/help/topics/epub.md +0 -74
  203. package/src/lib/help/topics/pdf.md +0 -74
  204. package/src/lib/help/topics/publishing.md +0 -80
  205. package/src/lib/help/topics/workflows.md +0 -50
  206. package/src/lib/installer/index.js +0 -309
  207. package/src/lib/installer/index.spec.js +0 -83
  208. package/src/lib/installer/index.test.js +0 -545
  209. package/src/lib/logger/README.md +0 -424
  210. package/src/lib/logger/debug.js +0 -132
  211. package/src/lib/logger/debug.spec.js +0 -130
  212. package/src/lib/logger/debug.test.js +0 -128
  213. package/src/lib/logger/index.js +0 -228
  214. package/src/lib/logger/index.spec.js +0 -131
  215. package/src/lib/logger/index.test.js +0 -578
  216. package/src/lib/npm/README.md +0 -127
  217. package/src/lib/npm/index.js +0 -198
  218. package/src/lib/npm/index.spec.js +0 -60
  219. package/src/lib/npm/index.test.js +0 -355
  220. package/src/lib/pdf/engines.js +0 -46
  221. package/src/lib/pdf/index.test.js +0 -708
  222. package/src/lib/pdf/paged.test.js +0 -366
  223. package/src/lib/pdf/prince.test.js +0 -202
  224. package/src/lib/pdf/schema.js +0 -21
  225. package/src/lib/pdf/split.test.js +0 -445
  226. package/src/lib/platform.js +0 -95
  227. package/src/lib/process/manager.js +0 -110
  228. package/src/lib/process/manager.test.js +0 -55
  229. package/src/lib/project/build.js +0 -162
  230. package/src/lib/project/build.test.js +0 -275
  231. package/src/lib/project/config.js +0 -48
  232. package/src/lib/project/config.test.js +0 -134
  233. package/src/lib/project/detect.js +0 -47
  234. package/src/lib/project/detect.test.js +0 -157
  235. package/src/lib/project/index.js +0 -56
  236. package/src/lib/project/output-paths.js +0 -87
  237. package/src/lib/project/output-paths.test.js +0 -66
  238. package/src/lib/project/paths.js +0 -272
  239. package/src/lib/project/version.js +0 -110
  240. package/src/lib/project/version.test.js +0 -350
  241. package/src/lib/reporter/index.test.js +0 -862
  242. package/src/main.spec.js +0 -61
  243. package/src/main.test.js +0 -347
  244. package/src/validators/validate-data-files.js +0 -154
  245. package/src/validators/validate-data-files.test.js +0 -217
@@ -1,174 +0,0 @@
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
- })
@@ -1,129 +0,0 @@
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
- }
@@ -1,194 +0,0 @@
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
- })