@vizzly-testing/cli 0.3.2 → 0.5.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 (60) hide show
  1. package/README.md +50 -28
  2. package/dist/cli.js +34 -30
  3. package/dist/client/index.js +1 -1
  4. package/dist/commands/run.js +38 -11
  5. package/dist/commands/tdd.js +30 -18
  6. package/dist/commands/upload.js +56 -5
  7. package/dist/server/handlers/api-handler.js +83 -0
  8. package/dist/server/handlers/tdd-handler.js +138 -0
  9. package/dist/server/http-server.js +132 -0
  10. package/dist/services/api-service.js +22 -2
  11. package/dist/services/server-manager.js +45 -29
  12. package/dist/services/test-runner.js +66 -69
  13. package/dist/services/uploader.js +11 -4
  14. package/dist/types/commands/run.d.ts +4 -1
  15. package/dist/types/commands/tdd.d.ts +5 -1
  16. package/dist/types/sdk/index.d.ts +6 -6
  17. package/dist/types/server/handlers/api-handler.d.ts +49 -0
  18. package/dist/types/server/handlers/tdd-handler.d.ts +85 -0
  19. package/dist/types/server/http-server.d.ts +5 -0
  20. package/dist/types/services/api-service.d.ts +1 -0
  21. package/dist/types/services/server-manager.d.ts +148 -3
  22. package/dist/types/services/test-runner.d.ts +1 -0
  23. package/dist/types/services/uploader.d.ts +2 -1
  24. package/dist/types/utils/ci-env.d.ts +55 -0
  25. package/dist/types/utils/config-helpers.d.ts +1 -1
  26. package/dist/types/utils/console-ui.d.ts +1 -1
  27. package/dist/types/utils/git.d.ts +12 -0
  28. package/dist/utils/ci-env.js +293 -0
  29. package/dist/utils/console-ui.js +4 -14
  30. package/dist/utils/git.js +38 -0
  31. package/docs/api-reference.md +17 -5
  32. package/docs/getting-started.md +1 -1
  33. package/docs/tdd-mode.md +9 -9
  34. package/docs/test-integration.md +9 -17
  35. package/docs/upload-command.md +7 -0
  36. package/package.json +4 -5
  37. package/dist/screenshot-wrapper.js +0 -68
  38. package/dist/server/index.js +0 -522
  39. package/dist/services/service-utils.js +0 -171
  40. package/dist/types/index.js +0 -153
  41. package/dist/types/screenshot-wrapper.d.ts +0 -27
  42. package/dist/types/server/index.d.ts +0 -38
  43. package/dist/types/services/service-utils.d.ts +0 -45
  44. package/dist/types/types/index.d.ts +0 -373
  45. package/dist/types/utils/diagnostics.d.ts +0 -69
  46. package/dist/types/utils/error-messages.d.ts +0 -42
  47. package/dist/types/utils/framework-detector.d.ts +0 -5
  48. package/dist/types/utils/help.d.ts +0 -11
  49. package/dist/types/utils/image-comparison.d.ts +0 -42
  50. package/dist/types/utils/package.d.ts +0 -1
  51. package/dist/types/utils/project-detection.d.ts +0 -19
  52. package/dist/types/utils/ui-helpers.d.ts +0 -23
  53. package/dist/utils/diagnostics.js +0 -184
  54. package/dist/utils/error-messages.js +0 -34
  55. package/dist/utils/framework-detector.js +0 -40
  56. package/dist/utils/help.js +0 -66
  57. package/dist/utils/image-comparison.js +0 -172
  58. package/dist/utils/package.js +0 -9
  59. package/dist/utils/project-detection.js +0 -145
  60. package/dist/utils/ui-helpers.js +0 -86
