samaro-uitest 1.0.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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +336 -0
  3. package/bin/samaro-allure.js +172 -0
  4. package/bin/samaro-init.js +278 -0
  5. package/bin/samaro-test.js +36 -0
  6. package/config/index.d.ts +4 -0
  7. package/config/index.d.ts.map +1 -0
  8. package/config/index.js +11 -0
  9. package/config/index.js.map +1 -0
  10. package/config/index.ts +3 -0
  11. package/config/playwright.component.config.d.ts +12 -0
  12. package/config/playwright.component.config.d.ts.map +1 -0
  13. package/config/playwright.component.config.js +42 -0
  14. package/config/playwright.component.config.js.map +1 -0
  15. package/config/playwright.component.config.ts +60 -0
  16. package/config/playwright.config.d.ts +14 -0
  17. package/config/playwright.config.d.ts.map +1 -0
  18. package/config/playwright.config.js +53 -0
  19. package/config/playwright.config.js.map +1 -0
  20. package/config/playwright.config.ts +76 -0
  21. package/config/test-setup.ts +17 -0
  22. package/config/vitest.config.d.ts +13 -0
  23. package/config/vitest.config.d.ts.map +1 -0
  24. package/config/vitest.config.js +53 -0
  25. package/config/vitest.config.js.map +1 -0
  26. package/config/vitest.config.ts +64 -0
  27. package/dist/config/index.d.ts +4 -0
  28. package/dist/config/index.d.ts.map +1 -0
  29. package/dist/config/index.js +4 -0
  30. package/dist/config/index.js.map +1 -0
  31. package/dist/config/playwright.component.config.d.ts +12 -0
  32. package/dist/config/playwright.component.config.d.ts.map +1 -0
  33. package/dist/config/playwright.component.config.js +39 -0
  34. package/dist/config/playwright.component.config.js.map +1 -0
  35. package/dist/config/playwright.config.d.ts +14 -0
  36. package/dist/config/playwright.config.d.ts.map +1 -0
  37. package/dist/config/playwright.config.js +50 -0
  38. package/dist/config/playwright.config.js.map +1 -0
  39. package/dist/config/test-setup.d.ts +3 -0
  40. package/dist/config/test-setup.d.ts.map +1 -0
  41. package/dist/config/test-setup.js +17 -0
  42. package/dist/config/test-setup.js.map +1 -0
  43. package/dist/config/vitest.config.d.ts +13 -0
  44. package/dist/config/vitest.config.d.ts.map +1 -0
  45. package/dist/config/vitest.config.js +46 -0
  46. package/dist/config/vitest.config.js.map +1 -0
  47. package/dist/helpers/api.d.ts +69 -0
  48. package/dist/helpers/api.d.ts.map +1 -0
  49. package/dist/helpers/api.js +154 -0
  50. package/dist/helpers/api.js.map +1 -0
  51. package/dist/helpers/auth.d.ts +35 -0
  52. package/dist/helpers/auth.d.ts.map +1 -0
  53. package/dist/helpers/auth.js +96 -0
  54. package/dist/helpers/auth.js.map +1 -0
  55. package/dist/helpers/config.d.ts +34 -0
  56. package/dist/helpers/config.d.ts.map +1 -0
  57. package/dist/helpers/config.js +63 -0
  58. package/dist/helpers/config.js.map +1 -0
  59. package/dist/helpers/debug.d.ts +48 -0
  60. package/dist/helpers/debug.d.ts.map +1 -0
  61. package/dist/helpers/debug.js +76 -0
  62. package/dist/helpers/debug.js.map +1 -0
  63. package/dist/helpers/index.d.ts +6 -0
  64. package/dist/helpers/index.d.ts.map +1 -0
  65. package/dist/helpers/index.js +11 -0
  66. package/dist/helpers/index.js.map +1 -0
  67. package/dist/helpers/setup.d.ts +50 -0
  68. package/dist/helpers/setup.d.ts.map +1 -0
  69. package/dist/helpers/setup.js +95 -0
  70. package/dist/helpers/setup.js.map +1 -0
  71. package/dist/src/index.d.ts +16 -0
  72. package/dist/src/index.d.ts.map +1 -0
  73. package/dist/src/index.js +38 -0
  74. package/dist/src/index.js.map +1 -0
  75. package/helpers/api.d.ts +69 -0
  76. package/helpers/api.d.ts.map +1 -0
  77. package/helpers/api.js +163 -0
  78. package/helpers/api.js.map +1 -0
  79. package/helpers/api.ts +224 -0
  80. package/helpers/auth.d.ts +35 -0
  81. package/helpers/auth.d.ts.map +1 -0
  82. package/helpers/auth.js +104 -0
  83. package/helpers/auth.js.map +1 -0
  84. package/helpers/auth.ts +125 -0
  85. package/helpers/config.d.ts +34 -0
  86. package/helpers/config.d.ts.map +1 -0
  87. package/helpers/config.js +70 -0
  88. package/helpers/config.js.map +1 -0
  89. package/helpers/config.ts +80 -0
  90. package/helpers/debug.d.ts +48 -0
  91. package/helpers/debug.d.ts.map +1 -0
  92. package/helpers/debug.js +86 -0
  93. package/helpers/debug.js.map +1 -0
  94. package/helpers/debug.ts +111 -0
  95. package/helpers/index.d.ts +6 -0
  96. package/helpers/index.d.ts.map +1 -0
  97. package/helpers/index.js +47 -0
  98. package/helpers/index.js.map +1 -0
  99. package/helpers/index.ts +62 -0
  100. package/helpers/setup.d.ts +50 -0
  101. package/helpers/setup.d.ts.map +1 -0
  102. package/helpers/setup.js +137 -0
  103. package/helpers/setup.js.map +1 -0
  104. package/helpers/setup.ts +144 -0
  105. package/package.json +94 -0
  106. package/schematics/collection.json +11 -0
  107. package/schematics/ng-add/index.js +121 -0
  108. package/schematics/ng-add/schema.json +26 -0
  109. package/scripts/check-allure-results.js +269 -0
  110. package/types/allure.d.ts +76 -0
  111. package/types/global.d.ts +49 -0
