Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions dwds/test/integration/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -332,7 +332,7 @@ class TestContext {

if (testSettings.enableExpressionEvaluation) {
ddcService = ExpressionCompilerService(
'localhost',
'127.0.0.1',
_port!,
verbose: testSettings.verboseCompiler,
sdkConfigurationProvider: sdkConfigurationProvider,
Expand Down Expand Up @@ -518,7 +518,7 @@ class TestContext {

if (testSettings.enableExpressionEvaluation) {
ddcService = ExpressionCompilerService(
'localhost',
'127.0.0.1',
_port!,
verbose: testSettings.verboseCompiler,
sdkConfigurationProvider: sdkConfigurationProvider,
Expand Down Expand Up @@ -595,7 +595,7 @@ class TestContext {
// listeners in DWDS or `main` is run.
final tabConnectionCompleter = Completer<void>();
final appConnectionCompleter = Completer<void>();
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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);
}
Expand All @@ -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,
);

Expand Down
46 changes: 46 additions & 0 deletions dwds_test_common/lib/test_sdk_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -86,4 +124,12 @@ class TestSdkConfigurationProvider extends SdkConfigurationProvider {
}
}
}

Future<void> _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).
}
}
}
Loading