@@ -1,171 +0,0 @@
1
- /**
2
- * Service Utilities
3
- *
4
- * Provides utilities for service composition using higher-order functions
5
- * and event-based architecture patterns.
6
- */
7
-
8
- import { EventEmitter } from 'events';
9
-
10
- /**
11
- * Create an event emitter with enhanced functionality
12
- * @returns {EventEmitter} Enhanced event emitter
13
- */
14
- export function createEventEmitter() {
15
- const emitter = new EventEmitter();
16
-
17
- // Add helper methods
18
- emitter.emitProgress = (stage, message, data = {}) => {
19
- const progressData = {
20
- stage,
21
- message,
22
- timestamp: new Date().toISOString(),
23
- ...data
24
- };
25
- emitter.emit('progress', progressData);
26
- };
27
- emitter.emitError = (error, context = {}) => {
28
- emitter.emit('error', {
29
- error: error.message,
30
- stack: error.stack,
31
- context,
32
- timestamp: new Date().toISOString()
33
- });
34
- };
35
- return emitter;
36
- }
37
-
38
- /**
39
- * Create a cleanup manager
40
- * @returns {Object} Cleanup manager with add/execute methods
41
- */
42
- export function createCleanupManager() {
43
- const cleanupFunctions = [];
44
- return {
45
- add: fn => cleanupFunctions.push(fn),
46
- execute: async () => {
47
- for (const fn of cleanupFunctions) {
48
- try {
49
- await fn();
50
- } catch (error) {
51
- console.error('Cleanup error:', error);
52
- }
53
- }
54
- cleanupFunctions.length = 0;
55
- }
56
- };
57
- }
58
-
59
- /**
60
- * Create signal handlers for graceful shutdown
61
- * @param {Function} onSignal - Function to call on signal
62
- * @returns {Function} Cleanup function to remove handlers
63
- */
64
- export function createSignalHandlers(onSignal) {
65
- const handleSignal = async signal => {
66
- await onSignal(signal);
67
- process.exit(signal === 'SIGINT' ? 130 : 1);
68
- };
69
- process.once('SIGINT', () => handleSignal('SIGINT'));
70
- process.once('SIGTERM', () => handleSignal('SIGTERM'));
71
- return () => {
72
- process.removeAllListeners('SIGINT');
73
- process.removeAllListeners('SIGTERM');
74
- };
75
- }
76
-
77
- /**
78
- * Higher-order function to add error handling to any function
79
- * @param {Function} fn - Function to wrap
80
- * @param {Object} options - Error handling options
81
- * @returns {Function} Wrapped function with error handling
82
- */
83
- export function withErrorHandling(fn, options = {}) {
84
- return async (...args) => {
85
- try {
86
- return await fn(...args);
87
- } catch (error) {
88
- if (options.onError) {
89
- options.onError(error);
90
- }
91
- if (options.rethrow !== false) {
92
- throw error;
93
- }
94
- return options.defaultReturn;
95
- }
96
- };
97
- }
98
-
99
- /**
100
- * Higher-order function to add logging to any function
101
- * @param {Function} fn - Function to wrap
102
- * @param {Object} logger - Logger instance
103
- * @param {string} operation - Operation name for logging
104
- * @returns {Function} Wrapped function with logging
105
- */
106
- export function withLogging(fn, logger, operation) {
107
- return async (...args) => {
108
- logger.debug(`Starting ${operation}`);
109
- const start = Date.now();
110
- try {
111
- const result = await fn(...args);
112
- const duration = Date.now() - start;
113
- logger.debug(`Completed ${operation} in ${duration}ms`);
114
- return result;
115
- } catch (error) {
116
- const duration = Date.now() - start;
117
- logger.error(`Failed ${operation} after ${duration}ms:`, error.message);
118
- throw error;
119
- }
120
- };
121
- }
122
-
123
- /**
124
- * Compose multiple functions together
125
- * @param {...Function} fns - Functions to compose
126
- * @returns {Function} Composed function
127
- */
128
- export function compose(...fns) {
129
- return value => fns.reduceRight((acc, fn) => fn(acc), value);
130
- }
131
-
132
- /**
133
- * Create a service context with shared functionality
134
- * @param {Object} config - Service configuration
135
- * @param {Object} options - Service options
136
- * @returns {Object} Service context
137
- */
138
- export function createServiceContext(config, options = {}) {
139
- const emitter = createEventEmitter(options);
140
- const cleanup = createCleanupManager();
141
- let isRunning = false;
142
- const context = {
143
- config,
144
- emitter,
145
- cleanup,
146
- get isRunning() {
147
- return isRunning;
148
- },
149
- set isRunning(value) {
150
- isRunning = value;
151
- },
152
- // Convenience methods
153
- emitProgress: emitter.emitProgress,
154
- emitError: emitter.emitError,
155
- emit: emitter.emit.bind(emitter),
156
- on: emitter.on.bind(emitter),
157
- off: emitter.off.bind(emitter),
158
- once: emitter.once.bind(emitter),
159
- // Signal handling
160
- setupSignalHandlers: () => {
161
- const removeHandlers = createSignalHandlers(async signal => {
162
- if (isRunning) {
163
- emitter.emitProgress('cleanup', `Received ${signal}, cleaning up...`);
164
- await cleanup.execute();
165
- }
166
- });
167
- cleanup.add(removeHandlers);
168
- }
169
- };
170
- return context;
171
- }
@@ -1,153 +0,0 @@
1
- /**
2
- * @fileoverview Vizzly CLI type definitions
3
- * Comprehensive JSDoc type definitions for IDE support
4
- */
5
-
6
- /**
7
- * @typedef {Object} VizzlyConfig
8
- * @property {string} [apiKey] - API key for authentication
9
- * @property {string} [apiUrl='https://vizzly.dev'] - API base URL
10
- * @property {ServerConfig} [server] - Server configuration
11
- * @property {BuildConfig} [build] - Build configuration
12
- * @property {UploadConfig} [upload] - Upload configuration
13
- * @property {ComparisonConfig} [comparison] - Comparison configuration
14
- */
15
-
16
- /**
17
- * @typedef {Object} ServerConfig
18
- * @property {number} [port=3001] - Server port
19
- * @property {string} [host='localhost'] - Server host
20
- * @property {boolean} [https=false] - Use HTTPS
21
- * @property {string} [certPath] - Path to SSL certificate
22
- * @property {string} [keyPath] - Path to SSL key
23
- * @property {string} [screenshotPath='/screenshot'] - Screenshot POST endpoint path
24
- */
25
-
26
- /**
27
- * @typedef {Object} BuildConfig
28
- * @property {string} [name] - Build name
29
- * @property {string} [branch] - Git branch
30
- * @property {string} [commit] - Git commit SHA
31
- * @property {string} [message] - Commit message
32
- * @property {string} [environment='production'] - Environment name
33
- * @property {Object.<string, any>} [metadata] - Additional metadata
34
- */
35
-
36
- /**
37
- * @typedef {Object} UploadConfig
38
- * @property {string} [screenshotsDir='screenshots'] - Directory containing screenshots
39
- * @property {number} [batchSize=50] - Upload batch size
40
- * @property {number} [timeout=300000] - Upload timeout in ms
41
- * @property {number} [retries=3] - Number of retries
42
- * @property {boolean} [deduplication=true] - Enable deduplication
43
- */
44
-
45
- /**
46
- * @typedef {Object} ComparisonConfig
47
- * @property {number} [threshold=0.1] - Default comparison threshold (0-1)
48
- * @property {boolean} [ignoreAntialiasing=true] - Ignore antialiasing differences
49
- * @property {boolean} [ignoreColors=false] - Ignore color differences
50
- * @property {string} [diffColor='#ff0000'] - Color for diff highlighting
51
- */
52
-
53
- /**
54
- * @typedef {Object} Screenshot
55
- * @property {string} name - Screenshot name
56
- * @property {Buffer} image - Image buffer data
57
- * @property {Object.<string, any>} [properties] - Additional properties
58
- * @property {number} [threshold] - Comparison threshold override
59
- * @property {string} [group] - Screenshot group/category
60
- * @property {string[]} [tags] - Screenshot tags
61
- */
62
-
63
- /**
64
- * @typedef {Object} UploadOptions
65
- * @property {string} screenshotsDir - Directory containing screenshots
66
- * @property {string} [buildName] - Name for this build
67
- * @property {string} [branch] - Git branch name
68
- * @property {string} [commit] - Git commit SHA
69
- * @property {string} [message] - Commit message
70
- * @property {string} [environment='production'] - Environment name
71
- * @property {number} [threshold] - Default comparison threshold
72
- * @property {ProgressCallback} [onProgress] - Progress callback
73
- */
74
-
75
- /**
76
- * @typedef {Object} UploadResult
77
- * @property {boolean} success - Whether upload succeeded
78
- * @property {string} [buildId] - Build ID if successful
79
- * @property {string} [url] - Build URL if available
80
- * @property {UploadStats} stats - Upload statistics
81
- * @property {string} [error] - Error message if failed
82
- */
83
-
84
- /**
85
- * @typedef {Object} UploadStats
86
- * @property {number} total - Total files found
87
- * @property {number} uploaded - Files uploaded
88
- * @property {number} skipped - Files skipped (duplicates)
89
- * @property {number} failed - Files failed to upload
90
- */
91
-
92
- /**
93
- * @typedef {Object} ProgressEvent
94
- * @property {'scanning'|'processing'|'deduplication'|'uploading'|'completed'|'error'} phase - Current phase
95
- * @property {number} [current] - Current item being processed
96
- * @property {number} [total] - Total items to process
97
- * @property {string} [message] - Progress message
98
- * @property {number} [toUpload] - Files to upload (deduplication phase)
99
- * @property {number} [existing] - Existing files (deduplication phase)
100
- * @property {string} [buildId] - Build ID (completed phase)
101
- * @property {string} [url] - Build URL (completed phase)
102
- */
103
-
104
- /**
105
- * @callback ProgressCallback
106
- * @param {ProgressEvent} event - Progress event
107
- * @returns {void}
108
- */
109
-
110
- /**
111
- * @typedef {Object} TDDOptions
112
- * @property {string} [baselineDir='baseline'] - Baseline screenshots directory
113
- * @property {string} [currentDir='screenshots'] - Current screenshots directory
114
- * @property {string} [diffDir='diffs'] - Diff output directory
115
- * @property {number} [threshold=0.1] - Comparison threshold
116
- * @property {boolean} [failOnDifference=true] - Fail on any difference
117
- * @property {boolean} [updateBaseline=false] - Update baseline on difference
118
- */
119
-
120
- /**
121
- * @typedef {Object} ComparisonResult
122
- * @property {string} name - Screenshot name
123
- * @property {boolean} passed - Whether comparison passed
124
- * @property {number} [difference] - Difference percentage (0-1)
125
- * @property {string} [diffPath] - Path to diff image
126
- * @property {string} [error] - Error message if comparison failed
127
- */
128
-
129
- /**
130
- * @typedef {Object} BuildInfo
131
- * @property {string} id - Build ID
132
- * @property {string} name - Build name
133
- * @property {'pending'|'processing'|'completed'|'failed'} status - Build status
134
- * @property {string} branch - Git branch
135
- * @property {string} [commit] - Git commit SHA
136
- * @property {string} environment - Environment name
137
- * @property {Date} createdAt - Creation timestamp
138
- * @property {Date} [completedAt] - Completion timestamp
139
- * @property {number} screenshotCount - Number of screenshots
140
- * @property {Object.<string, any>} [metadata] - Additional metadata
141
- */
142
-
143
- /**
144
- * @typedef {Object} CLIOptions
145
- * @property {boolean} [verbose=false] - Enable verbose logging
146
- * @property {string} [logLevel='info'] - Log level
147
- * @property {boolean} [quiet=false] - Suppress all output
148
- * @property {boolean} [json=false] - Output JSON instead of text
149
- * @property {string} [config] - Path to config file
150
- */
151
-
152
- // Export types for use in other files
153
- export default {};
@@ -1,27 +0,0 @@
1
- /**
2
- * Create a factory that pre-configures Vizzly instances
3
- *
4
- * @param {Object} config - Shared configuration
5
- * @param {Object} [config.defaultProperties] - Default metadata for all screenshots
6
- * @param {number} [config.defaultThreshold] - Default comparison threshold
7
- *
8
- * @example
9
- * // test-setup.js - Configure once
10
- * export const createVizzly = vizzlyFactory({
11
- * defaultProperties: {
12
- * framework: 'playwright',
13
- * project: 'web-app'
14
- * }
15
- * });
16
- *
17
- * // my-test.spec.js - Use everywhere
18
- * const vizzly = createVizzly();
19
- *
20
- * const screenshot = await page.screenshot({ fullPage: true }); // Your method
21
- * await vizzly.screenshot({
22
- * name: 'homepage',
23
- * image: screenshot, // Your buffer
24
- * properties: { browser: 'chrome' } // Merges with defaults
25
- * });
26
- */
27
- export function vizzlyFactory(globalConfig: any): (overrideConfig?: {}) => any;
@@ -1,38 +0,0 @@
1
- export class VizzlyServer {
2
- constructor({ port, config, tddMode, baselineBuild, baselineComparison, workingDir, buildId, vizzlyApi, buildInfo, emitter, }: {
3
- port: any;
4
- config: any;
5
- tddMode?: boolean;
6
- baselineBuild: any;
7
- baselineComparison: any;
8
- workingDir: any;
9
- buildId?: any;
10
- vizzlyApi?: any;
11
- buildInfo?: any;
12
- emitter?: any;
13
- });
14
- port: any;
15
- config: any;
16
- builds: Map<any, any>;
17
- server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
18
- tddMode: boolean;
19
- baselineBuild: any;
20
- baselineComparison: any;
21
- tddService: TddService;
22
- buildId: any;
23
- vizzlyApi: any;
24
- buildInfo: any;
25
- emitter: any;
26
- vizzlyDisabled: boolean;
27
- start(): Promise<any>;
28
- handleRequest(req: any, res: any): Promise<void>;
29
- handleScreenshot(req: any, res: any): Promise<void>;
30
- parseRequestBody(req: any): Promise<any>;
31
- stop(): Promise<any>;
32
- createBuild(options: any): Promise<`${string}-${string}-${string}-${string}-${string}`>;
33
- getScreenshotCount(buildId: any): any;
34
- getTotalScreenshotCount(): number;
35
- finishBuild(buildId: any): Promise<any>;
36
- cleanupBuild(buildId: any): Promise<void>;
37
- }
38
- import { TddService } from '../services/tdd-service.js';
@@ -1,45 +0,0 @@
1
- /**
2
- * Create an event emitter with enhanced functionality
3
- * @returns {EventEmitter} Enhanced event emitter
4
- */
5
- export function createEventEmitter(): EventEmitter;
6
- /**
7
- * Create a cleanup manager
8
- * @returns {Object} Cleanup manager with add/execute methods
9
- */
10
- export function createCleanupManager(): any;
11
- /**
12
- * Create signal handlers for graceful shutdown
13
- * @param {Function} onSignal - Function to call on signal
14
- * @returns {Function} Cleanup function to remove handlers
15
- */
16
- export function createSignalHandlers(onSignal: Function): Function;
17
- /**
18
- * Higher-order function to add error handling to any function
19
- * @param {Function} fn - Function to wrap
20
- * @param {Object} options - Error handling options
21
- * @returns {Function} Wrapped function with error handling
22
- */
23
- export function withErrorHandling(fn: Function, options?: any): Function;
24
- /**
25
- * Higher-order function to add logging to any function
26
- * @param {Function} fn - Function to wrap
27
- * @param {Object} logger - Logger instance
28
- * @param {string} operation - Operation name for logging
29
- * @returns {Function} Wrapped function with logging
30
- */
31
- export function withLogging(fn: Function, logger: any, operation: string): Function;
32
- /**
33
- * Compose multiple functions together
34
- * @param {...Function} fns - Functions to compose
35
- * @returns {Function} Composed function
36
- */
37
- export function compose(...fns: Function[]): Function;
38
- /**
39
- * Create a service context with shared functionality
40
- * @param {Object} config - Service configuration
41
- * @param {Object} options - Service options
42
- * @returns {Object} Service context
43
- */
44
- export function createServiceContext(config: any, options?: any): any;
45
- import { EventEmitter } from 'events';