Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bb24b49

Browse files
author
nturgut
authored
[web] Build unit tests with dart2js instead of build_runner (#20390)
* change from build_runner to dart2js * add internalBootstrapBrowserTest to some of the tests * add internalBootstrapBrowserTest to all remaining tests * make tests build in paralel. Total time dropped from 586 to 177 seconds for 8 core MacBook * change isolates with pool * fixing analysis errors * skipping canvaskit tests for ios-safari * copy image files to the build directory * adding internalBootstrapBrowserTest to newly added tests * add internalBootstrapBrowserTest to faling path iterator test * necessary changes to make chrome windows work * in windows test in chrome instead of edge. our edge code was for legacy edge * do not run golden unit tests on Windows LUCI bots for now * addressing reviewer comments. Adding a method for deciding when to run integration tests. * remove lines that I forgot to remove * fixing analysis error. add issue for todo * add bootstap to a test file * adding bootstrap to another test * add internalBootstrapBrowserTest to a golden test * return test result in bat file. use archieve package to unzip * fixing logs for chrome_installer * use archieve and archieve entity instead of dynamic * adding comments for windows platform archieve part * addressing reviewer comments * change readme file
1 parent 0fb3a8f commit bb24b49

File tree

93 files changed

+724
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+724
-204
lines changed

lib/web_ui/dev/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ felt build [-w] -j 100
4141

4242
If you are a Google employee, you can use an internal instance of Goma to parallelize your builds. Because Goma compiles code on remote servers, this option is effective even on low-powered laptops.
4343

44-
By default, when compiling Dart code to JavaScript, we use 4 `dart2js` workers.
45-
If you need to increase or reduce the number of workers, set the `BUILD_MAX_WORKERS_PER_TASK`
46-
environment variable to the desired number.
44+
By default, when compiling Dart code to JavaScript, we use 8 `dart2js` workers.
4745

4846
## Running web engine tests
4947

lib/web_ui/dev/browser_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ chrome:
55
# is not working with chrome.binary option.
66
Linux: 741412
77
Mac: 735194
8-
Win: 735105
8+
Win: 768975
99
firefox:
1010
version: '72.0'
1111
edge:

lib/web_ui/dev/chrome_installer.dart

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// found in the LICENSE file.
44

55
// @dart = 2.6
6+
import 'dart:async';
67
import 'dart:io' as io;
78

9+
import 'package:archive/archive.dart';
10+
import 'package:archive/archive_io.dart';
811
import 'package:args/args.dart';
912
import 'package:http/http.dart';
1013
import 'package:meta/meta.dart';
@@ -186,7 +189,7 @@ class ChromeInstaller {
186189
} else if (versionDir.existsSync() && isLuci) {
187190
print('INFO: Chrome version directory in LUCI: '
188191
'${versionDir.path}');
189-
} else if(!versionDir.existsSync() && isLuci) {
192+
} else if (!versionDir.existsSync() && isLuci) {
190193
// Chrome should have been deployed as a CIPD package on LUCI.
191194
// Throw if it does not exists.
192195
throw StateError('Failed to locate Chrome on LUCI on path:'
@@ -196,6 +199,8 @@ class ChromeInstaller {
196199
versionDir.createSync(recursive: true);
197200
}
198201

202+
print('INFO: Starting Chrome download.');
203+
199204
final String url = PlatformBinding.instance.getChromeDownloadUrl(version);
200205
final StreamedResponse download = await client.send(Request(
201206
'GET',
@@ -206,17 +211,50 @@ class ChromeInstaller {
206211
io.File(path.join(versionDir.path, 'chrome.zip'));
207212
await download.stream.pipe(downloadedFile.openWrite());
208213

209-
final io.ProcessResult unzipResult = await io.Process.run('unzip', <String>[
210-
downloadedFile.path,
211-
'-d',
212-
versionDir.path,
213-
]);
214-
215-
if (unzipResult.exitCode != 0) {
216-
throw BrowserInstallerException(
217-
'Failed to unzip the downloaded Chrome archive ${downloadedFile.path}.\n'
218-
'With the version path ${versionDir.path}\n'
219-
'The unzip process exited with code ${unzipResult.exitCode}.');
214+
/// Windows LUCI bots does not have a `unzip`. Instead we are
215+
/// using `archive` pub package.
216+
///
217+
/// We didn't use `archieve` on Mac/Linux since the new files have
218+
/// permission issues. For now we are not able change file permissions
219+
/// from dart.
220+
/// See: https://github.com/dart-lang/sdk/issues/15078.
221+
if (io.Platform.isWindows) {
222+
final Stopwatch stopwatch = Stopwatch()..start();
223+
224+
// Read the Zip file from disk.
225+
final bytes = downloadedFile.readAsBytesSync();
226+
227+
final Archive archive = ZipDecoder().decodeBytes(bytes);
228+
229+
// Extract the contents of the Zip archive to disk.
230+
for (final ArchiveFile file in archive) {
231+
final String filename = file.name;
232+
if (file.isFile) {
233+
final data = file.content as List<int>;
234+
io.File(path.join(versionDir.path, filename))
235+
..createSync(recursive: true)
236+
..writeAsBytesSync(data);
237+
} else {
238+
io.Directory(path.join(versionDir.path, filename))
239+
..create(recursive: true);
240+
}
241+
}
242+
243+
stopwatch.stop();
244+
print('INFO: The unzip took ${stopwatch.elapsedMilliseconds ~/ 1000} seconds.');
245+
} else {
246+
final io.ProcessResult unzipResult =
247+
await io.Process.run('unzip', <String>[
248+
downloadedFile.path,
249+
'-d',
250+
versionDir.path,
251+
]);
252+
if (unzipResult.exitCode != 0) {
253+
throw BrowserInstallerException(
254+
'Failed to unzip the downloaded Chrome archive ${downloadedFile.path}.\n'
255+
'With the version path ${versionDir.path}\n'
256+
'The unzip process exited with code ${unzipResult.exitCode}.');
257+
}
220258
}
221259

222260
downloadedFile.deleteSync();

lib/web_ui/dev/common.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class _WindowsBinding implements PlatformBinding {
5959

6060
@override
6161
String getChromeDownloadUrl(String version) =>
62-
'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Win%2F${version}%2Fchrome-win32.zip?alt=media';
62+
'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Win%2F${version}%2Fchrome-win.zip?alt=media';
6363

6464
@override
6565
String getChromeExecutablePath(io.Directory versionDir) =>
66-
path.join(versionDir.path, 'chrome-win32', 'chrome');
66+
path.join(versionDir.path, 'chrome-win', 'chrome.exe');
6767

6868
@override
6969
String getFirefoxDownloadUrl(String version) =>

lib/web_ui/dev/felt_windows.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ IF %orTempValue%==0 (
5757
:: TODO(nurhan): The batch script does not support snanphot option.
5858
:: Support snapshot option.
5959
CALL :installdeps
60-
IF %1==test (%DART_SDK_DIR%\bin\dart "%DEV_DIR%\felt.dart" %* --browser=edge) ELSE ( %DART_SDK_DIR%\bin\dart "%DEV_DIR%\felt.dart" %* )
60+
IF %1==test (%DART_SDK_DIR%\bin\dart "%DEV_DIR%\felt.dart" %* --browser=chrome) ELSE ( %DART_SDK_DIR%\bin\dart "%DEV_DIR%\felt.dart" %* )
6161

62-
EXIT /B 0
62+
EXIT /B %ERRORLEVEL%
6363

6464
:installdeps
6565
ECHO "Running \`pub get\` in 'engine/src/flutter/web_sdk/web_engine_tester'"
6666
cd "%FLUTTER_DIR%web_sdk\web_engine_tester"
6767
CALL %PUB_DIR% get
6868
ECHO "Running \`pub get\` in 'engine/src/flutter/lib/web_ui'"
69-
cd %WEB_UI_DIR%
69+
cd %WEB_UI_DIR%
7070
CALL %PUB_DIR% get
7171
EXIT /B 0

lib/web_ui/dev/test_platform.dart

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import 'package:test_core/src/runner/environment.dart'; // ignore: implementatio
3434

3535
import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
3636
import 'package:test_core/src/runner/configuration.dart'; // ignore: implementation_imports
37-
import 'package:test_core/src/runner/load_exception.dart'; // ignore: implementation_imports
3837
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
3938
as wip;
4039

@@ -407,15 +406,6 @@ Golden file $filename did not match the image generated by the test.
407406
throw ArgumentError('$browser is not a browser.');
408407
}
409408

410-
var htmlPath = p.withoutExtension(path) + '.html';
411-
if (File(htmlPath).existsSync() &&
412-
!File(htmlPath).readAsStringSync().contains('packages/test/dart.js')) {
413-
throw LoadException(
414-
path,
415-
'"${htmlPath}" must contain <script src="packages/test/dart.js">'
416-
'</script>.');
417-
}
418-
419409
if (_closed) {
420410
return null;
421411
}
@@ -811,15 +801,18 @@ class BrowserManager {
811801
controller = deserializeSuite(path, currentPlatform(_runtime),
812802
suiteConfig, await _environment, suiteChannel, message);
813803

814-
final String mapPath = p.join(
815-
env.environment.webUiRootDir.path,
816-
'build',
817-
'$path.browser_test.dart.js.map',
818-
);
819-
PackageConfig packageConfig = await loadPackageConfigUri(
820-
await Isolate.packageConfig);
821-
Map<String, Uri> packageMap =
822-
{for (var p in packageConfig.packages) p.name: p.packageUriRoot};
804+
final String sourceMapFileName =
805+
'${p.basename(path)}.browser_test.dart.js.map';
806+
final String pathToTest = p.dirname(path);
807+
808+
final String mapPath = p.join(env.environment.webUiRootDir.path,
809+
'build', pathToTest, sourceMapFileName);
810+
811+
PackageConfig packageConfig =
812+
await loadPackageConfigUri(await Isolate.packageConfig);
813+
Map<String, Uri> packageMap = {
814+
for (var p in packageConfig.packages) p.name: p.packageUriRoot
815+
};
823816
final JSStackTraceMapper mapper = JSStackTraceMapper(
824817
await File(mapPath).readAsString(),
825818
mapUrl: p.toUri(mapPath),

0 commit comments

Comments
 (0)