未验证 提交 6b09714a 编写于 作者: F Ferhat 提交者: GitHub

Add regression test for treeshaking debugFillProperties (#17325)

* Add test to make sure we don't regress treeshaking of debugFillProperties
* update cirrus
上级 e9f96e59
......@@ -156,6 +156,7 @@ task:
- $FRAMEWORK_PATH/flutter/bin/flutter config --local-engine=host_debug_unopt --no-analytics --enable-web
- $FRAMEWORK_PATH/flutter/bin/flutter pub get --local-engine=host_debug_unopt
- $FRAMEWORK_PATH/flutter/bin/flutter drive -v --target=test_driver/text_editing_e2e.dart -d web-server --release --browser-name=chrome --local-engine=host_debug_unopt
- $FRAMEWORK_PATH/flutter/bin/flutter drive -v --target=test_driver/treeshaking_e2e.dart -d web-server --profile --browser-name=chrome --local-engine=host_debug_unopt
- $FRAMEWORK_PATH/flutter/bin/flutter drive -v --target=test_driver/image_loading_e2e.dart -d web-server --release --browser-name=chrome --local-engine=host_debug_unopt
- name: build_and_test_web_linux_firefox
......
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
key: const Key('mainapp'),
title: 'Integration Test App',
home: MyHomePage(title: 'Integration Test App'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final TextEditingController _controller =
TextEditingController(text: 'TreeshakingThings1');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: const Center(
child: Text('TreeshakingThings'),
),
);
}
}
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'package:flutter_test/flutter_test.dart';
import 'package:regular_integration_tests/treeshaking_main.dart' as app;
import 'package:flutter/material.dart';
import 'package:e2e/e2e.dart';
void main() {
E2EWidgetsFlutterBinding.ensureInitialized() as E2EWidgetsFlutterBinding;
testWidgets('debug+Fill+Properties for widgets is tree shaken',
(WidgetTester tester) async {
// About 11 instances are used by DiagnosticsNode and diagnostics
// for flutter framework itself. Widgets have > 100. So we check for 20 to
// so this test fails when tree-shaking is broken.
await testOccurenceCountBelow(tester, '${debugPrefix}FillProperties', 20);
});
}
// Used to prevent compiler optimization that will generate const string.
// Preventing counting test strings.
String get debugPrefix => <String>['d','e','b','u','g'].join('');
Future<void> testOccurenceCountBelow(WidgetTester tester, String methodName, int count) async {
app.main();
await tester.pumpAndSettle();
// Make sure app loaded.
final Finder finder = find.byKey(const Key('mainapp'));
expect(finder, findsOneWidget);
await _loadBundleAndCheck(methodName, count);
}
String fileContents;
Future<void> _loadBundleAndCheck(String methodName, int count) async {
fileContents ??= await html.HttpRequest.getString('main.dart.js');
expect(fileContents, contains('RenderObjectToWidgetElement'));
expect(occurrenceCount(fileContents, methodName), lessThan(count));
}
int occurrenceCount(String contents, String word) {
int count = 0;
final int wordLength = word.length;
int pos = contents.indexOf(word);
final int contentLength = contents.length;
while (pos != -1) {
++count;
pos += wordLength;
if (pos >= contentLength || count > 100) {
break;
}
pos = contents.indexOf(word, pos);
}
return count;
}
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:e2e/e2e_driver.dart' as e2e;
Future<void> main() async => e2e.main();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册