Unverified Commit 5a3e1004 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] Add test that "Unresolve URI" warnings from DWDS are filtered from logs (#102399)

parent a3a9a23e
......@@ -275,7 +275,7 @@ class WebAssetServer implements AssetReader {
}
logging.Logger.root.level = logging.Level.ALL;
logging.Logger.root.onRecord.listen(_log);
logging.Logger.root.onRecord.listen(log);
// In debug builds, spin up DWDS and the full asset server.
final Dwds dwds = await dwdsLauncher(
......@@ -1004,7 +1004,8 @@ class ReleaseAssetServer {
}
}
void _log(logging.LogRecord event) {
@visibleForTesting
void log(logging.LogRecord event) {
final String error = event.error == null? '': 'Error: ${event.error}';
if (event.level >= logging.Level.SEVERE) {
globals.printError('${event.loggerName}: ${event.message}$error', stackTrace: event.stackTrace);
......
......@@ -8,6 +8,7 @@ import 'dart:io' hide Directory, File;
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/targets/web.dart';
......@@ -16,6 +17,7 @@ import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:flutter_tools/src/web/compile.dart';
import 'package:logging/logging.dart' as logging;
import 'package:package_config/package_config.dart';
import 'package:shelf/shelf.dart';
import 'package:test/fake.dart';
......@@ -39,6 +41,7 @@ void main() {
PackageConfig packages;
Platform windows;
FakeHttpServer httpServer;
BufferLogger logger;
setUpAll(() async {
packages = PackageConfig(<Package>[
......@@ -50,6 +53,7 @@ void main() {
httpServer = FakeHttpServer();
linux = FakePlatform(environment: <String, String>{});
windows = FakePlatform(operatingSystem: 'windows', environment: <String, String>{});
logger = BufferLogger.test();
testbed = Testbed(setup: () {
webAssetServer = WebAssetServer(
httpServer,
......@@ -67,9 +71,35 @@ void main() {
webBuildDirectory: null,
basePath: null,
);
}, overrides: <Type, Generator>{
Logger: () => logger,
});
});
test('.log() filters events', () => testbed.run(() {
// harmless warning that should be filtered out
const String harmlessMessage = 'Unresolved uri: dart:ui';
// serious warning
const String seriousMessage = 'Something bad happened';
final List<logging.LogRecord> events = <logging.LogRecord>[
logging.LogRecord(
logging.Level.WARNING,
harmlessMessage,
'DartUri',
),
logging.LogRecord(
logging.Level.WARNING,
seriousMessage,
'DartUri',
),
];
events.forEach(log);
expect(logger.warningText, contains(seriousMessage));
expect(logger.warningText, isNot(contains(harmlessMessage)));
}));
test('Handles against malformed manifest', () => testbed.run(() async {
final File source = globals.fs.file('source')
..writeAsStringSync('main() {}');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment