diff --git a/dwds/test/integration/fixtures/context.dart b/dwds/test/integration/fixtures/context.dart index ebf7bb654..c799a1381 100644 --- a/dwds/test/integration/fixtures/context.dart +++ b/dwds/test/integration/fixtures/context.dart @@ -252,11 +252,11 @@ class TestContext { var filePathToServe = project.filePathToServe; // Start the HTTP server and save its used port. - final httpServer = await startHttpServer('localhost'); + final httpServer = await startHttpServer('127.0.0.1'); _port = httpServer.port; final reloadedSourcesUri = Uri.parse( - 'http://localhost:$_port/${WebDevFS.reloadedSourcesFileName}', + 'http://127.0.0.1:$_port/${WebDevFS.reloadedSourcesFileName}', ); switch (testSettings.compilationMode) { @@ -332,7 +332,7 @@ class TestContext { if (testSettings.enableExpressionEvaluation) { ddcService = ExpressionCompilerService( - 'localhost', + '127.0.0.1', _port!, verbose: testSettings.verboseCompiler, sdkConfigurationProvider: sdkConfigurationProvider, @@ -518,7 +518,7 @@ class TestContext { if (testSettings.enableExpressionEvaluation) { ddcService = ExpressionCompilerService( - 'localhost', + '127.0.0.1', _port!, verbose: testSettings.verboseCompiler, sdkConfigurationProvider: sdkConfigurationProvider, @@ -595,7 +595,7 @@ class TestContext { // listeners in DWDS or `main` is run. final tabConnectionCompleter = Completer(); final appConnectionCompleter = Completer(); - final connection = ChromeConnection('localhost', debugPort); + final connection = ChromeConnection('127.0.0.1', debugPort); // TODO(srujzs): In the case of the frontend server, it doesn't make sense // that we initialize a new HTTP server instead of reusing the one in @@ -632,8 +632,8 @@ class TestContext { }); _appUrl = basePath.isEmpty - ? 'http://localhost:$port/$filePathToServe' - : 'http://localhost:$port/$basePath/$filePathToServe'; + ? 'http://127.0.0.1:$port/$filePathToServe' + : 'http://127.0.0.1:$port/$basePath/$filePathToServe'; if (testSettings.launchChrome) { await _webDriver?.get(appUrl); @@ -834,7 +834,7 @@ class TestContext { /// Returns a handler for build runner + DDC AMD module system. Handler _createBuildRunnerAmdAssetHandler(int assetServerPort) { return proxyHandler( - 'http://localhost:$assetServerPort/${project.directoryToServe}/', + 'http://127.0.0.1:$assetServerPort/${project.directoryToServe}/', client: client, ); } @@ -848,7 +848,7 @@ class TestContext { /// `project.directoryToServe`. Handler _createBuildRunnerDdcLibraryBundleAssetHandler(int assetServerPort) { final entrypointProxy = proxyHandler( - 'http://localhost:$assetServerPort/${project.directoryToServe}/', + 'http://127.0.0.1:$assetServerPort/${project.directoryToServe}/', client: client, ); diff --git a/dwds_test_common/lib/test_sdk_configuration.dart b/dwds_test_common/lib/test_sdk_configuration.dart index c6fabc016..3a985e1c5 100644 --- a/dwds_test_common/lib/test_sdk_configuration.dart +++ b/dwds_test_common/lib/test_sdk_configuration.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:dwds/expression_compiler.dart'; import 'package:dwds/sdk_configuration.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as p; import 'sdk_asset_generator.dart'; import 'test_sdk_layout.dart'; @@ -58,6 +59,29 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider { } try { + final cacheDirName = + 'dwds_sdk_cache_${ddcModuleFormat.name}_$canaryFeatures'; + final cacheDir = Directory( + p.join(Directory.systemTemp.path, cacheDirName), + ); + final cacheJsFile = File(p.join(cacheDir.path, 'dart_sdk.js')); + final cacheJsMapFile = File(p.join(cacheDir.path, 'dart_sdk.js.map')); + + final targetJsPath = ddcModuleFormat == ModuleFormat.amd + ? sdkLayout.amdJsPath + : sdkLayout.ddcJsPath; + final targetJsMapPath = ddcModuleFormat == ModuleFormat.amd + ? sdkLayout.amdJsMapPath + : sdkLayout.ddcJsMapPath; + + if (cacheJsFile.existsSync() && cacheJsMapFile.existsSync()) { + _logger.info('Found cached SDK assets in ${cacheDir.path}'); + await File(targetJsPath).create(recursive: true); + await File(targetJsMapPath).create(recursive: true); + await cacheJsFile.copy(targetJsPath); + await cacheJsMapFile.copy(targetJsMapPath); + } + final assetGenerator = SdkAssetGenerator( sdkLayout: sdkLayout, canaryFeatures: canaryFeatures, @@ -66,6 +90,20 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider { ); await assetGenerator.generateSdkAssets(); + + if (!cacheJsFile.existsSync() || !cacheJsMapFile.existsSync()) { + _logger.info('Caching SDK assets in ${cacheDir.path}'); + await cacheDir.create(recursive: true); + final tempJs = File(p.join(cacheDir.path, 'dart_sdk.js.tmp')); + final tempJsMap = File(p.join(cacheDir.path, 'dart_sdk.js.map.tmp')); + + await File(targetJsPath).copy(tempJs.path); + await File(targetJsMapPath).copy(tempJsMap.path); + + await _safeRename(tempJs, cacheJsFile.path); + await _safeRename(tempJsMap, cacheJsMapFile.path); + } + return TestSdkLayout.createConfiguration(sdkLayout); } catch (e, s) { _logger.severe('Failed generate missing assets', e, s); @@ -86,4 +124,12 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider { } } } + + Future _safeRename(File from, String to) async { + try { + await from.rename(to); + } on FileSystemException { + // Ignore if rename fails (e.g. file exists or busy on Windows). + } + } }