@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.
- package/CHANGELOG.md +0 -36
- package/README.md +0 -9
- package/bin/cli.js +1 -46
- package/package.json +10 -27
- package/src/Command.js +6 -26
- package/src/commands/README.md +122 -213
- package/src/commands/build.js +37 -45
- package/src/commands/clean.js +19 -33
- package/src/commands/conf.js +43 -0
- package/src/commands/create.js +14 -42
- package/src/commands/epub.js +31 -67
- package/src/commands/index.js +2 -9
- package/src/commands/info.js +86 -88
- package/src/commands/pdf.js +82 -63
- package/src/commands/preview.js +31 -32
- package/src/commands/validate.js +20 -64
- package/src/commands/version.js +43 -0
- package/src/errors/validation/validation-error.js +11 -20
- package/src/helpers/clean.js +1 -1
- package/src/helpers/is-quire.js +31 -0
- package/src/helpers/test-cwd.js +6 -5
- package/src/helpers/which.js +4 -10
- package/src/lib/11ty/README.md +19 -135
- package/src/lib/11ty/api.js +93 -235
- package/src/lib/11ty/cli.js +37 -112
- package/src/lib/11ty/index.js +5 -64
- package/src/lib/11ty/paths.js +103 -0
- package/src/lib/README.md +0 -330
- package/src/lib/conf/README.md +69 -86
- package/src/lib/conf/config.js +3 -5
- package/src/lib/conf/defaults.js +0 -65
- package/src/lib/conf/schema.js +9 -103
- package/src/lib/epub/README.md +2 -133
- package/src/lib/epub/epub.js +11 -36
- package/src/lib/epub/index.js +21 -111
- package/src/lib/epub/pandoc.js +4 -33
- package/src/lib/git/README.md +2 -151
- package/src/lib/git/index.js +13 -217
- package/src/lib/i18n/README.md +3 -0
- package/src/lib/i18n/config.js +53 -0
- package/src/lib/i18n/index.js +43 -0
- package/src/lib/i18n/localeService.js +58 -0
- package/src/lib/pdf/README.md +0 -131
- package/src/lib/pdf/index.js +21 -124
- package/src/lib/pdf/paged.js +52 -100
- package/src/lib/pdf/prince.js +37 -115
- package/src/lib/pdf/split.js +33 -61
- package/src/lib/quire/README.md +19 -0
- package/src/lib/quire/index.js +353 -0
- package/src/lib/reporter/README.md +2 -211
- package/src/lib/reporter/index.js +0 -607
- package/src/main.js +48 -221
- package/src/packageConfig.js +0 -17
- package/src/validators/utils.js +1 -2
- package/man/quire.1 +0 -341
- package/man/quire.1.md +0 -232
- package/schemas/config.schema.json +0 -194
- package/schemas/figures.schema.json +0 -56
- package/schemas/layout.schema.json +0 -5
- package/schemas/objects.schema.json +0 -62
- package/schemas/publication.schema.json +0 -140
- package/schemas/references.schema.json +0 -29
- package/src/Command.spec.js +0 -99
- package/src/commands/build.spec.js +0 -113
- package/src/commands/build.test.js +0 -397
- package/src/commands/clean.spec.js +0 -118
- package/src/commands/clean.test.js +0 -382
- package/src/commands/config.js +0 -238
- package/src/commands/config.spec.js +0 -107
- package/src/commands/config.test.js +0 -845
- package/src/commands/create.spec.js +0 -112
- package/src/commands/create.test.js +0 -415
- package/src/commands/doctor.js +0 -251
- package/src/commands/doctor.spec.js +0 -115
- package/src/commands/doctor.test.js +0 -1409
- package/src/commands/epub.spec.js +0 -114
- package/src/commands/epub.test.js +0 -503
- package/src/commands/help.js +0 -60
- package/src/commands/help.test.js +0 -132
- package/src/commands/info.spec.js +0 -72
- package/src/commands/info.test.js +0 -512
- package/src/commands/pdf.spec.js +0 -114
- package/src/commands/pdf.test.js +0 -464
- package/src/commands/preview.spec.js +0 -97
- package/src/commands/preview.test.js +0 -250
- package/src/commands/use.js +0 -56
- package/src/commands/use.spec.js +0 -61
- package/src/commands/use.test.js +0 -280
- package/src/commands/validate.spec.js +0 -90
- package/src/commands/validate.test.js +0 -378
- package/src/commands/workflows.js +0 -70
- package/src/errors/build/build-failed-error.js +0 -19
- package/src/errors/build/config-field-missing-error.js +0 -20
- package/src/errors/build/config-file-not-found-error.js +0 -20
- package/src/errors/build/index.js +0 -11
- package/src/errors/help/help-topic-not-found-error.js +0 -30
- package/src/errors/help/index.js +0 -8
- package/src/errors/index.js +0 -58
- package/src/errors/input/index.js +0 -8
- package/src/errors/input/invalid-input-error.js +0 -21
- package/src/errors/install/dependency-install-error.js +0 -19
- package/src/errors/install/directory-not-empty-error.js +0 -25
- package/src/errors/install/index.js +0 -12
- package/src/errors/install/invalid-path-error.js +0 -31
- package/src/errors/install/invalid-starter-error.js +0 -27
- package/src/errors/install/version-not-found-error.js +0 -35
- package/src/errors/output/epub-generation-error.js +0 -19
- package/src/errors/output/index.js +0 -14
- package/src/errors/output/invalid-epub-library-error.js +0 -20
- package/src/errors/output/invalid-pdf-library-error.js +0 -20
- package/src/errors/output/missing-build-output-error.js +0 -21
- package/src/errors/output/pdf-generation-error.js +0 -24
- package/src/errors/output/tool-not-found-error.js +0 -37
- package/src/errors/project/index.js +0 -10
- package/src/errors/project/not-in-project-error.js +0 -20
- package/src/errors/project/project-create-error.js +0 -21
- package/src/errors/quire-error.js +0 -27
- package/src/errors/validation/index.js +0 -3
- package/src/errors/validation/unknown-config-key-error.js +0 -27
- package/src/errors/validation/unknown-config-operation-error.js +0 -24
- package/src/helpers/docs-url.js +0 -32
- package/src/helpers/pager.js +0 -59
- package/src/helpers/pager.test.js +0 -85
- package/src/helpers/suggest-similar.js +0 -124
- package/src/helpers/suggest-similar.test.js +0 -108
- package/src/helpers/test-cwd.test.js +0 -192
- package/src/lib/11ty/index.test.js +0 -655
- package/src/lib/commander/index.js +0 -103
- package/src/lib/commander/index.test.js +0 -86
- package/src/lib/commander/options.js +0 -237
- package/src/lib/commander/options.test.js +0 -205
- package/src/lib/conf/build-status.js +0 -103
- package/src/lib/conf/build-status.test.js +0 -247
- package/src/lib/conf/config.test.js +0 -281
- package/src/lib/conf/format.js +0 -60
- package/src/lib/conf/format.test.js +0 -106
- package/src/lib/conf/helpers.js +0 -91
- package/src/lib/conf/helpers.test.js +0 -136
- package/src/lib/conf/index.js +0 -22
- package/src/lib/constants.js +0 -28
- package/src/lib/doctor/README.md +0 -667
- package/src/lib/doctor/checks/environment/cli-version.js +0 -62
- package/src/lib/doctor/checks/environment/cli-version.test.js +0 -132
- package/src/lib/doctor/checks/environment/git-available.js +0 -77
- package/src/lib/doctor/checks/environment/git-available.test.js +0 -52
- package/src/lib/doctor/checks/environment/index.js +0 -13
- package/src/lib/doctor/checks/environment/node-version.js +0 -66
- package/src/lib/doctor/checks/environment/node-version.test.js +0 -17
- package/src/lib/doctor/checks/environment/npm-available.js +0 -66
- package/src/lib/doctor/checks/environment/npm-available.test.js +0 -52
- package/src/lib/doctor/checks/environment/os-info.js +0 -48
- package/src/lib/doctor/checks/environment/os-info.test.js +0 -81
- package/src/lib/doctor/checks/environment/runtime-info.js +0 -51
- package/src/lib/doctor/checks/environment/runtime-info.test.js +0 -132
- package/src/lib/doctor/checks/outputs/epub-output.js +0 -119
- package/src/lib/doctor/checks/outputs/epub-output.test.js +0 -277
- package/src/lib/doctor/checks/outputs/index.js +0 -10
- package/src/lib/doctor/checks/outputs/pdf-output.js +0 -144
- package/src/lib/doctor/checks/outputs/pdf-output.test.js +0 -377
- package/src/lib/doctor/checks/outputs/stale-build.js +0 -122
- package/src/lib/doctor/checks/outputs/stale-build.test.js +0 -282
- package/src/lib/doctor/checks/project/data-files.js +0 -56
- package/src/lib/doctor/checks/project/data-files.test.js +0 -125
- package/src/lib/doctor/checks/project/dependencies.js +0 -53
- package/src/lib/doctor/checks/project/dependencies.test.js +0 -71
- package/src/lib/doctor/checks/project/index.js +0 -11
- package/src/lib/doctor/checks/project/quire-11ty.js +0 -98
- package/src/lib/doctor/checks/project/quire-11ty.test.js +0 -170
- package/src/lib/doctor/checks/project/quire-project.js +0 -38
- package/src/lib/doctor/checks/project/quire-project.test.js +0 -47
- package/src/lib/doctor/checks/tools/index.js +0 -10
- package/src/lib/doctor/checks/tools/pandoc-available.js +0 -82
- package/src/lib/doctor/checks/tools/pandoc-available.test.js +0 -73
- package/src/lib/doctor/checks/tools/prince-available.js +0 -81
- package/src/lib/doctor/checks/tools/prince-available.test.js +0 -73
- package/src/lib/doctor/constants.js +0 -39
- package/src/lib/doctor/formatDuration.js +0 -108
- package/src/lib/doctor/formatDuration.test.js +0 -76
- package/src/lib/doctor/formatters/human.js +0 -257
- package/src/lib/doctor/formatters/human.test.js +0 -463
- package/src/lib/doctor/formatters/index.js +0 -8
- package/src/lib/doctor/formatters/json.js +0 -78
- package/src/lib/doctor/formatters/json.test.js +0 -174
- package/src/lib/doctor/formatters/shared.js +0 -129
- package/src/lib/doctor/formatters/shared.test.js +0 -194
- package/src/lib/doctor/index.js +0 -271
- package/src/lib/doctor/index.test.js +0 -797
- package/src/lib/epub/engines.js +0 -46
- package/src/lib/epub/index.test.js +0 -518
- package/src/lib/epub/pandoc.test.js +0 -122
- package/src/lib/epub/schema.js +0 -21
- package/src/lib/error/README.md +0 -170
- package/src/lib/error/handler.js +0 -107
- package/src/lib/git/index.spec.js +0 -80
- package/src/lib/git/index.test.js +0 -453
- package/src/lib/help/frontmatter.js +0 -77
- package/src/lib/help/frontmatter.test.js +0 -139
- package/src/lib/help/index.js +0 -146
- package/src/lib/help/index.test.js +0 -188
- package/src/lib/help/topics/configuration.md +0 -77
- package/src/lib/help/topics/debugging.md +0 -69
- package/src/lib/help/topics/epub.md +0 -74
- package/src/lib/help/topics/pdf.md +0 -74
- package/src/lib/help/topics/publishing.md +0 -80
- package/src/lib/help/topics/workflows.md +0 -50
- package/src/lib/installer/index.js +0 -309
- package/src/lib/installer/index.spec.js +0 -83
- package/src/lib/installer/index.test.js +0 -545
- package/src/lib/logger/README.md +0 -424
- package/src/lib/logger/debug.js +0 -132
- package/src/lib/logger/debug.spec.js +0 -130
- package/src/lib/logger/debug.test.js +0 -128
- package/src/lib/logger/index.js +0 -228
- package/src/lib/logger/index.spec.js +0 -131
- package/src/lib/logger/index.test.js +0 -578
- package/src/lib/npm/README.md +0 -127
- package/src/lib/npm/index.js +0 -198
- package/src/lib/npm/index.spec.js +0 -60
- package/src/lib/npm/index.test.js +0 -355
- package/src/lib/pdf/engines.js +0 -46
- package/src/lib/pdf/index.test.js +0 -708
- package/src/lib/pdf/paged.test.js +0 -366
- package/src/lib/pdf/prince.test.js +0 -202
- package/src/lib/pdf/schema.js +0 -21
- package/src/lib/pdf/split.test.js +0 -445
- package/src/lib/platform.js +0 -95
- package/src/lib/process/manager.js +0 -110
- package/src/lib/process/manager.test.js +0 -55
- package/src/lib/project/build.js +0 -162
- package/src/lib/project/build.test.js +0 -275
- package/src/lib/project/config.js +0 -48
- package/src/lib/project/config.test.js +0 -134
- package/src/lib/project/detect.js +0 -47
- package/src/lib/project/detect.test.js +0 -157
- package/src/lib/project/index.js +0 -56
- package/src/lib/project/output-paths.js +0 -87
- package/src/lib/project/output-paths.test.js +0 -66
- package/src/lib/project/paths.js +0 -272
- package/src/lib/project/version.js +0 -110
- package/src/lib/project/version.test.js +0 -350
- package/src/lib/reporter/index.test.js +0 -862
- package/src/main.spec.js +0 -61
- package/src/main.test.js +0 -347
- package/src/validators/validate-data-files.js +0 -154
- package/src/validators/validate-data-files.test.js +0 -217
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for human-readable formatter
|
|
3
|
-
*/
|
|
4
|
-
import test from 'ava'
|
|
5
|
-
import { formatHuman } from './human.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', remediation: 'Upgrade Node.js', docsUrl: 'https://example.com' },
|
|
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
|
-
],
|
|
21
|
-
},
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
test('formatHuman returns lines array', (t) => {
|
|
25
|
-
const { lines } = formatHuman(mockSections)
|
|
26
|
-
t.true(Array.isArray(lines))
|
|
27
|
-
t.true(lines.length > 0)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
test('formatHuman lines have text and level properties', (t) => {
|
|
31
|
-
const { lines } = formatHuman(mockSections)
|
|
32
|
-
for (const line of lines) {
|
|
33
|
-
t.true(typeof line.text === 'string')
|
|
34
|
-
t.true(['info', 'warn', 'error'].includes(line.level))
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('formatHuman includes header with label', (t) => {
|
|
39
|
-
const { lines } = formatHuman(mockSections, { label: 'environment checks' })
|
|
40
|
-
const header = lines[0]
|
|
41
|
-
t.true(header.text.includes('Running environment checks'))
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('formatHuman header includes errors filter description', (t) => {
|
|
45
|
-
const { lines } = formatHuman(mockSections, { errors: true })
|
|
46
|
-
const header = lines.find((l) => l.text.includes('Running'))
|
|
47
|
-
t.truthy(header)
|
|
48
|
-
t.true(header.text.includes('(errors only)'))
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('formatHuman header includes warnings filter description', (t) => {
|
|
52
|
-
const { lines } = formatHuman(mockSections, { warnings: true })
|
|
53
|
-
const header = lines.find((l) => l.text.includes('Running'))
|
|
54
|
-
t.truthy(header)
|
|
55
|
-
t.true(header.text.includes('(warnings only)'))
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('formatHuman header includes combined filter description', (t) => {
|
|
59
|
-
const { lines } = formatHuman(mockSections, { errors: true, warnings: true })
|
|
60
|
-
const header = lines.find((l) => l.text.includes('Running'))
|
|
61
|
-
t.truthy(header)
|
|
62
|
-
t.true(header.text.includes('(warnings and errors only)'))
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('formatHuman header has no filter suffix without filters', (t) => {
|
|
66
|
-
const { lines } = formatHuman(mockSections)
|
|
67
|
-
const header = lines[0]
|
|
68
|
-
t.false(header.text.includes('only'))
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('formatHuman includes section names as headings', (t) => {
|
|
72
|
-
const { lines } = formatHuman(mockSections)
|
|
73
|
-
const envLine = lines.find((l) => l.text.includes('Environment') && !l.text.includes('Running'))
|
|
74
|
-
const projectLine = lines.find((l) => l.text.includes('Project'))
|
|
75
|
-
t.truthy(envLine)
|
|
76
|
-
t.truthy(projectLine)
|
|
77
|
-
// Section headings should be info level
|
|
78
|
-
t.is(envLine.level, 'info')
|
|
79
|
-
t.is(projectLine.level, 'info')
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('formatHuman includes check names and messages', (t) => {
|
|
83
|
-
const { lines } = formatHuman(mockSections)
|
|
84
|
-
const osLine = lines.find((l) => l.text.includes('Operating system'))
|
|
85
|
-
t.truthy(osLine)
|
|
86
|
-
t.true(osLine.text.includes('macOS 14'))
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
test('formatHuman returns summary with error count and N/A count', (t) => {
|
|
90
|
-
const { summary } = formatHuman(mockSections)
|
|
91
|
-
t.truthy(summary)
|
|
92
|
-
t.true(summary.text.includes('1 check failed'))
|
|
93
|
-
t.true(summary.text.includes('(1 not applicable)'))
|
|
94
|
-
t.is(summary.level, 'error')
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
test('formatHuman returns exitCode 1 when checks fail', (t) => {
|
|
98
|
-
const { exitCode } = formatHuman(mockSections)
|
|
99
|
-
t.is(exitCode, 1)
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
test('formatHuman returns exitCode 0 when all pass', (t) => {
|
|
103
|
-
const healthySections = [
|
|
104
|
-
{ section: 'Env', results: [{ id: 'os', name: 'OS', ok: true }] },
|
|
105
|
-
]
|
|
106
|
-
const { exitCode } = formatHuman(healthySections)
|
|
107
|
-
t.is(exitCode, 0)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
test('formatHuman includes remediation for failed checks', (t) => {
|
|
111
|
-
const { lines } = formatHuman(mockSections)
|
|
112
|
-
const remediationLine = lines.find((l) => l.text.includes('How to fix'))
|
|
113
|
-
t.truthy(remediationLine)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
test('formatHuman includes docsUrl for failed checks', (t) => {
|
|
117
|
-
const { lines } = formatHuman(mockSections)
|
|
118
|
-
const docsLine = lines.find((l) => l.text.includes('Documentation:'))
|
|
119
|
-
t.truthy(docsLine)
|
|
120
|
-
t.true(docsLine.text.includes('https://example.com'))
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
test('formatHuman with errors filter shows only failed', (t) => {
|
|
124
|
-
const { lines, isEmpty } = formatHuman(mockSections, { errors: true })
|
|
125
|
-
t.false(isEmpty)
|
|
126
|
-
// Should not include passed or warning checks
|
|
127
|
-
const osLine = lines.find((l) => l.text.includes('Operating system'))
|
|
128
|
-
t.falsy(osLine)
|
|
129
|
-
const nodeLine = lines.find((l) => l.text.includes('Node.js'))
|
|
130
|
-
t.truthy(nodeLine)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
test('formatHuman with warnings filter shows only warnings', (t) => {
|
|
134
|
-
const { lines, isEmpty } = formatHuman(mockSections, { warnings: true })
|
|
135
|
-
t.false(isEmpty)
|
|
136
|
-
const depsLine = lines.find((l) => l.text.includes('Dependencies'))
|
|
137
|
-
t.truthy(depsLine)
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
test('formatHuman with both errors and warnings shows failed and warnings', (t) => {
|
|
141
|
-
const { lines, isEmpty } = formatHuman(mockSections, { errors: true, warnings: true })
|
|
142
|
-
t.false(isEmpty)
|
|
143
|
-
// Should include failed check
|
|
144
|
-
const nodeLine = lines.find((l) => l.text.includes('Node.js'))
|
|
145
|
-
t.truthy(nodeLine)
|
|
146
|
-
// Should include warning check
|
|
147
|
-
const depsLine = lines.find((l) => l.text.includes('Dependencies'))
|
|
148
|
-
t.truthy(depsLine)
|
|
149
|
-
// Should not include passed checks
|
|
150
|
-
const osLine = lines.find((l) => l.text.includes('Operating system'))
|
|
151
|
-
t.falsy(osLine)
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
test('formatHuman summary reflects unfiltered counts when --errors filter is active', (t) => {
|
|
155
|
-
// mockSections has 1 error and 1 warning — --errors shows only the error
|
|
156
|
-
const { summary, exitCode } = formatHuman(mockSections, { errors: true })
|
|
157
|
-
t.truthy(summary)
|
|
158
|
-
t.true(summary.text.includes('1 check failed'))
|
|
159
|
-
t.is(exitCode, 1)
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
test('formatHuman summary reflects unfiltered counts when --warnings filter is active', (t) => {
|
|
163
|
-
// mockSections has 1 error and 1 warning — --warnings shows only the warning,
|
|
164
|
-
// but summary should still report the error
|
|
165
|
-
const { summary, exitCode } = formatHuman(mockSections, { warnings: true })
|
|
166
|
-
t.truthy(summary)
|
|
167
|
-
t.true(summary.text.includes('1 check failed'))
|
|
168
|
-
t.is(summary.level, 'error')
|
|
169
|
-
t.is(exitCode, 1)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
test('formatHuman returns isEmpty true when filter excludes all', (t) => {
|
|
173
|
-
const healthySections = [
|
|
174
|
-
{ section: 'Env', results: [{ id: 'os', name: 'OS', ok: true }] },
|
|
175
|
-
]
|
|
176
|
-
const { isEmpty, lines } = formatHuman(healthySections, { errors: true })
|
|
177
|
-
t.true(isEmpty)
|
|
178
|
-
t.true(lines[0].text.includes('No failed checks'))
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
test('formatHuman returns isEmpty with combined message when both filters exclude all', (t) => {
|
|
182
|
-
const healthySections = [
|
|
183
|
-
{ section: 'Env', results: [{ id: 'os', name: 'OS', ok: true }] },
|
|
184
|
-
]
|
|
185
|
-
const { isEmpty, lines } = formatHuman(healthySections, { errors: true, warnings: true })
|
|
186
|
-
t.true(isEmpty)
|
|
187
|
-
t.true(lines[0].text.includes('No failed checks or warnings'))
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
test('formatHuman isEmpty summary still reflects unfiltered status', (t) => {
|
|
191
|
-
// --warnings filter on sections with only an error → isEmpty, but summary shows the error
|
|
192
|
-
const errorSections = [
|
|
193
|
-
{
|
|
194
|
-
section: 'Outputs',
|
|
195
|
-
results: [
|
|
196
|
-
{ id: 'pdf', name: 'PDF', ok: false, message: 'Last PDF build failed' },
|
|
197
|
-
],
|
|
198
|
-
},
|
|
199
|
-
]
|
|
200
|
-
const { isEmpty, summary, exitCode } = formatHuman(errorSections, { warnings: true })
|
|
201
|
-
t.true(isEmpty)
|
|
202
|
-
t.truthy(summary)
|
|
203
|
-
t.true(summary.text.includes('1 check failed'))
|
|
204
|
-
t.is(summary.level, 'error')
|
|
205
|
-
t.is(exitCode, 1)
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
test('formatHuman returns key in default mode', (t) => {
|
|
209
|
-
const { key } = formatHuman(mockSections, {})
|
|
210
|
-
t.truthy(key)
|
|
211
|
-
t.true(key.text.includes('Key:'))
|
|
212
|
-
t.true(key.text.includes('passed'))
|
|
213
|
-
t.true(key.text.includes('failed'))
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
test('formatHuman returns key without verbose', (t) => {
|
|
217
|
-
const { key } = formatHuman(mockSections, { verbose: false })
|
|
218
|
-
t.truthy(key)
|
|
219
|
-
t.true(key.text.includes('Key:'))
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
test('formatHuman hides key when --errors filter is active', (t) => {
|
|
223
|
-
const { key } = formatHuman(mockSections, { errors: true })
|
|
224
|
-
t.is(key, null)
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
test('formatHuman hides key when --warnings filter is active', (t) => {
|
|
228
|
-
const { key } = formatHuman(mockSections, { warnings: true })
|
|
229
|
-
t.is(key, null)
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
test('formatHuman includes details in verbose mode', (t) => {
|
|
233
|
-
const sectionsWithDetails = [
|
|
234
|
-
{
|
|
235
|
-
section: 'Env',
|
|
236
|
-
results: [
|
|
237
|
-
{ id: 'os', name: 'OS', ok: true, message: 'macOS', details: '/usr/bin/sw_vers' },
|
|
238
|
-
],
|
|
239
|
-
},
|
|
240
|
-
]
|
|
241
|
-
const { lines } = formatHuman(sectionsWithDetails, { verbose: true })
|
|
242
|
-
const detailsLine = lines.find((l) => l.text.includes('/usr/bin/sw_vers'))
|
|
243
|
-
t.truthy(detailsLine)
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
test('formatHuman excludes details without verbose', (t) => {
|
|
247
|
-
const sectionsWithDetails = [
|
|
248
|
-
{
|
|
249
|
-
section: 'Env',
|
|
250
|
-
results: [
|
|
251
|
-
{ id: 'os', name: 'OS', ok: true, message: 'macOS', details: '/usr/bin/sw_vers' },
|
|
252
|
-
],
|
|
253
|
-
},
|
|
254
|
-
]
|
|
255
|
-
const { lines } = formatHuman(sectionsWithDetails, { verbose: false })
|
|
256
|
-
const detailsLine = lines.find((l) => l.text.includes('/usr/bin/sw_vers'))
|
|
257
|
-
t.falsy(detailsLine)
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
test('formatHuman assigns correct log levels to lines', (t) => {
|
|
261
|
-
const { lines } = formatHuman(mockSections)
|
|
262
|
-
// Failed check should have error level
|
|
263
|
-
const nodeLine = lines.find((l) => l.text.includes('Node.js'))
|
|
264
|
-
t.is(nodeLine.level, 'error')
|
|
265
|
-
// Warning check should have warn level
|
|
266
|
-
const depsLine = lines.find((l) => l.text.includes('Dependencies'))
|
|
267
|
-
t.is(depsLine.level, 'warn')
|
|
268
|
-
// Passed check should have info level
|
|
269
|
-
const osLine = lines.find((l) => l.text.includes('Operating system'))
|
|
270
|
-
t.is(osLine.level, 'info')
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
test('formatHuman handles timeout status', (t) => {
|
|
274
|
-
const sectionsWithTimeout = [
|
|
275
|
-
{
|
|
276
|
-
section: 'Env',
|
|
277
|
-
results: [
|
|
278
|
-
{ id: 'npm', name: 'npm', ok: false, level: 'timeout', message: 'Timed out' },
|
|
279
|
-
],
|
|
280
|
-
},
|
|
281
|
-
]
|
|
282
|
-
const { lines, summary } = formatHuman(sectionsWithTimeout)
|
|
283
|
-
const npmLine = lines.find((l) => l.text.includes('npm'))
|
|
284
|
-
t.truthy(npmLine)
|
|
285
|
-
t.is(npmLine.level, 'warn')
|
|
286
|
-
t.true(summary.text.includes('1 timed out'))
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
test('formatHuman summary shows warnings without errors', (t) => {
|
|
290
|
-
const warningSections = [
|
|
291
|
-
{
|
|
292
|
-
section: 'Project',
|
|
293
|
-
results: [
|
|
294
|
-
{ id: 'deps', name: 'Dependencies', ok: false, level: 'warn', message: 'Outdated' },
|
|
295
|
-
],
|
|
296
|
-
},
|
|
297
|
-
]
|
|
298
|
-
const { summary, exitCode } = formatHuman(warningSections)
|
|
299
|
-
t.true(summary.text.includes('All checks passed with 1 warning'))
|
|
300
|
-
t.is(summary.level, 'warn')
|
|
301
|
-
t.is(exitCode, 0)
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
305
|
-
// N/A count in summary
|
|
306
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
307
|
-
|
|
308
|
-
test('formatHuman summary includes N/A count when all checks pass', (t) => {
|
|
309
|
-
const sections = [
|
|
310
|
-
{
|
|
311
|
-
section: 'Outputs',
|
|
312
|
-
results: [
|
|
313
|
-
{ id: 'build', name: 'Build', ok: true, message: 'Up to date' },
|
|
314
|
-
{ id: 'pdf', name: 'PDF', ok: true, level: 'na', message: 'No PDF output' },
|
|
315
|
-
{ id: 'epub', name: 'EPUB', ok: true, level: 'na', message: 'No EPUB output' },
|
|
316
|
-
],
|
|
317
|
-
},
|
|
318
|
-
]
|
|
319
|
-
const { summary } = formatHuman(sections)
|
|
320
|
-
t.true(summary.text.includes('All checks passed!'))
|
|
321
|
-
t.true(summary.text.includes('(2 not applicable)'))
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
test('formatHuman summary includes N/A count with warnings', (t) => {
|
|
325
|
-
const sections = [
|
|
326
|
-
{
|
|
327
|
-
section: 'Outputs',
|
|
328
|
-
results: [
|
|
329
|
-
{ id: 'build', name: 'Build', ok: false, level: 'warn', message: 'Stale' },
|
|
330
|
-
{ id: 'pdf', name: 'PDF', ok: true, level: 'na', message: 'No PDF output' },
|
|
331
|
-
],
|
|
332
|
-
},
|
|
333
|
-
]
|
|
334
|
-
const { summary } = formatHuman(sections)
|
|
335
|
-
t.true(summary.text.includes('All checks passed with 1 warning'))
|
|
336
|
-
t.true(summary.text.includes('(1 not applicable)'))
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
test('formatHuman summary omits N/A count when none exist', (t) => {
|
|
340
|
-
const sections = [
|
|
341
|
-
{
|
|
342
|
-
section: 'Env',
|
|
343
|
-
results: [
|
|
344
|
-
{ id: 'os', name: 'OS', ok: true, message: 'macOS' },
|
|
345
|
-
],
|
|
346
|
-
},
|
|
347
|
-
]
|
|
348
|
-
const { summary } = formatHuman(sections)
|
|
349
|
-
t.true(summary.text.includes('All checks passed!'))
|
|
350
|
-
t.false(summary.text.includes('not applicable'))
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
test('formatHuman summary includes singular N/A count', (t) => {
|
|
354
|
-
const sections = [
|
|
355
|
-
{
|
|
356
|
-
section: 'Outputs',
|
|
357
|
-
results: [
|
|
358
|
-
{ id: 'build', name: 'Build', ok: true, message: 'Up to date' },
|
|
359
|
-
{ id: 'pdf', name: 'PDF', ok: true, level: 'na', message: 'No PDF output' },
|
|
360
|
-
],
|
|
361
|
-
},
|
|
362
|
-
]
|
|
363
|
-
const { summary } = formatHuman(sections)
|
|
364
|
-
t.true(summary.text.includes('(1 not applicable)'))
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
368
|
-
// Terminal width-aware wrapping
|
|
369
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
370
|
-
|
|
371
|
-
test('formatHuman wraps long remediation text to fit terminal width', (t) => {
|
|
372
|
-
const longRemediation = 'Install Node.js version 22 or later using your preferred package manager such as nvm, Homebrew, or download directly from the official Node.js website at nodejs.org'
|
|
373
|
-
const sections = [
|
|
374
|
-
{
|
|
375
|
-
section: 'Environment',
|
|
376
|
-
results: [
|
|
377
|
-
{ id: 'node', name: 'Node.js', ok: false, level: 'error', message: 'v18', remediation: longRemediation },
|
|
378
|
-
],
|
|
379
|
-
},
|
|
380
|
-
]
|
|
381
|
-
// Force narrow terminal (40 columns)
|
|
382
|
-
const { lines } = formatHuman(sections, { columns: 40 })
|
|
383
|
-
const checkLine = lines.find((l) => l.text.includes('How to fix'))
|
|
384
|
-
t.truthy(checkLine)
|
|
385
|
-
|
|
386
|
-
// The remediation text should be wrapped — each line should not exceed 40 chars
|
|
387
|
-
// (remediation is indented 4 spaces, so content width is 36)
|
|
388
|
-
const remediationLines = checkLine.text.split('\n').filter((l) => l.trim() && !l.includes('How to fix') && !l.includes('Node.js'))
|
|
389
|
-
for (const line of remediationLines) {
|
|
390
|
-
t.true(line.length <= 42, `line exceeds terminal width: "${line}" (${line.length} chars)`)
|
|
391
|
-
}
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
test('formatHuman wraps verbose details to fit terminal width', (t) => {
|
|
395
|
-
const longDetails = '/very/long/path/to/some/deeply/nested/directory/structure/that/exceeds/the/terminal/width/when/displayed/in/verbose/mode'
|
|
396
|
-
const sections = [
|
|
397
|
-
{
|
|
398
|
-
section: 'Environment',
|
|
399
|
-
results: [
|
|
400
|
-
{ id: 'node', name: 'Node.js', ok: true, message: 'v22', details: longDetails },
|
|
401
|
-
],
|
|
402
|
-
},
|
|
403
|
-
]
|
|
404
|
-
// Force narrow terminal (50 columns)
|
|
405
|
-
const { lines } = formatHuman(sections, { verbose: true, columns: 50 })
|
|
406
|
-
const checkLine = lines.find((l) => l.text.includes(longDetails.substring(0, 20)))
|
|
407
|
-
t.truthy(checkLine)
|
|
408
|
-
|
|
409
|
-
// Details are indented 6 spaces, so content width is 44
|
|
410
|
-
const detailLines = checkLine.text.split('\n').filter((l) => l.includes('/'))
|
|
411
|
-
for (const line of detailLines) {
|
|
412
|
-
t.true(line.length <= 52, `detail line exceeds terminal width: "${line}" (${line.length} chars)`)
|
|
413
|
-
}
|
|
414
|
-
})
|
|
415
|
-
|
|
416
|
-
test('formatHuman preserves remediation newlines when wrapping', (t) => {
|
|
417
|
-
const multiLineRemediation = 'Install Node.js 22 or later:\n • Run: nvm install 22\n • Or: brew install node@22'
|
|
418
|
-
const sections = [
|
|
419
|
-
{
|
|
420
|
-
section: 'Environment',
|
|
421
|
-
results: [
|
|
422
|
-
{ id: 'node', name: 'Node.js', ok: false, level: 'error', message: 'v18', remediation: multiLineRemediation },
|
|
423
|
-
],
|
|
424
|
-
},
|
|
425
|
-
]
|
|
426
|
-
const { lines } = formatHuman(sections, { columns: 80 })
|
|
427
|
-
const checkLine = lines.find((l) => l.text.includes('How to fix'))
|
|
428
|
-
t.truthy(checkLine)
|
|
429
|
-
// All three original lines should appear in the output
|
|
430
|
-
t.true(checkLine.text.includes('Install Node.js'))
|
|
431
|
-
t.true(checkLine.text.includes('nvm install'))
|
|
432
|
-
t.true(checkLine.text.includes('brew install'))
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
test('formatHuman applies default width when columns not specified', (t) => {
|
|
436
|
-
const sections = [
|
|
437
|
-
{
|
|
438
|
-
section: 'Environment',
|
|
439
|
-
results: [
|
|
440
|
-
{ id: 'node', name: 'Node.js', ok: false, level: 'error', message: 'v18', remediation: 'Upgrade' },
|
|
441
|
-
],
|
|
442
|
-
},
|
|
443
|
-
]
|
|
444
|
-
// Should not throw — uses getTerminalWidth() fallback
|
|
445
|
-
const { lines } = formatHuman(sections)
|
|
446
|
-
t.truthy(lines)
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
test('formatHuman enforces minimum content width of 20 for very narrow terminals', (t) => {
|
|
450
|
-
const sections = [
|
|
451
|
-
{
|
|
452
|
-
section: 'Environment',
|
|
453
|
-
results: [
|
|
454
|
-
{ id: 'node', name: 'Node.js', ok: false, level: 'error', message: 'v18', remediation: 'Install Node.js version 22 or later' },
|
|
455
|
-
],
|
|
456
|
-
},
|
|
457
|
-
]
|
|
458
|
-
// Extremely narrow terminal (10 columns) — should still produce output
|
|
459
|
-
const { lines } = formatHuman(sections, { columns: 10 })
|
|
460
|
-
const checkLine = lines.find((l) => l.text.includes('How to fix'))
|
|
461
|
-
t.truthy(checkLine)
|
|
462
|
-
t.true(checkLine.text.includes('Install'))
|
|
463
|
-
})
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON formatter for doctor check results
|
|
3
|
-
*
|
|
4
|
-
* Formats check results as machine-readable JSON for programmatic consumption.
|
|
5
|
-
*
|
|
6
|
-
* @module lib/doctor/formatters/json
|
|
7
|
-
*/
|
|
8
|
-
import { getStatus, countResults, filterResults } from './shared.js'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Format check results as JSON
|
|
12
|
-
*
|
|
13
|
-
* @param {Array} sections - Check results organized by section
|
|
14
|
-
* @param {Object} [options] - Formatting options
|
|
15
|
-
* @param {boolean} [options.errors] - Only include failed checks
|
|
16
|
-
* @param {boolean} [options.warnings] - Only include warning checks
|
|
17
|
-
* @param {boolean} [options.verbose] - Include additional details
|
|
18
|
-
* @returns {{json: string, exitCode: number}} Formatted JSON string and exit code
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { json, exitCode } = formatJson(sections, { verbose: true })
|
|
22
|
-
* console.log(json)
|
|
23
|
-
* process.exit(exitCode)
|
|
24
|
-
*/
|
|
25
|
-
export function formatJson(sections, options = {}) {
|
|
26
|
-
const filteredSections = filterResults(sections, options)
|
|
27
|
-
const counts = countResults(sections)
|
|
28
|
-
const allChecks = []
|
|
29
|
-
|
|
30
|
-
for (const { section, results } of filteredSections) {
|
|
31
|
-
for (const result of results) {
|
|
32
|
-
const status = getStatus(result)
|
|
33
|
-
|
|
34
|
-
// Build check object
|
|
35
|
-
const check = {
|
|
36
|
-
id: result.id,
|
|
37
|
-
name: result.name,
|
|
38
|
-
section,
|
|
39
|
-
status,
|
|
40
|
-
message: result.message || null,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Include verbose details if requested
|
|
44
|
-
if (options.verbose && result.details) {
|
|
45
|
-
check.details = result.details
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Include remediation for failed/warning/timeout checks
|
|
49
|
-
if (!result.ok && result.remediation) {
|
|
50
|
-
check.remediation = result.remediation
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!result.ok && result.docsUrl) {
|
|
54
|
-
check.docsUrl = result.docsUrl
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
allChecks.push(check)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Indicate active filters so consumers know results is a subset
|
|
62
|
-
const activeFilters = []
|
|
63
|
-
if (options.errors) activeFilters.push('errors')
|
|
64
|
-
if (options.warnings) activeFilters.push('warnings')
|
|
65
|
-
|
|
66
|
-
const output = {
|
|
67
|
-
summary: counts,
|
|
68
|
-
...(activeFilters.length > 0 && { filter: activeFilters }),
|
|
69
|
-
results: allChecks,
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
json: JSON.stringify(output, null, 2),
|
|
74
|
-
exitCode: counts.failed > 0 ? 1 : 0,
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default formatJson
|