Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: Add some tests for logging
  • Loading branch information
ValentinVignal committed Sep 9, 2023
commit 41192e913abc927488cfc2977ad35bd5cf072b3a
61 changes: 57 additions & 4 deletions packages/go_router/test/logging_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,70 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:go_router/src/logging.dart';
import 'package:logging/logging.dart';

void main() {
test('setLogging does not clear listeners', () {
log.onRecord
.listen(expectAsync1<void, LogRecord>((LogRecord r) {}, count: 2));
final StreamSubscription<LogRecord> subscription = logger.onRecord.listen(
expectAsync1<void, LogRecord>((LogRecord r) {}, count: 2),
);
addTearDown(subscription.cancel);

setLogging(enabled: true);
log.info('message');
logger.info('message');
setLogging();
log.info('message');
logger.info('message');
});

testWidgets(
'It should not log anything the if debugLogDiagnostics is false',
(WidgetTester tester) async {
final StreamSubscription<LogRecord> subscription =
Logger.root.onRecord.listen(
expectAsync1((LogRecord data) {}, count: 0),
);
addTearDown(subscription.cancel);
GoRouter(
routes: <RouteBase>[
GoRoute(
path: '/',
builder: (_, GoRouterState state) => const Text('home'),
),
],
);
},
);

testWidgets(
'It should not log the known routes and the initial route if debugLogDiagnostics is true',
(WidgetTester tester) async {
final List<String> logs = <String>[];
Logger.root.onRecord.listen(
(LogRecord event) => logs.add(event.message),
);
GoRouter(
debugLogDiagnostics: true,
routes: <RouteBase>[
GoRoute(
path: '/',
builder: (_, GoRouterState state) => const Text('home'),
),
],
);

expect(
logs,
const <String>[
'Full paths for routes:\n => /\n',
'setting initial location null'
],
);
},
);
}