@fluwa-tool/sdk 1.0.34 → 1.0.36
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.
|
@@ -115,6 +115,10 @@ class FetchInterceptor {
|
|
|
115
115
|
requestMetadata.source = types_1.RequestSource.MOCK;
|
|
116
116
|
requestMetadata.response = mockResponse.response;
|
|
117
117
|
requestMetadata.status = mockResponse.status;
|
|
118
|
+
this.logger.debug(`✅ Retornando mock para ${method} ${url}`, {
|
|
119
|
+
status: mockResponse.status,
|
|
120
|
+
response: mockResponse.response
|
|
121
|
+
});
|
|
118
122
|
// Aplicar delay se configurado
|
|
119
123
|
if (mockResponse.delay) {
|
|
120
124
|
await this.delay(mockResponse.delay);
|
|
@@ -124,11 +128,16 @@ class FetchInterceptor {
|
|
|
124
128
|
// Registrar completamento
|
|
125
129
|
await this.requestLogger.logComplete(requestMetadata);
|
|
126
130
|
// Retornar mock como Response
|
|
127
|
-
|
|
131
|
+
const mockResponseObj = new Response(JSON.stringify(mockResponse.response), {
|
|
128
132
|
status: mockResponse.status || 200,
|
|
129
133
|
statusText: 'Mock',
|
|
130
134
|
headers: { 'Content-Type': 'application/json' },
|
|
131
135
|
});
|
|
136
|
+
this.logger.debug(`📤 Mock Response criada:`, {
|
|
137
|
+
status: mockResponseObj.status,
|
|
138
|
+
statusText: mockResponseObj.statusText
|
|
139
|
+
});
|
|
140
|
+
return mockResponseObj;
|
|
132
141
|
}
|
|
133
142
|
// Fazer request real
|
|
134
143
|
const response = await this.originalFetch.apply(globalThis, args);
|
|
@@ -97,9 +97,6 @@ class XMLHttpRequestInterceptor {
|
|
|
97
97
|
// Simular a resposta mockada assincronamente
|
|
98
98
|
setTimeout(() => {
|
|
99
99
|
try {
|
|
100
|
-
// Simular readyState = 4 (completo)
|
|
101
|
-
// Criar um evento fake que faz parecer que a resposta chegou
|
|
102
|
-
const mockEvent = new Event('readystatechange');
|
|
103
100
|
// Injetar dados fake no xhr para simular resposta
|
|
104
101
|
Object.defineProperty(xhr, 'readyState', {
|
|
105
102
|
value: 4,
|
|
@@ -126,8 +123,9 @@ class XMLHttpRequestInterceptor {
|
|
|
126
123
|
// Registrar completamento do mock
|
|
127
124
|
self.requestLogger.logComplete(requestMetadata).catch(() => { });
|
|
128
125
|
// Chamar handler original para processar a "resposta"
|
|
126
|
+
// Sem Event object (React Native não suporta)
|
|
129
127
|
if (originalOnReadyStateChange) {
|
|
130
|
-
originalOnReadyStateChange.call(xhr
|
|
128
|
+
originalOnReadyStateChange.call(xhr);
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
catch (error) {
|