mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 02:07:00 +08:00
Replace print with debugPrint and improve logging
Replaced print statements with debugPrint in tests for better Flutter logging practices. In js_runtime_notifier.dart, replaced print statements with structured logging via terminalStateProvider, providing more consistent and contextual log handling. Minor code style improvements were also made.
This commit is contained in:
@@ -50,7 +50,9 @@ class APIDashRequestDescription {
|
||||
if (bodyJSON != null) {
|
||||
getTyp(input, [i = 0]) {
|
||||
String indent = "\t";
|
||||
for (int j = 0; j < i; j++) indent += "\t";
|
||||
for (int j = 0; j < i; j++) {
|
||||
indent += "\t";
|
||||
}
|
||||
if (input.runtimeType.toString().toLowerCase().contains('map')) {
|
||||
String typd = '{';
|
||||
for (final z in input.keys) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// ignore_for_file: avoid_print
|
||||
import 'dart:convert';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -307,8 +306,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
||||
updateEnv?.call(originalEnvironmentModel, newValues);
|
||||
} else {
|
||||
if (scriptResult.updatedEnvironment.isNotEmpty) {
|
||||
print(
|
||||
'Warning: Pre-request script updated environment variables, but no active environment was selected to save them to.');
|
||||
final term = ref.read(terminalStateProvider.notifier);
|
||||
final msg =
|
||||
'Pre-request script updated environment variables, but no active environment was selected to save them to.';
|
||||
state = state.copyWith(lastError: msg);
|
||||
term.logJs(
|
||||
level: 'warn',
|
||||
args: [msg],
|
||||
context: 'preRequest',
|
||||
contextRequestId: requestModel.id,
|
||||
);
|
||||
return requestModel;
|
||||
}
|
||||
return newRequestModel;
|
||||
@@ -359,8 +366,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
||||
updateEnv?.call(originalEnvironmentModel, newValues);
|
||||
} else {
|
||||
if (scriptResult.updatedEnvironment.isNotEmpty) {
|
||||
print(
|
||||
'Warning: Post-response script updated environment variables, but no active environment was selected to save them to.');
|
||||
final term = ref.read(terminalStateProvider.notifier);
|
||||
final msg =
|
||||
'Post-response script updated environment variables, but no active environment was selected to save them to.';
|
||||
state = state.copyWith(lastError: msg);
|
||||
term.logJs(
|
||||
level: 'warn',
|
||||
args: [msg],
|
||||
context: 'postResponse',
|
||||
contextRequestId: requestModel.id,
|
||||
);
|
||||
}
|
||||
return requestModel;
|
||||
}
|
||||
@@ -375,8 +390,8 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
||||
}
|
||||
|
||||
void _handleConsole(String level, dynamic args) {
|
||||
try {
|
||||
final term = ref.read(terminalStateProvider.notifier);
|
||||
try {
|
||||
List<String> argList = const <String>[];
|
||||
if (args is List) {
|
||||
argList = args.map((e) => e.toString()).toList();
|
||||
@@ -398,13 +413,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
||||
term.logJs(
|
||||
level: level, args: argList, contextRequestId: _currentRequestId);
|
||||
} catch (e) {
|
||||
print('[JS ${level.toUpperCase()} HANDLER ERROR]: $args, Error: $e');
|
||||
term.logSystem(
|
||||
category: 'provider',
|
||||
message:
|
||||
'[JS ${level.toUpperCase()} HANDLER ERROR]: $args, Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void _handleFatal(dynamic args) {
|
||||
try {
|
||||
final term = ref.read(terminalStateProvider.notifier);
|
||||
try {
|
||||
if (args is Map<String, dynamic>) {
|
||||
final message = args['message']?.toString() ?? 'Unknown fatal error';
|
||||
final error = args['error']?.toString();
|
||||
@@ -424,7 +442,9 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
||||
contextRequestId: _currentRequestId);
|
||||
}
|
||||
} catch (e) {
|
||||
print('[JS FATAL ERROR decoding error]: $args, Error: $e');
|
||||
term.logSystem(
|
||||
category: 'provider',
|
||||
message: '[JS FATAL ERROR decoding error]: $args, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,9 +746,10 @@ void main() {
|
||||
|
||||
// First verify we can find String popup menus
|
||||
final stringPopupMenus = find.byType(ADPopupMenu<String>);
|
||||
print('Found ${stringPopupMenus.evaluate().length} String popup menus');
|
||||
debugPrint(
|
||||
'Found ${stringPopupMenus.evaluate().length} String popup menus');
|
||||
|
||||
if (stringPopupMenus.evaluate().length > 0) {
|
||||
if (stringPopupMenus.evaluate().isNotEmpty) {
|
||||
// Find the code challenge method dropdown
|
||||
final codeChallengeDropdown = stringPopupMenus.first;
|
||||
await tester.tap(codeChallengeDropdown);
|
||||
@@ -756,7 +757,7 @@ void main() {
|
||||
|
||||
// Try to find and tap plaintext option
|
||||
final plaintextOption = find.text('Plaintext');
|
||||
if (plaintextOption.evaluate().length > 0) {
|
||||
if (plaintextOption.evaluate().isNotEmpty) {
|
||||
await tester.tap(plaintextOption.first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -852,19 +853,19 @@ void main() {
|
||||
|
||||
// Debug: Print all text widgets to see what's available
|
||||
final allText = find.byType(Text);
|
||||
print('Found ${allText.evaluate().length} Text widgets');
|
||||
debugPrint('Found ${allText.evaluate().length} Text widgets');
|
||||
|
||||
// Try to find any button-like widget
|
||||
final allButtons = find.byType(ADTextButton);
|
||||
print('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
||||
debugPrint('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
||||
|
||||
// Look for the specific text content
|
||||
final clearText = find.text('Clear OAuth2 Session');
|
||||
print(
|
||||
debugPrint(
|
||||
'Found ${clearText.evaluate().length} widgets with Clear OAuth2 Session text');
|
||||
|
||||
// If we can find the clear button text, tap it
|
||||
if (clearText.evaluate().length > 0) {
|
||||
if (clearText.evaluate().isNotEmpty) {
|
||||
await tester.tap(clearText.first);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
@@ -1296,10 +1297,10 @@ void main() {
|
||||
|
||||
// Debug: Look for all buttons and text widgets
|
||||
final allButtons = find.byType(ADTextButton);
|
||||
print('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
||||
debugPrint('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
||||
|
||||
final allText = find.byType(Text);
|
||||
print('Found ${allText.evaluate().length} Text widgets');
|
||||
debugPrint('Found ${allText.evaluate().length} Text widgets');
|
||||
|
||||
// Try finding the button widget itself
|
||||
if (allButtons.evaluate().isNotEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user