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

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,113 +0,0 @@
1
- import { Command, Option } from 'commander'
2
- import program from '#src/main.js'
3
- import test from 'ava'
4
-
5
- /**
6
- * Command Contract/Interface Tests
7
- *
8
- * Verifies the command's public API and Commander.js integration.
9
- * @see docs/testing-commands.md
10
- */
11
-
12
- test.before((t) => {
13
- // Get the registered command (from program.commands) once and share across all tests
14
- t.context.command = program.commands.find((cmd) => cmd.name() === 'build')
15
- })
16
-
17
- test('command is registered in CLI program', (t) => {
18
- const { command } = t.context
19
-
20
- t.truthy(command, 'command "build" should be registered in program')
21
- t.true(command instanceof Command, 'registered command should be Commander.js Command instance')
22
- })
23
-
24
- test('registered command has correct metadata', (t) => {
25
- const { command } = t.context
26
-
27
- t.is(command.name(), 'build')
28
- t.truthy(command.description())
29
- t.is(typeof command._actionHandler, 'function', 'command should have action handler')
30
- })
31
-
32
- test('registered command has no arguments', (t) => {
33
- const { command } = t.context
34
- const registeredArguments = command.registeredArguments
35
-
36
- t.is(registeredArguments.length, 0, 'build command should have no arguments')
37
- })
38
-
39
- test('registered command has correct options', (t) => {
40
- const { command } = t.context
41
-
42
- // Get all options
43
- const dryRunOption = command.options.find((opt) => opt.long === '--dry-run')
44
- const dryrunAlias = command.options.find((opt) => opt.long === '--dryrun')
45
- const quietOption = command.options.find((opt) => opt.long === '--quiet')
46
- const verboseOption = command.options.find((opt) => opt.long === '--verbose')
47
- const progressOption = command.options.find((opt) => opt.long === '--progress')
48
- const eleventyOption = command.options.find((opt) => opt.long === '--11ty')
49
- const debugOption = command.options.find((opt) => opt.long === '--debug')
50
-
51
- // Verify all options exist
52
- t.truthy(dryRunOption, '--dry-run option should exist')
53
- t.truthy(dryrunAlias, '--dryrun alias should exist')
54
- t.truthy(quietOption, '--quiet option should exist')
55
- t.truthy(verboseOption, '--verbose option should exist')
56
- t.truthy(progressOption, '--progress option should exist')
57
- t.truthy(eleventyOption, '--11ty option should exist')
58
- t.truthy(debugOption, '--debug option should exist')
59
-
60
- // Verify they are Option instances
61
- t.true(dryRunOption instanceof Option, '--dry-run should be Option instance')
62
- t.true(dryrunAlias instanceof Option, '--dryrun should be Option instance')
63
- t.true(quietOption instanceof Option, '--quiet should be Option instance')
64
- t.true(verboseOption instanceof Option, '--verbose should be Option instance')
65
- t.true(progressOption instanceof Option, '--progress should be Option instance')
66
- t.true(eleventyOption instanceof Option, '--11ty should be Option instance')
67
- t.true(debugOption instanceof Option, '--debug should be Option instance')
68
-
69
- // Verify option properties
70
- t.is(dryRunOption.long, '--dry-run')
71
- t.is(dryRunOption.short, '-d')
72
- t.truthy(dryRunOption.description)
73
-
74
- // --dryrun is a hidden alias for --dry-run
75
- t.is(dryrunAlias.long, '--dryrun')
76
- t.true(dryrunAlias.hidden, '--dryrun should be hidden from help')
77
-
78
- t.is(quietOption.long, '--quiet')
79
- t.is(quietOption.short, '-q')
80
- t.truthy(quietOption.description)
81
-
82
- t.is(verboseOption.long, '--verbose')
83
- t.is(verboseOption.short, '-v')
84
- t.truthy(verboseOption.description)
85
-
86
- // --progress is a hidden alias for --verbose
87
- t.is(progressOption.long, '--progress')
88
- t.truthy(progressOption.description)
89
- t.true(progressOption.hidden, '--progress should be hidden from help')
90
-
91
- t.is(eleventyOption.long, '--11ty')
92
- t.truthy(eleventyOption.description)
93
- t.true(eleventyOption.required, '--11ty should require a value')
94
-
95
- t.is(debugOption.long, '--debug')
96
- t.truthy(debugOption.description)
97
- t.false(debugOption.required, '--debug should not require a value')
98
- })
99
-
100
- test('command options are accessible via public API', (t) => {
101
- const { command } = t.context
102
-
103
- // Test that options can be accessed the way Commander.js does
104
- const optionNames = command.options.map((opt) => opt.long)
105
-
106
- t.true(optionNames.includes('--dry-run'))
107
- t.true(optionNames.includes('--dryrun'))
108
- t.true(optionNames.includes('--quiet'))
109
- t.true(optionNames.includes('--verbose'))
110
- t.true(optionNames.includes('--progress'))
111
- t.true(optionNames.includes('--11ty'))
112
- t.true(optionNames.includes('--debug'))
113
- })
@@ -1,397 +0,0 @@
1
- import test from 'ava'
2
- import { Volume, createFsFromVolume } from 'memfs'
3
- import sinon from 'sinon'
4
- import esmock from 'esmock'
5
-
6
- test.beforeEach((t) => {
7
- // Create sinon sandbox for mocking
8
- t.context.sandbox = sinon.createSandbox()
9
-
10
- // Create in-memory file system
11
- t.context.vol = new Volume()
12
- t.context.fs = createFsFromVolume(t.context.vol)
13
-
14
- // Setup mock directory structure
15
- t.context.vol.fromJSON({
16
- '/project/content/_data/config.yaml': 'title: Test Project',
17
- '/project/content/index.md': '# Quire Test Project',
18
- '/project/package.json': JSON.stringify({ name: 'test-project' })
19
- })
20
-
21
- t.context.projectRoot = '/project'
22
-
23
- // Create mock logger (no global console stubbing needed!)
24
- t.context.mockLogger = {
25
- info: t.context.sandbox.stub(),
26
- error: t.context.sandbox.stub(),
27
- debug: t.context.sandbox.stub(),
28
- log: t.context.sandbox.stub(),
29
- warn: t.context.sandbox.stub()
30
- }
31
-
32
- // Create mock reporter
33
- t.context.mockReporter = {
34
- configure: t.context.sandbox.stub().returnsThis(),
35
- start: t.context.sandbox.stub().returnsThis(),
36
- update: t.context.sandbox.stub().returnsThis(),
37
- succeed: t.context.sandbox.stub().returnsThis(),
38
- fail: t.context.sandbox.stub().returnsThis(),
39
- stop: t.context.sandbox.stub().returnsThis(),
40
- }
41
- })
42
-
43
- test.afterEach.always((t) => {
44
- // Restore all mocks
45
- t.context.sandbox.restore()
46
-
47
- // Clear in-memory file system
48
- t.context.vol.reset()
49
- })
50
-
51
- test('build command should call eleventy CLI with default options', async (t) => {
52
- const { sandbox, fs, mockLogger, mockReporter } = t.context
53
-
54
- // Mock eleventy CLI module
55
- const mockEleventyCli = {
56
- build: sandbox.stub().resolves({ exitCode: 0 })
57
- }
58
-
59
- // Mock eleventy API module
60
- const mockEleventyApi = {
61
- build: sandbox.stub().resolves()
62
- }
63
-
64
- // Mock clean helper
65
- const mockClean = sandbox.stub()
66
-
67
- // Mock testcwd helper
68
- const mockTestcwd = sandbox.stub()
69
-
70
- // Use esmock to replace imports
71
- const BuildCommand = await esmock('./build.js', {
72
- '#lib/11ty/index.js': {
73
- api: mockEleventyApi,
74
- cli: mockEleventyCli
75
- },
76
- '#lib/project/index.js': {
77
- default: {
78
- getProjectRoot: () => '/project',
79
- toObject: () => ({ output: '_site' })
80
- }
81
- },
82
- '#helpers/clean.js': {
83
- clean: mockClean
84
- },
85
- '#helpers/test-cwd.js': {
86
- default: mockTestcwd
87
- },
88
- '#lib/logger/index.js': {
89
- logger: mockLogger
90
- },
91
- '#lib/reporter/index.js': {
92
- default: mockReporter
93
- },
94
- 'fs-extra': fs
95
- })
96
-
97
- const command = new BuildCommand()
98
- command.name = sandbox.stub().returns('build')
99
- command.opts = sandbox.stub().returns({})
100
-
101
- // Run preAction
102
- command.preAction(command)
103
-
104
- // Run action with default options (uses cli by default)
105
- await command.action({ '11ty': 'cli' }, command)
106
-
107
- t.true(mockTestcwd.called, 'testcwd should be called in preAction')
108
- t.true(mockClean.called, 'clean should be called in preAction')
109
- t.false(mockEleventyApi.build.called, 'eleventy API build should not be called')
110
- t.true(mockEleventyCli.build.called, 'eleventy CLI build should be called')
111
- })
112
-
113
- test('build command should call eleventy API when 11ty option is "api"', async (t) => {
114
- const { sandbox, fs, mockLogger, mockReporter } = t.context
115
-
116
- // Mock eleventy CLI module
117
- const mockEleventyCli = {
118
- build: sandbox.stub().resolves({ exitCode: 0 })
119
- }
120
-
121
- // Mock eleventy API module
122
- const mockEleventyApi = {
123
- build: sandbox.stub().resolves()
124
- }
125
-
126
- // Mock clean helper
127
- const mockClean = sandbox.stub()
128
-
129
- // Mock testcwd helper
130
- const mockTestcwd = sandbox.stub()
131
-
132
- // Use esmock to replace imports
133
- const BuildCommand = await esmock('./build.js', {
134
- '#lib/11ty/index.js': {
135
- cli: mockEleventyCli,
136
- api: mockEleventyApi
137
- },
138
- '#lib/project/index.js': {
139
- default: {
140
- getProjectRoot: () => '/project',
141
- toObject: () => ({ output: '_site' })
142
- }
143
- },
144
- '#helpers/clean.js': {
145
- clean: mockClean
146
- },
147
- '#helpers/test-cwd.js': {
148
- default: mockTestcwd
149
- },
150
- '#lib/logger/index.js': {
151
- logger: mockLogger
152
- },
153
- '#lib/reporter/index.js': {
154
- default: mockReporter
155
- },
156
- 'fs-extra': fs
157
- })
158
-
159
- const command = new BuildCommand()
160
- command.name = sandbox.stub().returns('build')
161
-
162
- // Run action with api option
163
- await command.action({ '11ty': 'api' }, command)
164
-
165
- t.false(mockEleventyCli.build.called, 'eleventy CLI build should not be called')
166
- t.true(mockEleventyApi.build.called, 'eleventy API build should be called')
167
- })
168
-
169
- test('build command should call clean with correct parameters in preAction', async (t) => {
170
- const { sandbox, fs, mockLogger, mockReporter } = t.context
171
-
172
- // Mock eleventy modules
173
- const mockEleventyCli = {
174
- build: sandbox.stub().resolves({ exitCode: 0 })
175
- }
176
-
177
- const mockEleventyApi = {
178
- build: sandbox.stub().resolves()
179
- }
180
-
181
- // Mock clean helper
182
- const mockClean = sandbox.stub()
183
-
184
- // Mock testcwd helper
185
- const mockTestcwd = sandbox.stub()
186
-
187
- // Use esmock to replace imports
188
- const BuildCommand = await esmock('./build.js', {
189
- '#lib/11ty/index.js': {
190
- cli: mockEleventyCli,
191
- api: mockEleventyApi
192
- },
193
- '#lib/project/index.js': {
194
- default: {
195
- getProjectRoot: () => '/project',
196
- toObject: () => ({ output: '_site' })
197
- }
198
- },
199
- '#helpers/clean.js': {
200
- clean: mockClean
201
- },
202
- '#helpers/test-cwd.js': {
203
- default: mockTestcwd
204
- },
205
- '#lib/logger/index.js': {
206
- logger: mockLogger
207
- },
208
- '#lib/reporter/index.js': {
209
- default: mockReporter
210
- },
211
- 'fs-extra': fs
212
- })
213
-
214
- const command = new BuildCommand()
215
- command.name = sandbox.stub().returns('build')
216
- const options = { verbose: true }
217
- command.opts = sandbox.stub().returns(options)
218
-
219
- // Run preAction
220
- command.preAction(command)
221
-
222
- t.true(mockClean.called, 'clean should be called')
223
- t.true(mockClean.calledWith('/project', { output: '_site' }, options), 'clean should be called with correct parameters')
224
- })
225
-
226
- test('build command should pass options to eleventy build', async (t) => {
227
- const { sandbox, fs, mockLogger, mockReporter } = t.context
228
-
229
- // Mock eleventy CLI module
230
- const mockEleventyCli = {
231
- build: sandbox.stub().resolves({ exitCode: 0 })
232
- }
233
-
234
- // Mock eleventy API module
235
- const mockEleventyApi = {
236
- build: sandbox.stub().resolves()
237
- }
238
-
239
- // Mock clean helper
240
- const mockClean = sandbox.stub()
241
-
242
- // Mock testcwd helper
243
- const mockTestcwd = sandbox.stub()
244
-
245
- // Use esmock to replace imports
246
- const BuildCommand = await esmock('./build.js', {
247
- '#lib/11ty/index.js': {
248
- cli: mockEleventyCli,
249
- api: mockEleventyApi
250
- },
251
- '#lib/project/index.js': {
252
- default: {
253
- getProjectRoot: () => '/project',
254
- toObject: () => ({ output: '_site' })
255
- }
256
- },
257
- '#helpers/clean.js': {
258
- clean: mockClean
259
- },
260
- '#helpers/test-cwd.js': {
261
- default: mockTestcwd
262
- },
263
- '#lib/logger/index.js': {
264
- logger: mockLogger
265
- },
266
- '#lib/reporter/index.js': {
267
- default: mockReporter
268
- },
269
- 'fs-extra': fs
270
- })
271
-
272
- const command = new BuildCommand()
273
- command.name = sandbox.stub().returns('build')
274
-
275
- const options = { '11ty': 'cli', verbose: true, quiet: false }
276
-
277
- // Run action with options
278
- await command.action(options, command)
279
-
280
- t.true(mockEleventyCli.build.calledWith(options), 'eleventy CLI build should be called with options')
281
- })
282
-
283
- test('build command should propagate errors from eleventy build', async (t) => {
284
- const { sandbox, fs, mockLogger, mockReporter } = t.context
285
-
286
- const buildError = new Error('Build failed')
287
-
288
- // Mock eleventy API module to throw error
289
- const mockEleventyApi = {
290
- build: sandbox.stub().rejects(buildError)
291
- }
292
-
293
- // Mock eleventy CLI module
294
- const mockEleventyCli = {
295
- build: sandbox.stub().resolves({ exitCode: 0 })
296
- }
297
-
298
- // Mock clean helper
299
- const mockClean = sandbox.stub()
300
-
301
- // Mock testcwd helper
302
- const mockTestcwd = sandbox.stub()
303
-
304
- // Use esmock to replace imports
305
- const BuildCommand = await esmock('./build.js', {
306
- '#lib/11ty/index.js': {
307
- api: mockEleventyApi,
308
- cli: mockEleventyCli
309
- },
310
- '#lib/project/index.js': {
311
- default: {
312
- getProjectRoot: () => '/project',
313
- toObject: () => ({ output: '_site' })
314
- }
315
- },
316
- '#helpers/clean.js': {
317
- clean: mockClean
318
- },
319
- '#helpers/test-cwd.js': {
320
- default: mockTestcwd
321
- },
322
- '#lib/logger/index.js': {
323
- logger: mockLogger
324
- },
325
- '#lib/reporter/index.js': {
326
- default: mockReporter
327
- },
328
- 'fs-extra': fs
329
- })
330
-
331
- const command = new BuildCommand()
332
- command.name = sandbox.stub().returns('build')
333
-
334
- // Run action and expect it to throw
335
- // Nota bene: reporter.start/succeed/fail are called by the lib layer, not the command
336
- await t.throwsAsync(() => command.action({ '11ty': 'api' }, command), { message: 'Build failed' })
337
- })
338
-
339
- test('build command should configure reporter with quiet option', async (t) => {
340
- const { sandbox, fs, mockLogger, mockReporter } = t.context
341
-
342
- // Mock eleventy CLI module
343
- const mockEleventyCli = {
344
- build: sandbox.stub().resolves({ exitCode: 0 })
345
- }
346
-
347
- // Mock eleventy API module
348
- const mockEleventyApi = {
349
- build: sandbox.stub().resolves()
350
- }
351
-
352
- // Mock clean helper
353
- const mockClean = sandbox.stub()
354
-
355
- // Mock testcwd helper
356
- const mockTestcwd = sandbox.stub()
357
-
358
- // Use esmock to replace imports
359
- const BuildCommand = await esmock('./build.js', {
360
- '#lib/11ty/index.js': {
361
- cli: mockEleventyCli,
362
- api: mockEleventyApi
363
- },
364
- '#lib/project/index.js': {
365
- default: {
366
- getProjectRoot: () => '/project',
367
- toObject: () => ({ output: '_site' })
368
- }
369
- },
370
- '#helpers/clean.js': {
371
- clean: mockClean
372
- },
373
- '#helpers/test-cwd.js': {
374
- default: mockTestcwd
375
- },
376
- '#lib/logger/index.js': {
377
- logger: mockLogger
378
- },
379
- '#lib/reporter/index.js': {
380
- default: mockReporter
381
- },
382
- 'fs-extra': fs
383
- })
384
-
385
- const command = new BuildCommand()
386
- command.name = sandbox.stub().returns('build')
387
-
388
- const options = { '11ty': 'api', quiet: true }
389
-
390
- // Run action with quiet option
391
- await command.action(options, command)
392
-
393
- t.true(
394
- mockReporter.configure.calledWith(sinon.match({ quiet: true })),
395
- 'reporter.configure should be called with quiet option'
396
- )
397
- })
@@ -1,118 +0,0 @@
1
- import { Command, Option } from 'commander'
2
- import program from '#src/main.js'
3
- import test from 'ava'
4
-
5
- /**
6
- * Command Contract/Interface Tests
7
- *
8
- * Verifies the command's public API and Commander.js integration.
9
- * @see docs/testing-commands.md
10
- */
11
-
12
- test.before((t) => {
13
- // Get the registered command (from program.commands) once and share across all tests
14
- t.context.command = program.commands.find((cmd) => cmd.name() === 'clean')
15
- })
16
-
17
- test('command is registered in CLI program', (t) => {
18
- const { command } = t.context
19
-
20
- t.truthy(command, 'command "clean" should be registered in program')
21
- t.true(command instanceof Command, 'registered command should be Commander.js Command instance')
22
- })
23
-
24
- test('registered command has correct metadata', (t) => {
25
- const { command } = t.context
26
-
27
- t.is(command.name(), 'clean')
28
- t.truthy(command.description())
29
- t.is(typeof command._actionHandler, 'function', 'command should have action handler')
30
- })
31
-
32
- test('registered command has no arguments', (t) => {
33
- const { command } = t.context
34
- const registeredArguments = command.registeredArguments
35
-
36
- t.is(registeredArguments.length, 0, 'clean command should have no arguments')
37
- })
38
-
39
- test('registered command has correct options', (t) => {
40
- const { command } = t.context
41
-
42
- // Get all options
43
- const dryRunOption = command.options.find((opt) => opt.long === '--dry-run')
44
- const dryrunAlias = command.options.find((opt) => opt.long === '--dryrun')
45
- const statusOption = command.options.find((opt) => opt.long === '--status')
46
- const progressOption = command.options.find((opt) => opt.long === '--progress')
47
- const quietOption = command.options.find((opt) => opt.long === '--quiet')
48
- const verboseOption = command.options.find((opt) => opt.long === '--verbose')
49
- const debugOption = command.options.find((opt) => opt.long === '--debug')
50
-
51
- // Verify all options exist
52
- t.truthy(dryRunOption, '--dry-run option should exist')
53
- t.truthy(dryrunAlias, '--dryrun alias should exist')
54
- t.truthy(statusOption, '--status option should exist')
55
- t.truthy(progressOption, '--progress option should exist')
56
- t.truthy(quietOption, '--quiet option should exist')
57
- t.truthy(verboseOption, '--verbose option should exist')
58
- t.truthy(debugOption, '--debug option should exist')
59
-
60
- // Verify they are Option instances
61
- t.true(dryRunOption instanceof Option, '--dry-run should be Option instance')
62
- t.true(dryrunAlias instanceof Option, '--dryrun should be Option instance')
63
- t.true(statusOption instanceof Option, '--status should be Option instance')
64
- t.true(progressOption instanceof Option, '--progress should be Option instance')
65
- t.true(quietOption instanceof Option, '--quiet should be Option instance')
66
- t.true(verboseOption instanceof Option, '--verbose should be Option instance')
67
- t.true(debugOption instanceof Option, '--debug should be Option instance')
68
-
69
- // Verify option properties
70
- t.is(dryRunOption.long, '--dry-run')
71
- t.is(dryRunOption.short, '-d')
72
- t.truthy(dryRunOption.description)
73
- t.false(dryRunOption.required, '--dry-run should not require a value')
74
-
75
- // --dryrun is a hidden alias for --dry-run
76
- t.is(dryrunAlias.long, '--dryrun')
77
- t.true(dryrunAlias.hidden, '--dryrun should be hidden from help')
78
-
79
- // --status clears stored build status
80
- t.is(statusOption.long, '--status')
81
- t.falsy(statusOption.short, '--status should not have a short flag')
82
- t.truthy(statusOption.description)
83
- t.false(statusOption.required, '--status should not require a value')
84
-
85
- // --progress is a hidden alias for --verbose
86
- t.is(progressOption.long, '--progress')
87
- t.truthy(progressOption.description)
88
- t.true(progressOption.hidden, '--progress should be hidden from help')
89
-
90
- t.is(quietOption.long, '--quiet')
91
- t.is(quietOption.short, '-q')
92
- t.truthy(quietOption.description)
93
- t.false(quietOption.required, '--quiet should not require a value')
94
-
95
- t.is(verboseOption.long, '--verbose')
96
- t.is(verboseOption.short, '-v')
97
- t.truthy(verboseOption.description)
98
- t.false(verboseOption.required, '--verbose should not require a value')
99
-
100
- t.is(debugOption.long, '--debug')
101
- t.truthy(debugOption.description)
102
- t.false(debugOption.required, '--debug should not require a value')
103
- })
104
-
105
- test('command options are accessible via public API', (t) => {
106
- const { command } = t.context
107
-
108
- // Test that options can be accessed the way Commander.js does
109
- const optionNames = command.options.map((opt) => opt.long)
110
-
111
- t.true(optionNames.includes('--dry-run'))
112
- t.true(optionNames.includes('--dryrun'))
113
- t.true(optionNames.includes('--status'))
114
- t.true(optionNames.includes('--progress'))
115
- t.true(optionNames.includes('--quiet'))
116
- t.true(optionNames.includes('--verbose'))
117
- t.true(optionNames.includes('--debug'))
118
- })