@vizzly-testing/cli 0.20.0 → 0.20.1-beta.0

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 (72) hide show
  1. package/dist/api/client.js +134 -0
  2. package/dist/api/core.js +341 -0
  3. package/dist/api/endpoints.js +314 -0
  4. package/dist/api/index.js +19 -0
  5. package/dist/auth/client.js +91 -0
  6. package/dist/auth/core.js +176 -0
  7. package/dist/auth/index.js +30 -0
  8. package/dist/auth/operations.js +148 -0
  9. package/dist/cli.js +1 -1
  10. package/dist/commands/doctor.js +3 -3
  11. package/dist/commands/finalize.js +41 -15
  12. package/dist/commands/login.js +7 -6
  13. package/dist/commands/logout.js +4 -4
  14. package/dist/commands/project.js +5 -4
  15. package/dist/commands/run.js +158 -90
  16. package/dist/commands/status.js +22 -18
  17. package/dist/commands/tdd.js +105 -78
  18. package/dist/commands/upload.js +61 -26
  19. package/dist/commands/whoami.js +4 -4
  20. package/dist/config/core.js +438 -0
  21. package/dist/config/index.js +13 -0
  22. package/dist/config/operations.js +327 -0
  23. package/dist/index.js +1 -1
  24. package/dist/project/core.js +295 -0
  25. package/dist/project/index.js +13 -0
  26. package/dist/project/operations.js +393 -0
  27. package/dist/report-generator/core.js +315 -0
  28. package/dist/report-generator/index.js +8 -0
  29. package/dist/report-generator/operations.js +196 -0
  30. package/dist/reporter/reporter-bundle.iife.js +16 -16
  31. package/dist/screenshot-server/core.js +157 -0
  32. package/dist/screenshot-server/index.js +11 -0
  33. package/dist/screenshot-server/operations.js +183 -0
  34. package/dist/sdk/index.js +3 -2
  35. package/dist/server/handlers/api-handler.js +14 -5
  36. package/dist/server/handlers/tdd-handler.js +80 -48
  37. package/dist/server-manager/core.js +183 -0
  38. package/dist/server-manager/index.js +81 -0
  39. package/dist/server-manager/operations.js +208 -0
  40. package/dist/services/build-manager.js +2 -69
  41. package/dist/services/index.js +21 -48
  42. package/dist/services/screenshot-server.js +40 -74
  43. package/dist/services/server-manager.js +45 -80
  44. package/dist/services/static-report-generator.js +21 -163
  45. package/dist/services/test-runner.js +90 -250
  46. package/dist/services/uploader.js +56 -358
  47. package/dist/tdd/core/hotspot-coverage.js +112 -0
  48. package/dist/tdd/core/signature.js +101 -0
  49. package/dist/tdd/index.js +19 -0
  50. package/dist/tdd/metadata/baseline-metadata.js +103 -0
  51. package/dist/tdd/metadata/hotspot-metadata.js +93 -0
  52. package/dist/tdd/services/baseline-downloader.js +151 -0
  53. package/dist/tdd/services/baseline-manager.js +166 -0
  54. package/dist/tdd/services/comparison-service.js +230 -0
  55. package/dist/tdd/services/hotspot-service.js +71 -0
  56. package/dist/tdd/services/result-service.js +123 -0
  57. package/dist/tdd/tdd-service.js +1081 -0
  58. package/dist/test-runner/core.js +255 -0
  59. package/dist/test-runner/index.js +13 -0
  60. package/dist/test-runner/operations.js +483 -0
  61. package/dist/uploader/core.js +396 -0
  62. package/dist/uploader/index.js +11 -0
  63. package/dist/uploader/operations.js +412 -0
  64. package/package.json +7 -12
  65. package/dist/services/api-service.js +0 -412
  66. package/dist/services/auth-service.js +0 -226
  67. package/dist/services/config-service.js +0 -369
  68. package/dist/services/html-report-generator.js +0 -455
  69. package/dist/services/project-service.js +0 -326
  70. package/dist/services/report-generator/report.css +0 -411
  71. package/dist/services/report-generator/viewer.js +0 -102
  72. package/dist/services/tdd-service.js +0 -1437
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Test Runner Core - Pure functions for test execution logic
3
+ *
4
+ * No I/O, no side effects - just data transformations.
5
+ */
6
+
7
+ // ============================================================================
8
+ // Environment Building
9
+ // ============================================================================
10
+
11
+ /**
12
+ * Build environment variables for test process execution
13
+ * @param {Object} options - Options
14
+ * @param {number} options.port - Server port
15
+ * @param {string} options.buildId - Build ID
16
+ * @param {boolean} [options.setBaseline] - Whether to set baseline
17
+ * @param {Object} [options.baseEnv] - Base environment (defaults to process.env)
18
+ * @returns {Object} Environment variables object
19
+ */
20
+ export function buildTestEnv({
21
+ port,
22
+ buildId,
23
+ setBaseline = false,
24
+ baseEnv = process.env
25
+ }) {
26
+ return {
27
+ ...baseEnv,
28
+ VIZZLY_SERVER_URL: `http://localhost:${port}`,
29
+ VIZZLY_BUILD_ID: buildId,
30
+ VIZZLY_ENABLED: 'true',
31
+ VIZZLY_SET_BASELINE: setBaseline ? 'true' : 'false'
32
+ };
33
+ }
34
+
35
+ /**
36
+ * Build environment for disabled Vizzly (allowNoToken mode)
37
+ * @param {Object} [baseEnv] - Base environment (defaults to process.env)
38
+ * @returns {Object} Environment variables object
39
+ */
40
+ export function buildDisabledEnv(baseEnv = process.env) {
41
+ return {
42
+ ...baseEnv,
43
+ VIZZLY_ENABLED: 'false'
44
+ };
45
+ }
46
+
47
+ // ============================================================================
48
+ // Build Payload Building
49
+ // ============================================================================
50
+
51
+ /**
52
+ * Build API build payload from options
53
+ * @param {Object} options - Run options
54
+ * @param {Object} [comparisonConfig] - Comparison configuration (threshold, minClusterSize)
55
+ * @returns {Object} Build payload for API
56
+ */
57
+ export function buildApiBuildPayload(options, comparisonConfig = null) {
58
+ let payload = {
59
+ name: options.buildName || `Test Run ${new Date().toISOString()}`,
60
+ branch: options.branch || 'main',
61
+ environment: options.environment || 'test',
62
+ commit_sha: options.commit,
63
+ commit_message: options.message,
64
+ github_pull_request_number: options.pullRequestNumber,
65
+ parallel_id: options.parallelId
66
+ };
67
+
68
+ // Only include metadata if we have meaningful config to send
69
+ if (comparisonConfig?.threshold != null || comparisonConfig?.minClusterSize != null) {
70
+ payload.metadata = {
71
+ comparison: {
72
+ threshold: comparisonConfig.threshold,
73
+ minClusterSize: comparisonConfig.minClusterSize
74
+ }
75
+ };
76
+ }
77
+ return payload;
78
+ }
79
+
80
+ // ============================================================================
81
+ // Mode Determination
82
+ // ============================================================================
83
+
84
+ /**
85
+ * Determine if we should skip Vizzly integration entirely
86
+ * @param {Object} options - Options
87
+ * @param {boolean} options.allowNoToken - Whether to allow running without token
88
+ * @param {boolean} options.hasApiKey - Whether an API key is available
89
+ * @param {boolean} options.tdd - Whether in TDD mode
90
+ * @returns {boolean} True if Vizzly should be disabled
91
+ */
92
+ export function shouldDisableVizzly({
93
+ allowNoToken,
94
+ hasApiKey,
95
+ tdd
96
+ }) {
97
+ return allowNoToken && !hasApiKey && !tdd;
98
+ }
99
+
100
+ /**
101
+ * Determine build mode
102
+ * @param {boolean} tdd - Whether TDD mode is enabled
103
+ * @returns {'tdd'|'api'} Build mode
104
+ */
105
+ export function determineBuildMode(tdd) {
106
+ return tdd ? 'tdd' : 'api';
107
+ }
108
+
109
+ // ============================================================================
110
+ // Result Building
111
+ // ============================================================================
112
+
113
+ /**
114
+ * Build result object for disabled run (no Vizzly integration)
115
+ * @returns {Object} Result object
116
+ */
117
+ export function buildDisabledRunResult() {
118
+ return {
119
+ testsPassed: 1,
120
+ testsFailed: 0,
121
+ screenshotsCaptured: 0
122
+ };
123
+ }
124
+
125
+ /**
126
+ * Build final run result object
127
+ * @param {Object} options - Options
128
+ * @param {string|null} options.buildId - Build ID
129
+ * @param {string|null} options.buildUrl - Build URL
130
+ * @param {boolean} options.testSuccess - Whether tests passed
131
+ * @param {number} options.screenshotCount - Number of screenshots
132
+ * @param {Object|null} options.tddResults - TDD results (comparisons, etc.)
133
+ * @returns {Object} Final result object
134
+ */
135
+ export function buildRunResult({
136
+ buildId,
137
+ buildUrl,
138
+ testSuccess,
139
+ screenshotCount,
140
+ tddResults
141
+ }) {
142
+ return {
143
+ buildId,
144
+ url: buildUrl,
145
+ testsPassed: testSuccess ? 1 : 0,
146
+ testsFailed: testSuccess ? 0 : 1,
147
+ screenshotsCaptured: screenshotCount,
148
+ comparisons: tddResults?.comparisons || null,
149
+ failed: (tddResults?.failed || 0) > 0
150
+ };
151
+ }
152
+
153
+ // ============================================================================
154
+ // Validation
155
+ // ============================================================================
156
+
157
+ /**
158
+ * Validate test command is provided
159
+ * @param {string|undefined} testCommand - Test command to validate
160
+ * @returns {{ valid: boolean, error: string|null }}
161
+ */
162
+ export function validateTestCommand(testCommand) {
163
+ if (!testCommand) {
164
+ return {
165
+ valid: false,
166
+ error: 'No test command provided'
167
+ };
168
+ }
169
+ return {
170
+ valid: true,
171
+ error: null
172
+ };
173
+ }
174
+
175
+ /**
176
+ * Validate daemon mode requirements
177
+ * @param {Object} options - Options
178
+ * @param {boolean} options.tdd - Whether TDD mode is enabled
179
+ * @param {boolean} options.daemon - Whether daemon mode is enabled
180
+ * @returns {{ valid: boolean, error: string|null }}
181
+ */
182
+ export function validateDaemonMode({
183
+ tdd,
184
+ daemon
185
+ }) {
186
+ if (!tdd || !daemon) {
187
+ return {
188
+ valid: false,
189
+ error: 'Initialize method is only for TDD daemon mode'
190
+ };
191
+ }
192
+ return {
193
+ valid: true,
194
+ error: null
195
+ };
196
+ }
197
+
198
+ // ============================================================================
199
+ // Client Options Building
200
+ // ============================================================================
201
+
202
+ /**
203
+ * Build API client options from config
204
+ * @param {Object} config - Configuration object
205
+ * @returns {Object|null} Client options or null if no API key
206
+ */
207
+ export function buildClientOptions(config) {
208
+ if (!config?.apiKey) {
209
+ return null;
210
+ }
211
+ return {
212
+ baseUrl: config.apiUrl,
213
+ token: config.apiKey,
214
+ command: 'run'
215
+ };
216
+ }
217
+
218
+ /**
219
+ * Check if API key is available
220
+ * @param {Object} config - Configuration object
221
+ * @returns {boolean} Whether API key exists
222
+ */
223
+ export function hasApiKey(config) {
224
+ return Boolean(config?.apiKey);
225
+ }
226
+
227
+ // ============================================================================
228
+ // Spawn Options Building
229
+ // ============================================================================
230
+
231
+ /**
232
+ * Build spawn options for test command execution
233
+ * @param {Object} env - Environment variables
234
+ * @returns {Object} Spawn options
235
+ */
236
+ export function buildSpawnOptions(env) {
237
+ return {
238
+ env,
239
+ stdio: 'inherit',
240
+ shell: true
241
+ };
242
+ }
243
+
244
+ // ============================================================================
245
+ // Set Baseline Normalization
246
+ // ============================================================================
247
+
248
+ /**
249
+ * Normalize setBaseline option (handles both camelCase and kebab-case)
250
+ * @param {Object} options - Options object
251
+ * @returns {boolean} Whether to set baseline
252
+ */
253
+ export function normalizeSetBaseline(options) {
254
+ return Boolean(options?.setBaseline || options?.['set-baseline']);
255
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Test Runner Module - Public exports
3
+ *
4
+ * Provides functional test runner primitives:
5
+ * - core.js: Pure functions for building env, payloads, results
6
+ * - operations.js: Test execution operations with dependency injection
7
+ */
8
+
9
+ // Core pure functions
10
+ export { buildApiBuildPayload, buildClientOptions, buildDisabledEnv, buildDisabledRunResult, buildRunResult, buildSpawnOptions, buildTestEnv, determineBuildMode, hasApiKey, normalizeSetBaseline, shouldDisableVizzly, validateDaemonMode, validateTestCommand } from './core.js';
11
+
12
+ // Test runner operations (take dependencies as parameters)
13
+ export { cancelTests, createBuild, executeTestCommand, fetchBuildUrl, finalizeBuild, initializeDaemon, runTests } from './operations.js';