@silasfmartins/testhub 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.
- package/.github/copilot-instructions.md +520 -0
- package/biome.json +37 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +169 -0
- package/dist/scripts/consumer-postinstall.d.ts +15 -0
- package/dist/scripts/consumer-postinstall.js +785 -0
- package/dist/scripts/generate-docs.d.ts +16 -0
- package/dist/scripts/generate-docs.js +1363 -0
- package/dist/scripts/generate-index.d.ts +2 -0
- package/dist/scripts/generate-index.js +314 -0
- package/dist/scripts/init-api.d.ts +2 -0
- package/dist/scripts/init-api.js +525 -0
- package/dist/scripts/init-banco.d.ts +2 -0
- package/dist/scripts/init-banco.js +347 -0
- package/dist/scripts/init-frontend.d.ts +2 -0
- package/dist/scripts/init-frontend.js +627 -0
- package/dist/scripts/init-mobile.d.ts +2 -0
- package/dist/scripts/init-mobile.js +481 -0
- package/dist/scripts/init-scenarios.d.ts +2 -0
- package/dist/scripts/init-scenarios.js +846 -0
- package/dist/scripts/init-ssh.d.ts +2 -0
- package/dist/scripts/init-ssh.js +639 -0
- package/dist/scripts/package-versions.d.ts +57 -0
- package/dist/scripts/package-versions.js +768 -0
- package/dist/scripts/postinstall.d.ts +1 -0
- package/dist/scripts/postinstall.js +527 -0
- package/dist/scripts/robust-build.d.ts +7 -0
- package/dist/scripts/robust-build.js +88 -0
- package/dist/scripts/setup-local-packages.d.ts +31 -0
- package/dist/scripts/setup-local-packages.js +237 -0
- package/dist/scripts/smart-override.d.ts +2 -0
- package/dist/scripts/smart-override.js +1360 -0
- package/dist/scripts/sync-configs.d.ts +27 -0
- package/dist/scripts/sync-configs.js +248 -0
- package/dist/scripts/test-biome-parse.d.ts +5 -0
- package/dist/scripts/test-biome-parse.js +84 -0
- package/dist/scripts/ultracite-setup.d.ts +4 -0
- package/dist/scripts/ultracite-setup.js +310 -0
- package/dist/scripts/update-all-init-scripts.d.ts +2 -0
- package/dist/scripts/update-all-init-scripts.js +52 -0
- package/dist/scripts/update-biome-schema.d.ts +15 -0
- package/dist/scripts/update-biome-schema.js +124 -0
- package/dist/src/AutoCoreFacade.d.ts +145 -0
- package/dist/src/AutoCoreFacade.js +217 -0
- package/dist/src/api/ApiActions.d.ts +297 -0
- package/dist/src/api/ApiActions.js +1905 -0
- package/dist/src/api/Certificate.d.ts +60 -0
- package/dist/src/api/Certificate.js +79 -0
- package/dist/src/api/JsonResponse.d.ts +116 -0
- package/dist/src/api/JsonResponse.js +206 -0
- package/dist/src/appium/DeviceFarmViewer.d.ts +79 -0
- package/dist/src/appium/DeviceFarmViewer.js +1083 -0
- package/dist/src/appium/MobileActions.d.ts +347 -0
- package/dist/src/appium/MobileActions.js +1632 -0
- package/dist/src/appium/MobileConnection.d.ts +160 -0
- package/dist/src/appium/MobileConnection.js +772 -0
- package/dist/src/config/envLoader.d.ts +123 -0
- package/dist/src/config/envLoader.js +361 -0
- package/dist/src/config/jest-safe-setup.d.ts +19 -0
- package/dist/src/config/jest-safe-setup.js +369 -0
- package/dist/src/config/timeouts.d.ts +32 -0
- package/dist/src/config/timeouts.js +38 -0
- package/dist/src/desktop/DesktopActions.d.ts +46 -0
- package/dist/src/desktop/DesktopActions.js +398 -0
- package/dist/src/desktop/DesktopConnection.d.ts +32 -0
- package/dist/src/desktop/DesktopConnection.js +84 -0
- package/dist/src/domain/entities/TestExecution.d.ts +117 -0
- package/dist/src/domain/entities/TestExecution.js +150 -0
- package/dist/src/domain/entities/TestReport.d.ts +114 -0
- package/dist/src/domain/entities/TestReport.js +179 -0
- package/dist/src/domain/repositories/ITestRepository.d.ts +196 -0
- package/dist/src/domain/repositories/ITestRepository.js +14 -0
- package/dist/src/domain/schemas/ValidationSchemas.d.ts +159 -0
- package/dist/src/domain/schemas/ValidationSchemas.js +181 -0
- package/dist/src/functions/errors/BaseError.d.ts +78 -0
- package/dist/src/functions/errors/BaseError.js +245 -0
- package/dist/src/functions/errors/ConfigurationError.d.ts +16 -0
- package/dist/src/functions/errors/ConfigurationError.js +48 -0
- package/dist/src/functions/errors/ErrorCatalog.d.ts +148 -0
- package/dist/src/functions/errors/ErrorCatalog.js +157 -0
- package/dist/src/functions/errors/GlobalErrorHandler.d.ts +101 -0
- package/dist/src/functions/errors/GlobalErrorHandler.js +281 -0
- package/dist/src/functions/errors/IntegrationError.d.ts +17 -0
- package/dist/src/functions/errors/IntegrationError.js +51 -0
- package/dist/src/functions/errors/SecurityError.d.ts +14 -0
- package/dist/src/functions/errors/SecurityError.js +42 -0
- package/dist/src/functions/errors/SystemError.d.ts +12 -0
- package/dist/src/functions/errors/SystemError.js +36 -0
- package/dist/src/functions/errors/ValidationError.d.ts +14 -0
- package/dist/src/functions/errors/ValidationError.js +61 -0
- package/dist/src/functions/errors/index.d.ts +12 -0
- package/dist/src/functions/errors/index.js +13 -0
- package/dist/src/global-setup.d.ts +1 -0
- package/dist/src/global-setup.js +1037 -0
- package/dist/src/helpers/BancoActions.d.ts +188 -0
- package/dist/src/helpers/BancoActions.js +581 -0
- package/dist/src/helpers/EnviromentHelper.d.ts +17 -0
- package/dist/src/helpers/EnviromentHelper.js +66 -0
- package/dist/src/helpers/ParallelExecutionHelper.d.ts +183 -0
- package/dist/src/helpers/ParallelExecutionHelper.js +375 -0
- package/dist/src/helpers/SyncSignal.d.ts +15 -0
- package/dist/src/helpers/SyncSignal.js +44 -0
- package/dist/src/hubdocs/CategoryDetector.d.ts +83 -0
- package/dist/src/hubdocs/CategoryDetector.js +401 -0
- package/dist/src/hubdocs/DirectStatementInterceptor.d.ts +54 -0
- package/dist/src/hubdocs/DirectStatementInterceptor.js +243 -0
- package/dist/src/hubdocs/ExecutionTracker.d.ts +107 -0
- package/dist/src/hubdocs/ExecutionTracker.js +702 -0
- package/dist/src/hubdocs/HubDocs.d.ts +395 -0
- package/dist/src/hubdocs/HubDocs.js +3586 -0
- package/dist/src/hubdocs/StatementMethodFilter.d.ts +71 -0
- package/dist/src/hubdocs/StatementMethodFilter.js +618 -0
- package/dist/src/hubdocs/StatementTracker.d.ts +417 -0
- package/dist/src/hubdocs/StatementTracker.js +2419 -0
- package/dist/src/hubdocs/SwaggerGenerator.d.ts +59 -0
- package/dist/src/hubdocs/SwaggerGenerator.js +405 -0
- package/dist/src/hubdocs/index.d.ts +9 -0
- package/dist/src/hubdocs/index.js +9 -0
- package/dist/src/hubdocs/types.d.ts +114 -0
- package/dist/src/hubdocs/types.js +5 -0
- package/dist/src/infrastructure/DependencyContainer.d.ts +142 -0
- package/dist/src/infrastructure/DependencyContainer.js +250 -0
- package/dist/src/infrastructure/adapters/AppiumAdapter.d.ts +168 -0
- package/dist/src/infrastructure/adapters/AppiumAdapter.js +468 -0
- package/dist/src/infrastructure/adapters/OracleAdapter.d.ts +150 -0
- package/dist/src/infrastructure/adapters/OracleAdapter.js +388 -0
- package/dist/src/infrastructure/adapters/PlaywrightAdapter.d.ts +192 -0
- package/dist/src/infrastructure/adapters/PlaywrightAdapter.js +382 -0
- package/dist/src/infrastructure/adapters/SSHAdapter.d.ts +141 -0
- package/dist/src/infrastructure/adapters/SSHAdapter.js +428 -0
- package/dist/src/interfaces.d.ts +501 -0
- package/dist/src/interfaces.js +25 -0
- package/dist/src/internal/fakes/__fake-actions__.d.ts +17 -0
- package/dist/src/internal/fakes/__fake-actions__.js +21 -0
- package/dist/src/internal/fakes/__forbidden__.d.ts +10 -0
- package/dist/src/internal/fakes/__forbidden__.js +18 -0
- package/dist/src/internal/fakes/__honeypot__.d.ts +15 -0
- package/dist/src/internal/fakes/__honeypot__.js +24 -0
- package/dist/src/octane/OctaneReporter.d.ts +13 -0
- package/dist/src/octane/OctaneReporter.js +61 -0
- package/dist/src/playwright/CryptoActions.d.ts +20 -0
- package/dist/src/playwright/CryptoActions.js +75 -0
- package/dist/src/playwright/EnhancedWebActions.d.ts +7 -0
- package/dist/src/playwright/EnhancedWebActions.js +65 -0
- package/dist/src/playwright/WebActions.d.ts +1599 -0
- package/dist/src/playwright/WebActions.js +11788 -0
- package/dist/src/playwright/actions/ActionTimeline.d.ts +36 -0
- package/dist/src/playwright/actions/ActionTimeline.js +101 -0
- package/dist/src/playwright/actions/RecoveryQueue.d.ts +82 -0
- package/dist/src/playwright/actions/RecoveryQueue.js +130 -0
- package/dist/src/playwright/actions/SelectorCache.d.ts +53 -0
- package/dist/src/playwright/actions/SelectorCache.js +96 -0
- package/dist/src/playwright/actions/index.d.ts +13 -0
- package/dist/src/playwright/actions/index.js +14 -0
- package/dist/src/playwright/actions/types.d.ts +147 -0
- package/dist/src/playwright/actions/types.js +5 -0
- package/dist/src/playwright/fixtures.d.ts +112 -0
- package/dist/src/playwright/fixtures.js +718 -0
- package/dist/src/playwright/network-logs-reporter.d.ts +7 -0
- package/dist/src/playwright/network-logs-reporter.js +66 -0
- package/dist/src/playwright/registerRecoveryWrappers.d.ts +1 -0
- package/dist/src/playwright/registerRecoveryWrappers.js +54 -0
- package/dist/src/security/BuildSecurity.d.ts +12 -0
- package/dist/src/security/BuildSecurity.js +138 -0
- package/dist/src/security/EulaProtection.d.ts +70 -0
- package/dist/src/security/EulaProtection.js +155 -0
- package/dist/src/security/HoneypotManager.d.ts +46 -0
- package/dist/src/security/HoneypotManager.js +234 -0
- package/dist/src/security/KeysManager.d.ts +36 -0
- package/dist/src/security/KeysManager.js +158 -0
- package/dist/src/security/ProofOfWorkIntegration.d.ts +64 -0
- package/dist/src/security/ProofOfWorkIntegration.js +206 -0
- package/dist/src/security/SecurityValidation.d.ts +21 -0
- package/dist/src/security/SecurityValidation.js +163 -0
- package/dist/src/security/SourceMapProtection.d.ts +55 -0
- package/dist/src/security/SourceMapProtection.js +220 -0
- package/dist/src/security/protector.d.ts +1 -0
- package/dist/src/security/protector.js +97 -0
- package/dist/src/ssh/SSHActions.d.ts +262 -0
- package/dist/src/ssh/SSHActions.js +790 -0
- package/dist/src/ssh/SSHClient.d.ts +99 -0
- package/dist/src/ssh/SSHClient.js +409 -0
- package/dist/src/statements/BaseStatement.d.ts +38 -0
- package/dist/src/statements/BaseStatement.js +78 -0
- package/dist/src/testContext/AuthStateManager.d.ts +93 -0
- package/dist/src/testContext/AuthStateManager.js +256 -0
- package/dist/src/testContext/CoverageManager.d.ts +198 -0
- package/dist/src/testContext/CoverageManager.js +917 -0
- package/dist/src/testContext/TestAnnotations.d.ts +476 -0
- package/dist/src/testContext/TestAnnotations.js +2647 -0
- package/dist/src/testContext/TestContext.d.ts +138 -0
- package/dist/src/testContext/TestContext.js +369 -0
- package/dist/src/testContext/UnifiedHtmlGenerator.d.ts +7 -0
- package/dist/src/testContext/UnifiedHtmlGenerator.js +264 -0
- package/dist/src/testContext/UnifiedReportManager.d.ts +211 -0
- package/dist/src/testContext/UnifiedReportManager.js +1206 -0
- package/dist/src/testhub/DynamicConfigManager.d.ts +121 -0
- package/dist/src/testhub/DynamicConfigManager.js +320 -0
- package/dist/src/testhub/SystemsManager.d.ts +119 -0
- package/dist/src/testhub/SystemsManager.js +365 -0
- package/dist/src/testhub/TestHubClient.d.ts +335 -0
- package/dist/src/testhub/TestHubClient.js +1215 -0
- package/dist/src/testhub/TestHubReporter.d.ts +62 -0
- package/dist/src/testhub/TestHubReporter.js +576 -0
- package/dist/src/testhub/TestHubVars.d.ts +116 -0
- package/dist/src/testhub/TestHubVars.js +273 -0
- package/dist/src/utils/ActionInterceptor.d.ts +59 -0
- package/dist/src/utils/ActionInterceptor.js +741 -0
- package/dist/src/utils/ArtifactsCompressor.d.ts +43 -0
- package/dist/src/utils/ArtifactsCompressor.js +181 -0
- package/dist/src/utils/AutoLogsFinal.d.ts +47 -0
- package/dist/src/utils/AutoLogsFinal.js +148 -0
- package/dist/src/utils/CodeGenSession.d.ts +114 -0
- package/dist/src/utils/CodeGenSession.js +264 -0
- package/dist/src/utils/ConfigLogger.d.ts +133 -0
- package/dist/src/utils/ConfigLogger.js +611 -0
- package/dist/src/utils/CustomReporter.d.ts +22 -0
- package/dist/src/utils/CustomReporter.js +352 -0
- package/dist/src/utils/DataStore.d.ts +171 -0
- package/dist/src/utils/DataStore.js +484 -0
- package/dist/src/utils/DatabaseInterceptor.d.ts +19 -0
- package/dist/src/utils/DatabaseInterceptor.js +295 -0
- package/dist/src/utils/DateHelper.d.ts +16 -0
- package/dist/src/utils/DateHelper.js +120 -0
- package/dist/src/utils/DateValidator.d.ts +4 -0
- package/dist/src/utils/DateValidator.js +51 -0
- package/dist/src/utils/DocumentGenerator.d.ts +35 -0
- package/dist/src/utils/DocumentGenerator.js +129 -0
- package/dist/src/utils/EvidenceCapture.d.ts +90 -0
- package/dist/src/utils/EvidenceCapture.js +600 -0
- package/dist/src/utils/EvidenceReportGenerator.d.ts +70 -0
- package/dist/src/utils/EvidenceReportGenerator.js +799 -0
- package/dist/src/utils/FrameManagementUtil.d.ts +42 -0
- package/dist/src/utils/FrameManagementUtil.js +75 -0
- package/dist/src/utils/GlobalStatementsInterceptor.d.ts +1 -0
- package/dist/src/utils/GlobalStatementsInterceptor.js +1 -0
- package/dist/src/utils/HTMLTemplate.d.ts +1 -0
- package/dist/src/utils/HTMLTemplate.js +1034 -0
- package/dist/src/utils/InterceptacaoMagica.d.ts +23 -0
- package/dist/src/utils/InterceptacaoMagica.js +365 -0
- package/dist/src/utils/LogSanitizer.d.ts +35 -0
- package/dist/src/utils/LogSanitizer.js +110 -0
- package/dist/src/utils/Logger.d.ts +65 -0
- package/dist/src/utils/Logger.js +284 -0
- package/dist/src/utils/McpLocalClient.d.ts +141 -0
- package/dist/src/utils/McpLocalClient.js +871 -0
- package/dist/src/utils/PDFEvidenceGenerator.d.ts +20 -0
- package/dist/src/utils/PDFEvidenceGenerator.js +156 -0
- package/dist/src/utils/SpecFileAnalyzer.d.ts +35 -0
- package/dist/src/utils/SpecFileAnalyzer.js +209 -0
- package/dist/src/utils/StatementInterceptor.d.ts +18 -0
- package/dist/src/utils/StatementInterceptor.js +87 -0
- package/dist/src/utils/StatementLogger.d.ts +33 -0
- package/dist/src/utils/StatementLogger.js +113 -0
- package/dist/src/utils/StatementsInterceptor.d.ts +1 -0
- package/dist/src/utils/StatementsInterceptor.js +1 -0
- package/dist/src/utils/TeamsFlushHook.d.ts +17 -0
- package/dist/src/utils/TeamsFlushHook.js +168 -0
- package/dist/src/utils/TerminalLogCapture.d.ts +158 -0
- package/dist/src/utils/TerminalLogCapture.js +531 -0
- package/dist/src/utils/TestMethodLogger.d.ts +70 -0
- package/dist/src/utils/TestMethodLogger.js +95 -0
- package/dist/src/utils/UnifiedTeardown.d.ts +4 -0
- package/dist/src/utils/UnifiedTeardown.js +400 -0
- package/dist/src/utils/XPathCatalog.d.ts +152 -0
- package/dist/src/utils/XPathCatalog.js +350 -0
- package/dist/src/utils/generators.d.ts +90 -0
- package/dist/src/utils/generators.js +167 -0
- package/dist/src/utils/testRecovery/ResilientPlaywright.d.ts +152 -0
- package/dist/src/utils/testRecovery/ResilientPlaywright.js +715 -0
- package/dist/src/utils/testRecovery/TestRecoveryClient.d.ts +801 -0
- package/dist/src/utils/testRecovery/TestRecoveryClient.js +1415 -0
- package/dist/src/utils/testRecovery/autoFixCode.d.ts +65 -0
- package/dist/src/utils/testRecovery/autoFixCode.js +32 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +59 -0
- package/dist/wdio.conf.d.ts +1 -0
- package/dist/wdio.conf.js +420 -0
- package/package.json +137 -0
- package/protect-loader.mjs +643 -0
- package/scripts/consumer-postinstall.ts +975 -0
- package/scripts/generate-index.ts +343 -0
- package/scripts/init-api.ts +613 -0
- package/scripts/init-banco.ts +437 -0
- package/scripts/init-frontend.ts +727 -0
- package/scripts/init-mobile.ts +558 -0
- package/scripts/init-scenarios.ts +925 -0
- package/scripts/init-ssh.ts +734 -0
- package/scripts/package-versions.ts +978 -0
- package/scripts/postinstall.ts +605 -0
- package/scripts/smart-override.ts +1675 -0
- package/scripts/sync-configs.ts +302 -0
- package/scripts/ultracite-setup.ts +370 -0
- package/src/types/globals.d.ts +48 -0
- package/tsconfig.json +29 -0
- package/types/autocore-sync-signal.d.ts +10 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🔐 AuthStateManager - Gerenciamento de Estado de Autenticação
|
|
3
|
+
* @description Sistema similar ao Playwright storageState para salvar e restaurar cookies, localStorage e sessionStorage
|
|
4
|
+
* @author TestHUB Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
*
|
|
7
|
+
* @note TypeScript global declaration for browser context in page.evaluate()
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* // Salvar estado após login
|
|
12
|
+
* await AuthStateManager.saveState(page, './auth.json')
|
|
13
|
+
*
|
|
14
|
+
* // Restaurar estado em outro teste
|
|
15
|
+
* await AuthStateManager.restoreState(page, './auth.json')
|
|
16
|
+
*
|
|
17
|
+
* // Limpar estado
|
|
18
|
+
* await AuthStateManager.clearState(page)
|
|
19
|
+
*/
|
|
20
|
+
import type { BrowserContext, Page } from '@playwright/test';
|
|
21
|
+
/**
|
|
22
|
+
* Interface para o estado de autenticação completo
|
|
23
|
+
*/
|
|
24
|
+
export interface AuthState {
|
|
25
|
+
cookies: Array<{
|
|
26
|
+
name: string;
|
|
27
|
+
value: string;
|
|
28
|
+
domain: string;
|
|
29
|
+
path: string;
|
|
30
|
+
expires?: number;
|
|
31
|
+
httpOnly?: boolean;
|
|
32
|
+
secure?: boolean;
|
|
33
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
34
|
+
}>;
|
|
35
|
+
origins: Array<{
|
|
36
|
+
origin: string;
|
|
37
|
+
localStorage: Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
value: string;
|
|
40
|
+
}>;
|
|
41
|
+
sessionStorage?: Array<{
|
|
42
|
+
name: string;
|
|
43
|
+
value: string;
|
|
44
|
+
}>;
|
|
45
|
+
}>;
|
|
46
|
+
timestamp: string;
|
|
47
|
+
url?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare class AuthStateManager {
|
|
50
|
+
private static readonly DEFAULT_AUTH_DIR;
|
|
51
|
+
/**
|
|
52
|
+
* 💾 Salva o estado completo de autenticação (cookies + localStorage + sessionStorage)
|
|
53
|
+
* @param page Página do Playwright
|
|
54
|
+
* @param filePath Caminho do arquivo para salvar (padrão: ./test-results/auth/auth-state.json)
|
|
55
|
+
*/
|
|
56
|
+
static saveState(page: Page, filePath?: string): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* 🔄 Restaura o estado de autenticação salvo
|
|
59
|
+
* @param page Página do Playwright
|
|
60
|
+
* @param filePath Caminho do arquivo de estado
|
|
61
|
+
*/
|
|
62
|
+
static restoreState(page: Page, filePath?: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* 🧹 Limpa todo o estado de autenticação (cookies + localStorage + sessionStorage)
|
|
65
|
+
* @param page Página do Playwright
|
|
66
|
+
*/
|
|
67
|
+
static clearState(page: Page): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* 📄 Verifica se um arquivo de estado existe
|
|
70
|
+
* @param filePath Caminho do arquivo
|
|
71
|
+
*/
|
|
72
|
+
static stateExists(filePath?: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* 🔍 Lê e retorna o estado sem aplicar
|
|
75
|
+
* @param filePath Caminho do arquivo
|
|
76
|
+
*/
|
|
77
|
+
static readState(filePath?: string): AuthState | null;
|
|
78
|
+
/**
|
|
79
|
+
* 🗑️ Remove o arquivo de estado
|
|
80
|
+
* @param filePath Caminho do arquivo
|
|
81
|
+
*/
|
|
82
|
+
static deleteState(filePath?: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* 📋 Lista todos os arquivos de estado no diretório padrão
|
|
85
|
+
*/
|
|
86
|
+
static listStates(): string[];
|
|
87
|
+
/**
|
|
88
|
+
* 🔐 Salva estado usando o contexto do Playwright diretamente (método alternativo)
|
|
89
|
+
* @param context Contexto do navegador
|
|
90
|
+
* @param filePath Caminho do arquivo
|
|
91
|
+
*/
|
|
92
|
+
static saveContextState(context: BrowserContext, filePath?: string): Promise<string>;
|
|
93
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🔐 AuthStateManager - Gerenciamento de Estado de Autenticação
|
|
3
|
+
* @description Sistema similar ao Playwright storageState para salvar e restaurar cookies, localStorage e sessionStorage
|
|
4
|
+
* @author TestHUB Team
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
*
|
|
7
|
+
* @note TypeScript global declaration for browser context in page.evaluate()
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import { Logger } from '../utils/Logger.js';
|
|
12
|
+
export class AuthStateManager {
|
|
13
|
+
static DEFAULT_AUTH_DIR = './test-results/auth';
|
|
14
|
+
/**
|
|
15
|
+
* 💾 Salva o estado completo de autenticação (cookies + localStorage + sessionStorage)
|
|
16
|
+
* @param page Página do Playwright
|
|
17
|
+
* @param filePath Caminho do arquivo para salvar (padrão: ./test-results/auth/auth-state.json)
|
|
18
|
+
*/
|
|
19
|
+
static async saveState(page, filePath) {
|
|
20
|
+
try {
|
|
21
|
+
const finalPath = filePath ||
|
|
22
|
+
path.join(AuthStateManager.DEFAULT_AUTH_DIR, 'auth-state.json');
|
|
23
|
+
// Garantir que o diretório existe
|
|
24
|
+
const dir = path.dirname(finalPath);
|
|
25
|
+
if (!fs.existsSync(dir)) {
|
|
26
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
// Coletar cookies do contexto
|
|
29
|
+
const context = page.context();
|
|
30
|
+
const cookies = await context.cookies();
|
|
31
|
+
// Coletar localStorage e sessionStorage da página
|
|
32
|
+
const storageData = await page.evaluate(() => {
|
|
33
|
+
const origins = [];
|
|
34
|
+
// Capturar origin atual
|
|
35
|
+
const origin = window.location.origin;
|
|
36
|
+
// Capturar localStorage
|
|
37
|
+
const localStorageItems = [];
|
|
38
|
+
for (let i = 0; i < window.localStorage.length; i++) {
|
|
39
|
+
const key = window.localStorage.key(i);
|
|
40
|
+
if (key) {
|
|
41
|
+
localStorageItems.push({
|
|
42
|
+
name: key,
|
|
43
|
+
value: window.localStorage.getItem(key) || '',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Capturar sessionStorage
|
|
48
|
+
const sessionStorageItems = [];
|
|
49
|
+
for (let i = 0; i < window.sessionStorage.length; i++) {
|
|
50
|
+
const key = window.sessionStorage.key(i);
|
|
51
|
+
if (key) {
|
|
52
|
+
sessionStorageItems.push({
|
|
53
|
+
name: key,
|
|
54
|
+
value: window.sessionStorage.getItem(key) || '',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
origins.push({
|
|
59
|
+
origin,
|
|
60
|
+
localStorage: localStorageItems,
|
|
61
|
+
sessionStorage: sessionStorageItems,
|
|
62
|
+
});
|
|
63
|
+
return origins;
|
|
64
|
+
});
|
|
65
|
+
// Capturar URL atual para referência
|
|
66
|
+
const currentUrl = page.url();
|
|
67
|
+
// Criar objeto de estado
|
|
68
|
+
const authState = {
|
|
69
|
+
cookies: cookies.map((cookie) => ({
|
|
70
|
+
name: cookie.name,
|
|
71
|
+
value: cookie.value,
|
|
72
|
+
domain: cookie.domain,
|
|
73
|
+
path: cookie.path,
|
|
74
|
+
expires: cookie.expires,
|
|
75
|
+
httpOnly: cookie.httpOnly,
|
|
76
|
+
secure: cookie.secure,
|
|
77
|
+
sameSite: cookie.sameSite,
|
|
78
|
+
})),
|
|
79
|
+
origins: storageData,
|
|
80
|
+
timestamp: new Date().toISOString(),
|
|
81
|
+
url: currentUrl,
|
|
82
|
+
};
|
|
83
|
+
// Salvar no arquivo
|
|
84
|
+
fs.writeFileSync(finalPath, JSON.stringify(authState, null, 2), 'utf-8');
|
|
85
|
+
Logger.success(`✅ Estado de autenticação salvo: ${finalPath}`);
|
|
86
|
+
Logger.info(` 📊 ${cookies.length} cookies, ${storageData.length} origins`);
|
|
87
|
+
return finalPath;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
Logger.error('❌ Erro ao salvar estado de autenticação', error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 🔄 Restaura o estado de autenticação salvo
|
|
96
|
+
* @param page Página do Playwright
|
|
97
|
+
* @param filePath Caminho do arquivo de estado
|
|
98
|
+
*/
|
|
99
|
+
static async restoreState(page, filePath) {
|
|
100
|
+
try {
|
|
101
|
+
const finalPath = filePath ||
|
|
102
|
+
path.join(AuthStateManager.DEFAULT_AUTH_DIR, 'auth-state.json');
|
|
103
|
+
if (!fs.existsSync(finalPath)) {
|
|
104
|
+
throw new Error(`Arquivo de estado não encontrado: ${finalPath}`);
|
|
105
|
+
}
|
|
106
|
+
// Ler estado do arquivo
|
|
107
|
+
const fileContent = fs.readFileSync(finalPath, 'utf-8');
|
|
108
|
+
const authState = JSON.parse(fileContent);
|
|
109
|
+
// Restaurar cookies no contexto
|
|
110
|
+
const context = page.context();
|
|
111
|
+
await context.addCookies(authState.cookies);
|
|
112
|
+
// Restaurar localStorage e sessionStorage
|
|
113
|
+
for (const originData of authState.origins) {
|
|
114
|
+
// Navegar para a origem se necessário
|
|
115
|
+
if (!page.url().startsWith(originData.origin)) {
|
|
116
|
+
await page.goto(originData.origin);
|
|
117
|
+
}
|
|
118
|
+
// Restaurar localStorage
|
|
119
|
+
if (originData.localStorage && originData.localStorage.length > 0) {
|
|
120
|
+
await page.evaluate((items) => {
|
|
121
|
+
for (const item of items) {
|
|
122
|
+
window.localStorage.setItem(item.name, item.value);
|
|
123
|
+
}
|
|
124
|
+
}, originData.localStorage);
|
|
125
|
+
}
|
|
126
|
+
// Restaurar sessionStorage
|
|
127
|
+
if (originData.sessionStorage && originData.sessionStorage.length > 0) {
|
|
128
|
+
await page.evaluate((items) => {
|
|
129
|
+
for (const item of items) {
|
|
130
|
+
window.sessionStorage.setItem(item.name, item.value);
|
|
131
|
+
}
|
|
132
|
+
}, originData.sessionStorage);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
Logger.success(`✅ Estado de autenticação restaurado: ${finalPath}`);
|
|
136
|
+
Logger.info(` 📊 ${authState.cookies.length} cookies, ${authState.origins.length} origins`);
|
|
137
|
+
Logger.info(` 🕐 Salvo em: ${authState.timestamp}`);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
Logger.error('❌ Erro ao restaurar estado de autenticação', error);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 🧹 Limpa todo o estado de autenticação (cookies + localStorage + sessionStorage)
|
|
146
|
+
* @param page Página do Playwright
|
|
147
|
+
*/
|
|
148
|
+
static async clearState(page) {
|
|
149
|
+
try {
|
|
150
|
+
// Limpar cookies do contexto
|
|
151
|
+
const context = page.context();
|
|
152
|
+
await context.clearCookies();
|
|
153
|
+
// Limpar localStorage e sessionStorage
|
|
154
|
+
await page.evaluate(() => {
|
|
155
|
+
window.localStorage.clear();
|
|
156
|
+
window.sessionStorage.clear();
|
|
157
|
+
});
|
|
158
|
+
Logger.success('✅ Estado de autenticação limpo');
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
Logger.error('❌ Erro ao limpar estado de autenticação', error);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 📄 Verifica se um arquivo de estado existe
|
|
167
|
+
* @param filePath Caminho do arquivo
|
|
168
|
+
*/
|
|
169
|
+
static stateExists(filePath) {
|
|
170
|
+
const finalPath = filePath ||
|
|
171
|
+
path.join(AuthStateManager.DEFAULT_AUTH_DIR, 'auth-state.json');
|
|
172
|
+
return fs.existsSync(finalPath);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 🔍 Lê e retorna o estado sem aplicar
|
|
176
|
+
* @param filePath Caminho do arquivo
|
|
177
|
+
*/
|
|
178
|
+
static readState(filePath) {
|
|
179
|
+
try {
|
|
180
|
+
const finalPath = filePath ||
|
|
181
|
+
path.join(AuthStateManager.DEFAULT_AUTH_DIR, 'auth-state.json');
|
|
182
|
+
if (!fs.existsSync(finalPath)) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const fileContent = fs.readFileSync(finalPath, 'utf-8');
|
|
186
|
+
return JSON.parse(fileContent);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
Logger.error('❌ Erro ao ler estado de autenticação', error);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 🗑️ Remove o arquivo de estado
|
|
195
|
+
* @param filePath Caminho do arquivo
|
|
196
|
+
*/
|
|
197
|
+
static deleteState(filePath) {
|
|
198
|
+
try {
|
|
199
|
+
const finalPath = filePath ||
|
|
200
|
+
path.join(AuthStateManager.DEFAULT_AUTH_DIR, 'auth-state.json');
|
|
201
|
+
if (fs.existsSync(finalPath)) {
|
|
202
|
+
fs.unlinkSync(finalPath);
|
|
203
|
+
Logger.success(`✅ Arquivo de estado removido: ${finalPath}`);
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
Logger.error('❌ Erro ao remover estado de autenticação', error);
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 📋 Lista todos os arquivos de estado no diretório padrão
|
|
215
|
+
*/
|
|
216
|
+
static listStates() {
|
|
217
|
+
try {
|
|
218
|
+
const dir = AuthStateManager.DEFAULT_AUTH_DIR;
|
|
219
|
+
if (!fs.existsSync(dir)) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const files = fs.readdirSync(dir);
|
|
223
|
+
return files
|
|
224
|
+
.filter((file) => file.endsWith('.json'))
|
|
225
|
+
.map((file) => path.join(dir, file));
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
Logger.error('❌ Erro ao listar estados', error);
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* 🔐 Salva estado usando o contexto do Playwright diretamente (método alternativo)
|
|
234
|
+
* @param context Contexto do navegador
|
|
235
|
+
* @param filePath Caminho do arquivo
|
|
236
|
+
*/
|
|
237
|
+
static async saveContextState(context, filePath) {
|
|
238
|
+
try {
|
|
239
|
+
const finalPath = filePath ||
|
|
240
|
+
path.join(AuthStateManager.DEFAULT_AUTH_DIR, 'auth-state.json');
|
|
241
|
+
// Garantir que o diretório existe
|
|
242
|
+
const dir = path.dirname(finalPath);
|
|
243
|
+
if (!fs.existsSync(dir)) {
|
|
244
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
245
|
+
}
|
|
246
|
+
// Usar método nativo do Playwright
|
|
247
|
+
await context.storageState({ path: finalPath });
|
|
248
|
+
Logger.success(`✅ Estado de contexto salvo: ${finalPath}`);
|
|
249
|
+
return finalPath;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
Logger.error('❌ Erro ao salvar estado de contexto', error);
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🤖 SISTEMA DE COVERAGE AUTOMÁTICO - AutoCore Framework
|
|
3
|
+
*
|
|
4
|
+
* ✅ FUNCIONAMENTO TRANSPARENTE:
|
|
5
|
+
* - Detecta automaticamente tipo de projeto (Playwright/Vitest/Mixed)
|
|
6
|
+
* - Hook automático em tests Vitest via globalSetup/globalTeardown
|
|
7
|
+
* - Hook automático em tests Playwright via beforeEach/afterEach
|
|
8
|
+
* - Usuário não precisa adicionar NENHUMA linha de código
|
|
9
|
+
* - Gera estrutura completa de coverage automaticamente
|
|
10
|
+
*
|
|
11
|
+
* 📁 ARQUIVOS GERADOS AUTOMATICAMENTE:
|
|
12
|
+
* - coverage/index.html (Dashboard visual)
|
|
13
|
+
* - coverage/coverage-final.json (Standard)
|
|
14
|
+
* - coverage/coverage-summary.json (Standard)
|
|
15
|
+
* - coverage/lcov.info (IDE integration)
|
|
16
|
+
* - coverage/autocore-coverage-report.json (Detalhado)
|
|
17
|
+
* - coverage/autocore-coverage-summary.json (Resumo)
|
|
18
|
+
*/
|
|
19
|
+
import type { IPage } from '../interfaces.js';
|
|
20
|
+
export interface CoverageData {
|
|
21
|
+
frontend?: {
|
|
22
|
+
js?: any[];
|
|
23
|
+
css?: any[];
|
|
24
|
+
timestamp?: Date;
|
|
25
|
+
};
|
|
26
|
+
vitest?: {
|
|
27
|
+
lines?: {
|
|
28
|
+
total: number;
|
|
29
|
+
covered: number;
|
|
30
|
+
skipped: number;
|
|
31
|
+
pct: number;
|
|
32
|
+
};
|
|
33
|
+
functions?: {
|
|
34
|
+
total: number;
|
|
35
|
+
covered: number;
|
|
36
|
+
skipped: number;
|
|
37
|
+
pct: number;
|
|
38
|
+
};
|
|
39
|
+
statements?: {
|
|
40
|
+
total: number;
|
|
41
|
+
covered: number;
|
|
42
|
+
skipped: number;
|
|
43
|
+
pct: number;
|
|
44
|
+
};
|
|
45
|
+
branches?: {
|
|
46
|
+
total: number;
|
|
47
|
+
covered: number;
|
|
48
|
+
skipped: number;
|
|
49
|
+
pct: number;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
summary?: {
|
|
53
|
+
totalCoverage: number;
|
|
54
|
+
frontendEnabled: boolean;
|
|
55
|
+
vitestEnabled: boolean;
|
|
56
|
+
projectType: 'playwright' | 'vitest' | 'mixed';
|
|
57
|
+
timestamp: Date;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface TestCoverageMetrics {
|
|
61
|
+
testName: string;
|
|
62
|
+
testType: 'Frontend' | 'API' | 'Mobile' | 'SSH' | 'Banco' | 'Mixed';
|
|
63
|
+
coverage: CoverageData;
|
|
64
|
+
duration: number;
|
|
65
|
+
timestamp: Date;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 🤖 SISTEMA DE COVERAGE AUTOMÁTICO - AutoCore Framework
|
|
69
|
+
*/
|
|
70
|
+
export declare class CoverageManager {
|
|
71
|
+
private static instance;
|
|
72
|
+
private static coverageData;
|
|
73
|
+
private static globalCoverage;
|
|
74
|
+
private static outputDir;
|
|
75
|
+
private static isInitialized;
|
|
76
|
+
private static currentTestPage;
|
|
77
|
+
private static coverageWarningShown;
|
|
78
|
+
static getInstance(): CoverageManager;
|
|
79
|
+
/**
|
|
80
|
+
* 🤖 INICIALIZAÇÃO AUTOMÁTICA - Chamado pelo global-setup.ts
|
|
81
|
+
*/
|
|
82
|
+
static autoInitialize(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* ✅ NOVO: Limpa arquivos de coverage antigos para Playwright
|
|
85
|
+
*/
|
|
86
|
+
private static cleanupOldCoverageFiles;
|
|
87
|
+
/**
|
|
88
|
+
* 🎯 Setup unificado para hooks
|
|
89
|
+
*/
|
|
90
|
+
private static setupPlaywrightHooks;
|
|
91
|
+
private static setupVitestHooks;
|
|
92
|
+
private static setupProcessHooks;
|
|
93
|
+
/**
|
|
94
|
+
* 🔍 Tenta capturar coverage automaticamente sem interferir nos testes
|
|
95
|
+
*/
|
|
96
|
+
private static tryAutoCapture;
|
|
97
|
+
/**
|
|
98
|
+
* 📸 Captura teste atual automaticamente
|
|
99
|
+
*/
|
|
100
|
+
private static captureCurrentTest;
|
|
101
|
+
/**
|
|
102
|
+
* 🔍 Detecta nome do teste atual automaticamente
|
|
103
|
+
*/
|
|
104
|
+
private static getCurrentTestName;
|
|
105
|
+
/**
|
|
106
|
+
* 🔗 Registra page automaticamente (chamado pelo framework)
|
|
107
|
+
* O usuário não chama isso - é automático via hooks internos
|
|
108
|
+
*/
|
|
109
|
+
static registerPageAutomatically(page: IPage): void;
|
|
110
|
+
/**
|
|
111
|
+
* 🏁 Finalização automática - chamado pelos hooks
|
|
112
|
+
*/
|
|
113
|
+
static autoFinalize(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* 🔄 NOVO: Reset dados estáticos para nova execução
|
|
116
|
+
*/
|
|
117
|
+
private static resetForNewExecution;
|
|
118
|
+
/**
|
|
119
|
+
* 🔍 Detecta o tipo de projeto automaticamente
|
|
120
|
+
*/
|
|
121
|
+
static detectProjectType(): 'playwright' | 'vitest' | 'mixed';
|
|
122
|
+
/**
|
|
123
|
+
* 🔍 Verifica se existem testes Playwright (.spec.ts)
|
|
124
|
+
*/
|
|
125
|
+
private static hasPlaywrightTests;
|
|
126
|
+
/**
|
|
127
|
+
* 🔍 Verifica se existe configuração Vitest
|
|
128
|
+
*/
|
|
129
|
+
private static hasVitestConfig;
|
|
130
|
+
/**
|
|
131
|
+
* 🔍 Verifica se existem testes Vitest na pasta tests/unit
|
|
132
|
+
*/
|
|
133
|
+
private static hasVitestTests;
|
|
134
|
+
/**
|
|
135
|
+
* 🔍 Busca arquivos recursivamente por padrão
|
|
136
|
+
*/
|
|
137
|
+
private static findFilesRecursive;
|
|
138
|
+
/**
|
|
139
|
+
* ✅ NOVO: Inicia cobertura para teste Frontend
|
|
140
|
+
*/
|
|
141
|
+
static startFrontendCoverage(page: IPage, testName: string): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* ✅ NOVO: Para cobertura Frontend e coleta dados
|
|
144
|
+
*/
|
|
145
|
+
static stopFrontendCoverage(page: IPage, testName: string): Promise<CoverageData['frontend']>;
|
|
146
|
+
/**
|
|
147
|
+
* ✅ NOVO: Coleta cobertura do Vitest de forma inteligente
|
|
148
|
+
*/
|
|
149
|
+
static collectVitestCoverage(): Promise<CoverageData['vitest']>;
|
|
150
|
+
/**
|
|
151
|
+
* ✅ NOVO: Registra cobertura completa de um teste
|
|
152
|
+
*/
|
|
153
|
+
static registerTestCoverage(testName: string, testType: 'Frontend' | 'API' | 'Mobile' | 'SSH' | 'Banco' | 'Mixed', page?: IPage, duration?: number): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* 🎭 NOVO: Gera métricas para testes Playwright puros
|
|
156
|
+
*/
|
|
157
|
+
private static generatePlaywrightTestMetrics;
|
|
158
|
+
/**
|
|
159
|
+
* ✅ NOVO: Atualiza cobertura global
|
|
160
|
+
*/
|
|
161
|
+
private static updateGlobalCoverage;
|
|
162
|
+
/**
|
|
163
|
+
* ✅ NOVO: Salva relatório de cobertura
|
|
164
|
+
*/
|
|
165
|
+
static saveCoverageReport(): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* 📁 NOVO: Gera arquivos de cobertura padrão para projeto consumidor
|
|
168
|
+
*/
|
|
169
|
+
private static generateStandardCoverageFiles;
|
|
170
|
+
/**
|
|
171
|
+
* 📄 Gera formato LCOV
|
|
172
|
+
*/
|
|
173
|
+
private static generateLcovFormat;
|
|
174
|
+
/**
|
|
175
|
+
* 📄 Gera HTML básico para cobertura
|
|
176
|
+
*/
|
|
177
|
+
private static generateCoverageHtml;
|
|
178
|
+
/**
|
|
179
|
+
* Obtém versão do framework
|
|
180
|
+
*/
|
|
181
|
+
private static getFrameworkVersion;
|
|
182
|
+
/**
|
|
183
|
+
* ✅ PÚBLICO: Obtém cobertura global
|
|
184
|
+
*/
|
|
185
|
+
static getGlobalCoverage(): CoverageData;
|
|
186
|
+
/**
|
|
187
|
+
* ✅ PÚBLICO: Obtém cobertura de um teste específico
|
|
188
|
+
*/
|
|
189
|
+
static getTestCoverage(testName: string): TestCoverageMetrics | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* ✅ PÚBLICO: Obtém todas as coberturas de teste
|
|
192
|
+
*/
|
|
193
|
+
static getAllTestsCoverage(): TestCoverageMetrics[];
|
|
194
|
+
/**
|
|
195
|
+
* ✅ PÚBLICO: Reset para testes
|
|
196
|
+
*/
|
|
197
|
+
static reset(): void;
|
|
198
|
+
}
|