@@ -0,0 +1,269 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Pre-test Allure results checker
5
+ *
6
+ * This script checks for existing Allure result data and prompts the user
7
+ * to either clean it, keep it, or cancel the test run.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const { spawn } = require('child_process');
13
+ const readline = require('readline');
14
+
15
+ const rl = readline.createInterface({
16
+ input: process.stdin,
17
+ output: process.stdout,
18
+ });
19
+
20
+ // Allure result directories to check
21
+ const ALLURE_DIRS = [
22
+ { name: 'Unit Tests', dir: 'allure-unit-results', type: 'unit' },
23
+ { name: 'E2E Tests', dir: 'allure-e2e-results', type: 'e2e' },
24
+ { name: 'Component Tests', dir: 'allure-ct-results', type: 'ct' },
25
+ ];
26
+
27
+ // Colors for terminal output
28
+ const colors = {
29
+ reset: '\x1b[0m',
30
+ bright: '\x1b[1m',
31
+ red: '\x1b[31m',
32
+ green: '\x1b[32m',
33
+ yellow: '\x1b[33m',
34
+ blue: '\x1b[34m',
35
+ cyan: '\x1b[36m',
36
+ gray: '\x1b[90m',
37
+ };
38
+
39
+ /**
40
+ * Check if a directory exists and get its contents
41
+ */
42
+ function checkDirectory(dirPath) {
43
+ const fullPath = path.join(process.cwd(), dirPath);
44
+
45
+ if (!fs.existsSync(fullPath)) {
46
+ return { exists: false, count: 0, lastModified: null };
47
+ }
48
+
49
+ try {
50
+ const files = fs.readdirSync(fullPath);
51
+ const stats = fs.statSync(fullPath);
52
+
53
+ return {
54
+ exists: true,
55
+ count: files.length,
56
+ lastModified: stats.mtime,
57
+ };
58
+ } catch (error) {
59
+ return { exists: false, count: 0, lastModified: null, error: error.message };
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Format the last modified time
65
+ */
66
+ function formatTime(date) {
67
+ if (!date) return '-';
68
+
69
+ const now = new Date();
70
+ const diff = now - date;
71
+ const minutes = Math.floor(diff / 60000);
72
+ const hours = Math.floor(diff / 3600000);
73
+ const days = Math.floor(diff / 86400000);
74
+
75
+ if (minutes < 1) return 'Just now';
76
+ if (minutes < 60) return `${minutes} min ago`;
77
+ if (hours < 24) return `${hours} hour${hours > 1 ? 's' : ''} ago`;
78
+ return `${days} day${days > 1 ? 's' : ''} ago`;
79
+ }
80
+
81
+ /**
82
+ * Clean all Allure result directories
83
+ */
84
+ function cleanAllureResults() {
85
+ console.log(`${colors.cyan}🧹 Cleaning Allure results...${colors.reset}\n`);
86
+
87
+ let cleanedCount = 0;
88
+
89
+ for (const { dir } of ALLURE_DIRS) {
90
+ const fullPath = path.join(process.cwd(), dir);
91
+ if (fs.existsSync(fullPath)) {
92
+ try {
93
+ fs.rmSync(fullPath, { recursive: true, force: true });
94
+ console.log(` ${colors.green}✓${colors.reset} Removed ${dir}/`);
95
+ cleanedCount++;
96
+ } catch (error) {
97
+ console.log(` ${colors.red}✗${colors.reset} Failed to remove ${dir}/: ${error.message}`);
98
+ }
99
+ }
100
+ }
101
+
102
+ // Also clean the reports directory
103
+ const reportsPath = path.join(process.cwd(), 'allure-reports');
104
+ if (fs.existsSync(reportsPath)) {
105
+ try {
106
+ fs.rmSync(reportsPath, { recursive: true, force: true });
107
+ console.log(` ${colors.green}✓${colors.reset} Removed allure-reports/`);
108
+ cleanedCount++;
109
+ } catch (error) {
110
+ console.log(` ${colors.red}✗${colors.reset} Failed to remove allure-reports/: ${error.message}`);
111
+ }
112
+ }
113
+
114
+ console.log(`${colors.green}\n✅ Cleanup complete!${colors.reset}\n`);
115
+ return cleanedCount;
116
+ }
117
+
118
+ /**
119
+ * Run the actual test command
120
+ */
121
+ function runTestCommand(command) {
122
+ console.log(`${colors.cyan}▶️ Running: ${command}${colors.reset}\n`);
123
+
124
+ const parts = command.split(' ');
125
+ const cmd = parts[0];
126
+ const args = parts.slice(1);
127
+
128
+ const isWindows = process.platform === 'win32';
129
+
130
+ const child = spawn(cmd, args, {
131
+ stdio: 'inherit',
132
+ shell: isWindows,
133
+ cwd: process.cwd(),
134
+ });
135
+
136
+ child.on('close', (code) => {
137
+ process.exit(code);
138
+ });
139
+
140
+ child.on('error', (error) => {
141
+ console.error(`${colors.red}Failed to run command: ${error.message}${colors.reset}`);
142
+ process.exit(1);
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Show the prompt and handle user input
148
+ */
149
+ function showPrompt(hasExistingResults, testCommand) {
150
+ console.log(`${colors.bright}What would you like to do?${colors.reset}\n`);
151
+
152
+ if (hasExistingResults) {
153
+ console.log(` ${colors.green}[1]${colors.reset} 🧹 Clean all results and run tests (recommended)`);
154
+ console.log(` ${colors.yellow}[2]${colors.reset} ▶️ Keep results and run tests (will accumulate)`);
155
+ } else {
156
+ console.log(` ${colors.green}[1]${colors.reset} ▶️ Run tests`);
157
+ }
158
+ console.log(` ${colors.red}[3]${colors.reset} ❌ Cancel\n`);
159
+
160
+ const promptText = hasExistingResults
161
+ ? `Select option (1-3): `
162
+ : `Select option (1 or 3): `;
163
+
164
+ rl.question(promptText, (answer) => {
165
+ const choice = answer.trim();
166
+
167
+ if (choice === '1') {
168
+ // Clean and run
169
+ if (hasExistingResults) {
170
+ cleanAllureResults();
171
+ }
172
+ rl.close();
173
+ runTestCommand(testCommand);
174
+ } else if (choice === '2' && hasExistingResults) {
175
+ // Keep results and run
176
+ console.log(`${colors.yellow}\n⚠️ Proceeding with existing results. Reports will show duplicates.${colors.reset}\n`);
177
+ rl.close();
178
+ runTestCommand(testCommand);
179
+ } else if (choice === '3') {
180
+ // Cancel
181
+ console.log(`${colors.gray}\n❌ Test run cancelled.${colors.reset}`);
182
+ rl.close();
183
+ process.exit(0);
184
+ } else {
185
+ // Invalid input
186
+ console.log(`${colors.red}\n❌ Invalid option. Please try again.${colors.reset}\n`);
187
+ showPrompt(hasExistingResults, testCommand);
188
+ }
189
+ });
190
+ }
191
+
192
+ /**
193
+ * Auto mode - clean and run without prompting (for CI)
194
+ */
195
+ function autoMode(testCommand) {
196
+ console.log(`${colors.cyan}🧹 Auto-cleaning Allure results (CI mode)...${colors.reset}\n`);
197
+ cleanAllureResults();
198
+ runTestCommand(testCommand);
199
+ }
200
+
201
+ /**
202
+ * Main function
203
+ */
204
+ function main() {
205
+ // Get the test command from arguments
206
+ const testCommand = process.argv.slice(2).join(' ');
207
+
208
+ if (!testCommand) {
209
+ console.error(`${colors.red}Error: No test command provided${colors.reset}`);
210
+ console.error(`Usage: node check-allure-results.js "<test-command>"`);
211
+ console.error(`Example: node check-allure-results.js "vitest"`);
212
+ process.exit(1);
213
+ }
214
+
215
+ // Check if in CI mode
216
+ if (process.env.CI || process.env.SAMARO_AUTO_CLEAN) {
217
+ autoMode(testCommand);
218
+ return;
219
+ }
220
+
221
+ console.log(`\n${colors.bright}🔍 Checking for existing Allure results...${colors.reset}\n`);
222
+
223
+ // Check all directories
224
+ const results = ALLURE_DIRS.map(({ name, dir }) => ({
225
+ name,
226
+ dir,
227
+ ...checkDirectory(dir),
228
+ }));
229
+
230
+ const hasExistingResults = results.some(r => r.exists && r.count > 0);
231
+
232
+ if (!hasExistingResults) {
233
+ console.log(`${colors.green}✅ No existing Allure results found.${colors.reset}`);
234
+ console.log(`${colors.gray} Starting with a clean slate.${colors.reset}\n`);
235
+ showPrompt(false, testCommand);
236
+ return;
237
+ }
238
+
239
+ // Show warning
240
+ console.log(`${colors.yellow}⚠️ WARNING: Found existing result data from previous runs:${colors.reset}\n`);
241
+
242
+ // Print table header
243
+ console.log(` ${colors.bright}Directory${colors.reset} Files Last Run`);
244
+ console.log(` ${colors.gray}────────────────────────────────────────────────${colors.reset}`);
245
+
246
+ // Print results
247
+ results.forEach(({ name, dir, exists, count, lastModified }) => {
248
+ if (exists) {
249
+ const namePadded = name.padEnd(28);
250
+ const countPadded = String(count).padStart(5);
251
+ const time = formatTime(lastModified);
252
+ console.log(` ${namePadded} ${countPadded} ${time}`);
253
+ }
254
+ });
255
+
256
+ console.log(`\n${colors.cyan}💡 Not cleaning will cause duplicate entries in reports.${colors.reset}\n`);
257
+
258
+ showPrompt(true, testCommand);
259
+ }
260
+
261
+ // Handle Ctrl+C gracefully
262
+ rl.on('SIGINT', () => {
263
+ console.log(`\n${colors.gray}\n❌ Cancelled by user.${colors.reset}`);
264
+ rl.close();
265
+ process.exit(0);
266
+ });
267
+
268
+ // Run the script
269
+ main();
@@ -0,0 +1,76 @@
1
+ // Type definitions for Allure metadata in tests
2
+
3
+ export interface AllureLabel {
4
+ name: string;
5
+ value: string;
6
+ }
7
+
8
+ export interface AllureLink {
9
+ name?: string;
10
+ url: string;
11
+ type?: string;
12
+ }
13
+
14
+ export interface AllureParameter {
15
+ name: string;
16
+ value: string;
17
+ }
18
+
19
+ export interface AllureStep {
20
+ name: string;
21
+ status: 'passed' | 'failed' | 'broken' | 'skipped';
22
+ }
23
+
24
+ export interface AllureAttachment {
25
+ name: string;
26
+ type: string;
27
+ source: string;
28
+ }
29
+
30
+ export interface AllureTestCase {
31
+ name: string;
32
+ fullName: string;
33
+ historyId: string;
34
+ testCaseId?: string;
35
+ labels: AllureLabel[];
36
+ links: AllureLink[];
37
+ parameters: AllureParameter[];
38
+ steps: AllureStep[];
39
+ attachments: AllureAttachment[];
40
+ status: 'passed' | 'failed' | 'broken' | 'skipped';
41
+ statusDetails?: {
42
+ known?: boolean;
43
+ muted?: boolean;
44
+ flaky?: boolean;
45
+ message?: string;
46
+ trace?: string;
47
+ };
48
+ stage: 'scheduled' | 'running' | 'finished';
49
+ description?: string;
50
+ descriptionHtml?: string;
51
+ start?: number;
52
+ stop?: number;
53
+ }
54
+
55
+ // Severity levels
56
+ export type Severity = 'blocker' | 'critical' | 'normal' | 'minor' | 'trivial';
57
+
58
+ // Label names
59
+ export type LabelName =
60
+ | 'epic'
61
+ | 'feature'
62
+ | 'story'
63
+ | 'suite'
64
+ | 'parentSuite'
65
+ | 'subSuite'
66
+ | 'owner'
67
+ | 'severity'
68
+ | 'tag'
69
+ | 'layer'
70
+ | 'host'
71
+ | 'thread'
72
+ | 'language'
73
+ | 'framework'
74
+ | 'package'
75
+ | 'testClass'
76
+ | 'testMethod';
@@ -0,0 +1,49 @@
1
+ // Global type definitions for SamaroUItest
2
+
3
+ declare global {
4
+ interface Window {
5
+ /**
6
+ * Debug interface for accessing Angular app state during tests
7
+ */
8
+ __app_debug__?: {
9
+ getToken(): string | null;
10
+ getAuthState(): 'authenticated' | 'unauthenticated' | 'unavailable' | 'loading';
11
+ getCurrentUser(): {
12
+ username: string;
13
+ email: string;
14
+ bio: string | null;
15
+ image: string | null;
16
+ token: string;
17
+ } | null;
18
+ };
19
+
20
+ /**
21
+ * Angular testability interface
22
+ */
23
+ getAngularTestability?(element: Element): {
24
+ isStable(): boolean;
25
+ whenStable(callback: () => void): void;
26
+ };
27
+ }
28
+
29
+ /**
30
+ * Environment variables
31
+ */
32
+ namespace NodeJS {
33
+ interface ProcessEnv {
34
+ CI?: string;
35
+ API_MODE?: string;
36
+ API_BASE?: string;
37
+ DEBUG_INTERFACE_NAME?: string;
38
+ TIMEOUT_NAVIGATION?: string;
39
+ TIMEOUT_ACTION?: string;
40
+ TIMEOUT_EXPECTATION?: string;
41
+ SAMARO_AUTO_CLEAN?: string;
42
+ NG_API_URL?: string;
43
+ DEBUG?: string;
44
+ PWDEBUG?: string;
45
+ }
46
+ }
47
+ }
48
+
49
+ export {};