Unverified Commit 064eae8c authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks and fix fake imports (#81309)

parent cbdd9c47
......@@ -74,9 +74,12 @@ const String _kDefaultIndex = '''
///
/// This is only used in development mode.
class WebExpressionCompiler implements ExpressionCompiler {
WebExpressionCompiler(this._generator);
WebExpressionCompiler(this._generator, {
@required FileSystem fileSystem,
}) : _fileSystem = fileSystem;
final ResidentCompiler _generator;
final FileSystem _fileSystem;
@override
Future<ExpressionCompilationResult> compileExpressionToJs(
......@@ -95,7 +98,7 @@ class WebExpressionCompiler implements ExpressionCompiler {
if (compilerOutput != null && compilerOutput.outputFilename != null) {
final String content = utf8.decode(
globals.fs.file(compilerOutput.outputFilename).readAsBytesSync());
_fileSystem.file(compilerOutput.outputFilename).readAsBytesSync());
return ExpressionCompilationResult(
content, compilerOutput.errorCount > 0);
}
......
......@@ -256,7 +256,7 @@ class ResidentWebRunner extends ResidentRunner {
return await asyncGuard(() async {
final ExpressionCompiler expressionCompiler =
debuggingOptions.webEnableExpressionEvaluation
? WebExpressionCompiler(device.generator)
? WebExpressionCompiler(device.generator, fileSystem: _fileSystem)
: null;
device.devFS = WebDevFS(
hostname: debuggingOptions.hostname ?? 'localhost',
......
......@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart';
......@@ -32,7 +31,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode', () {
......@@ -45,7 +44,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app.aab');
});
testWithoutContext("Finds app bundle when flavor doesn't contain underscores in release mode", () {
......@@ -58,7 +57,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooRelease', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/fooRelease/app.aab');
});
testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in release mode", () {
......@@ -71,7 +70,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaRelease', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/fooaRelease/app.aab');
});
testWithoutContext('Finds app bundle when no flavor is used in release mode', () {
......@@ -84,7 +83,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'release', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/release/app.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores in debug mode', () {
......@@ -97,7 +96,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barDebug', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode', () {
......@@ -110,7 +109,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barDebug', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app.aab');
});
testWithoutContext("Finds app bundle when flavor doesn't contain underscores in debug mode", () {
......@@ -123,7 +122,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooDebug', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/fooDebug/app.aab');
});
testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in debug mode", () {
......@@ -136,7 +135,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaDebug', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/fooaDebug/app.aab');
});
testWithoutContext('Finds app bundle when no flavor is used in debug mode', () {
......@@ -149,7 +148,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'debug', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/debug/app.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores in profile mode', () {
......@@ -162,7 +161,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barProfile/app.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in profile mode', () {
......@@ -175,7 +174,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barProfile/app.aab');
});
testWithoutContext("Finds app bundle when flavor doesn't contain underscores in profile mode", () {
......@@ -188,7 +187,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooProfile', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/fooProfile/app.aab');
});
testWithoutContext("Finds app bundle when flavor doesn't contain underscores but contains uppercase letters in profile mode", () {
......@@ -201,7 +200,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'fooaProfile', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/fooaProfile/app.aab');
});
testWithoutContext('Finds app bundle when no flavor is used in profile mode', () {
......@@ -214,7 +213,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'profile', 'app.aab'));
expect(bundle.path, '/build/app/outputs/bundle/profile/app.aab');
});
testWithoutContext('Finds app bundle in release mode - Gradle 3.5', () {
......@@ -227,7 +226,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'release', 'app-release.aab'));
expect(bundle.path, '/build/app/outputs/bundle/release/app-release.aab');
});
testWithoutContext('Finds app bundle in profile mode - Gradle 3.5', () {
......@@ -240,7 +239,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'profile', 'app-profile.aab'));
expect(bundle.path, '/build/app/outputs/bundle/profile/app-profile.aab');
});
testWithoutContext('Finds app bundle in debug mode - Gradle 3.5', () {
......@@ -253,7 +252,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'debug', 'app-debug.aab'));
expect(bundle.path, '/build/app/outputs/bundle/debug/app-debug.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores in release mode - Gradle 3.5', () {
......@@ -266,7 +265,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app-foo_bar-release.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app-foo_bar-release.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in release mode - Gradle 3.5', () {
......@@ -279,7 +278,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barRelease', 'app-foo_bar-release.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barRelease/app-foo_bar-release.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores in profile mode - Gradle 3.5', () {
......@@ -292,7 +291,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant', 'app', 'outputs', 'bundle', 'foo_barProfile', 'app-foo_bar-profile.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barProfile/app-foo_bar-profile.aab');
});
testWithoutContext('Finds app bundle when flavor contains underscores and uppercase letters in debug mode - Gradle 3.5', () {
......@@ -305,7 +304,7 @@ void main() {
);
expect(bundle, isNotNull);
expect(bundle.path, fileSystem.path.join('irrelevant','app', 'outputs', 'bundle', 'foo_barDebug', 'app-foo_bar-debug.aab'));
expect(bundle.path, '/build/app/outputs/bundle/foo_barDebug/app-foo_bar-debug.aab');
});
testWithoutContext('AAB not found', () {
......@@ -341,12 +340,7 @@ void main() {
/// Generates a fake app bundle at the location [directoryName]/[fileName].
FlutterProject generateFakeAppBundle(String directoryName, String fileName, FileSystem fileSystem) {
final FlutterProject project = MockFlutterProject();
final AndroidProject androidProject = MockAndroidProject();
when(project.isModule).thenReturn(false);
when(project.android).thenReturn(androidProject);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('irrelevant'));
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final Directory bundleDirectory = getBundleDirectory(project);
bundleDirectory
......@@ -359,6 +353,3 @@ FlutterProject generateFakeAppBundle(String directoryName, String fileName, File
.createSync();
return project;
}
class MockAndroidProject extends Mock implements AndroidProject {}
class MockFlutterProject extends Mock implements FlutterProject {}
......@@ -19,11 +19,19 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
const String kModulePubspec = '''
name: test
flutter:
module:
androidPackage: com.example
androidX: true
''';
void main() {
Cache.flutterRoot = getFlutterRoot();
......@@ -35,54 +43,42 @@ void main() {
});
testWithoutContext('getApkDirectory in app projects', () {
final FlutterProject project = MockFlutterProject();
final AndroidProject androidProject = MockAndroidProject();
when(project.android).thenReturn(androidProject);
when(project.isModule).thenReturn(false);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
expect(
getApkDirectory(project).path,
equals(fileSystem.path.join('foo', 'app', 'outputs', 'flutter-apk')),
getApkDirectory(project).path, '/build/app/outputs/flutter-apk',
);
});
testWithoutContext('getApkDirectory in module projects', () {
final FlutterProject project = MockFlutterProject();
final AndroidProject androidProject = MockAndroidProject();
when(project.android).thenReturn(androidProject);
when(project.isModule).thenReturn(true);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
fileSystem.currentDirectory
.childFile('pubspec.yaml')
.writeAsStringSync(kModulePubspec);
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
expect(project.isModule, true);
expect(
getApkDirectory(project).path,
equals(fileSystem.path.join('foo', 'host', 'outputs', 'apk')),
getApkDirectory(project).path, '/build/host/outputs/apk',
);
});
testWithoutContext('getBundleDirectory in app projects', () {
final FlutterProject project = MockFlutterProject();
final AndroidProject androidProject = MockAndroidProject();
when(project.android).thenReturn(androidProject);
when(project.isModule).thenReturn(false);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
expect(
getBundleDirectory(project).path,
equals(fileSystem.path.join('foo', 'app', 'outputs', 'bundle')),
getBundleDirectory(project).path, '/build/app/outputs/bundle',
);
});
testWithoutContext('getBundleDirectory in module projects', () {
final FlutterProject project = MockFlutterProject();
final AndroidProject androidProject = MockAndroidProject();
when(project.android).thenReturn(androidProject);
when(project.isModule).thenReturn(true);
when(androidProject.buildDirectory).thenReturn(fileSystem.directory('foo'));
fileSystem.currentDirectory
.childFile('pubspec.yaml')
.writeAsStringSync(kModulePubspec);
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
expect(project.isModule, true);
expect(
getBundleDirectory(project).path,
equals(fileSystem.path.join('foo', 'host', 'outputs', 'bundle')),
getBundleDirectory(project).path, '/build/host/outputs/bundle',
);
});
......@@ -1028,5 +1024,3 @@ class FakeGradleUtils extends GradleUtils {
}
class FakeAndroidSdk extends Fake implements AndroidSdk {}
class MockAndroidProject extends Mock implements AndroidProject {}
class MockFlutterProject extends Mock implements FlutterProject {}
......@@ -4,9 +4,10 @@
// @dart = 2.8
import 'dart:io' as io; // ignore: dart_io_import
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/device_port_forwarder.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../src/common.dart';
import '../src/context.dart';
......@@ -19,12 +20,20 @@ void main() {
});
testUsingContext('dispose kills process if process was available', () {
final MockProcess mockProcess = MockProcess();
final ForwardedPort forwardedPort = ForwardedPort.withContext(123, 456, mockProcess);
final FakeProcess process = FakeProcess();
final ForwardedPort forwardedPort = ForwardedPort.withContext(123, 456, process);
forwardedPort.dispose();
expect(forwardedPort.context, isNotNull);
verify(mockProcess.kill());
expect(process.killed, true);
});
}
class MockProcess extends Mock implements Process {}
class FakeProcess extends Fake implements Process {
bool killed = false;
@override
bool kill([io.ProcessSignal signal = io.ProcessSignal.sigterm]) {
return killed = true;
}
}
......@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/doctor_validator.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../src/common.dart';
import '../src/fake_process_manager.dart';
......
......@@ -14,7 +14,7 @@ import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/linux/application_package.dart';
import 'package:flutter_tools/src/linux/linux_device.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/fake_process_manager.dart';
......@@ -139,23 +139,17 @@ void main() {
});
testWithoutContext('LinuxDevice.executablePathForDevice uses the correct package executable', () async {
final MockLinuxApp mockApp = MockLinuxApp();
final FakeLinuxApp mockApp = FakeLinuxApp();
final LinuxDevice device = LinuxDevice(
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
const String debugPath = 'debug/executable';
const String profilePath = 'profile/executable';
const String releasePath = 'release/executable';
when(mockApp.executable(BuildMode.debug)).thenReturn(debugPath);
when(mockApp.executable(BuildMode.profile)).thenReturn(profilePath);
when(mockApp.executable(BuildMode.release)).thenReturn(releasePath);
expect(device.executablePathForDevice(mockApp, BuildMode.debug), debugPath);
expect(device.executablePathForDevice(mockApp, BuildMode.profile), profilePath);
expect(device.executablePathForDevice(mockApp, BuildMode.release), releasePath);
expect(device.executablePathForDevice(mockApp, BuildMode.debug), 'debug/executable');
expect(device.executablePathForDevice(mockApp, BuildMode.profile), 'profile/executable');
expect(device.executablePathForDevice(mockApp, BuildMode.release), 'release/executable');
});
}
......@@ -167,7 +161,21 @@ FlutterProject setUpFlutterProject(Directory directory) {
return flutterProjectFactory.fromDirectory(directory);
}
class MockLinuxApp extends Mock implements LinuxApp {}
class FakeLinuxApp extends Fake implements LinuxApp {
@override
String executable(BuildMode buildMode) {
switch (buildMode) {
case BuildMode.debug:
return 'debug/executable';
case BuildMode.profile:
return 'profile/executable';
case BuildMode.release:
return 'release/executable';
default:
throw StateError('Invalid mode: $buildMode');
}
}
}
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
FakeOperatingSystemUtils({
HostPlatform hostPlatform = HostPlatform.linux_x64
......
......@@ -19,7 +19,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/reporting/crash_reporting.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -180,9 +179,9 @@ void main() {
expect(logContents, contains('String: an exception % --'));
expect(logContents, contains('CrashingFlutterCommand.runCommand'));
expect(logContents, contains('[✓] Flutter'));
print(globals.crashReporter.runtimeType);
final VerificationResult argVerification = verify(globals.crashReporter.informUser(captureAny, any));
final CrashDetails sentDetails = argVerification.captured.first as CrashDetails;
final CrashDetails sentDetails = (globals.crashReporter as WaitingCrashReporter)._details;
expect(sentDetails.command, 'flutter crash');
expect(sentDetails.error, 'an exception % --');
expect(sentDetails.stackTrace.toString(), contains('CrashingFlutterCommand.runCommand'));
......@@ -199,6 +198,7 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
UserMessages: () => CustomBugInstructions(),
Artifacts: () => Artifacts.test(),
CrashReporter: () => WaitingCrashReporter(Future<void>.value())
});
});
}
......@@ -331,7 +331,11 @@ class WaitingCrashReporter implements CrashReporter {
WaitingCrashReporter(Future<void> future) : _future = future;
final Future<void> _future;
CrashDetails _details;
@override
Future<void> informUser(CrashDetails details, File crashFile) => _future;
Future<void> informUser(CrashDetails details, File crashFile) {
_details = details;
return _future;
}
}
......@@ -5,78 +5,55 @@
// @dart = 2.8
import 'package:dwds/dwds.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:mockito/mockito.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/testbed.dart';
void main() {
Testbed testbed;
FileSystem fileSystem;
setUp(() {
testbed = Testbed();
fileSystem = MemoryFileSystem.test();
});
test('WebExpressionCompiler handles successful expression compilation', () => testbed.run(() async {
globals.fs.file('compilerOutput').writeAsStringSync('a');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.compileExpressionToJs(
any, any, any, any, any, any, any
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('compilerOutput', 0, <Uri>[]);
});
final ExpressionCompiler expressionCompiler =
WebExpressionCompiler(residentCompiler);
testWithoutContext('WebExpressionCompiler handles successful expression compilation', () async {
fileSystem.file('compilerOutput').writeAsStringSync('a');
final ResidentCompiler residentCompiler = FakeResidentCompiler(const CompilerOutput('compilerOutput', 0, <Uri>[]));
final ExpressionCompiler expressionCompiler = WebExpressionCompiler(residentCompiler, fileSystem: fileSystem);
final ExpressionCompilationResult result =
await expressionCompiler.compileExpressionToJs(
null, null, 1, 1, null, null, null, null);
expectResult(result, false, 'a');
}));
test('WebExpressionCompiler handles compilation error', () => testbed.run(() async {
globals.fs.file('compilerOutput').writeAsStringSync('Error: a');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.compileExpressionToJs(
any, any, any, any, any, any, any
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('compilerOutput', 1, <Uri>[]);
});
});
final ExpressionCompiler expressionCompiler =
WebExpressionCompiler(residentCompiler);
testWithoutContext('WebExpressionCompiler handles compilation error', () async {
fileSystem.file('compilerOutput').writeAsStringSync('Error: a');
final ResidentCompiler residentCompiler = FakeResidentCompiler(const CompilerOutput('compilerOutput', 1, <Uri>[]));
final ExpressionCompiler expressionCompiler = WebExpressionCompiler(residentCompiler, fileSystem: fileSystem);
final ExpressionCompilationResult result =
await expressionCompiler.compileExpressionToJs(
null, null, 1, 1, null, null, null, null);
expectResult(result, true, 'Error: a');
}));
test('WebExpressionCompiler handles internal error', () => testbed.run(() async {
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.compileExpressionToJs(
any, any, any, any, any, any, any
)).thenAnswer((Invocation invocation) async {
return null;
});
});
final ExpressionCompiler expressionCompiler =
WebExpressionCompiler(residentCompiler);
testWithoutContext('WebExpressionCompiler handles internal error', () async {
final ResidentCompiler residentCompiler = FakeResidentCompiler(null);
final ExpressionCompiler expressionCompiler = WebExpressionCompiler(residentCompiler, fileSystem: fileSystem);
final ExpressionCompilationResult result =
await expressionCompiler.compileExpressionToJs(
null, null, 1, 1, null, null, null, 'a');
expectResult(result, true, 'InternalError: frontend server failed to compile \'a\'');
}));
});
}
void expectResult(ExpressionCompilationResult result, bool isError, String value) {
......@@ -86,4 +63,21 @@ void expectResult(ExpressionCompilationResult result, bool isError, String value
.having((ExpressionCompilationResult instance) => instance.result, 'result', value));
}
class MockResidentCompiler extends Mock implements ResidentCompiler {}
class FakeResidentCompiler extends Fake implements ResidentCompiler {
FakeResidentCompiler(this.output);
final CompilerOutput output;
@override
Future<CompilerOutput> compileExpressionToJs(
String libraryUri,
int line,
int column,
Map<String, String> jsModules,
Map<String, String> jsFrameValues,
String moduleName,
String expression,
) async {
return output;
}
}
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