Tiny fix about outdated message (#114391)
This commit is contained in:
parent
a41c447c8b
commit
86b62a3c21
@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||||
|
|
||||||
import '../base/common.dart';
|
import '../base/common.dart';
|
||||||
@ -168,7 +169,7 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
sink.add(base64.decode(skp.json?['skp'] as String));
|
sink.add(base64.decode(skp.json?['skp'] as String));
|
||||||
await sink.close();
|
await sink.close();
|
||||||
_showOutputFileInfo(outputFile);
|
_showOutputFileInfo(outputFile);
|
||||||
_ensureOutputIsNotJsonRpcError(outputFile);
|
ensureOutputIsNotJsonRpcError(outputFile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +193,7 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
sink.add(base64.decode(response.json?['screenshot'] as String));
|
sink.add(base64.decode(response.json?['screenshot'] as String));
|
||||||
await sink.close();
|
await sink.close();
|
||||||
_showOutputFileInfo(outputFile);
|
_showOutputFileInfo(outputFile);
|
||||||
_ensureOutputIsNotJsonRpcError(outputFile);
|
ensureOutputIsNotJsonRpcError(outputFile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +206,8 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _ensureOutputIsNotJsonRpcError(File outputFile) {
|
@visibleForTesting
|
||||||
|
static void ensureOutputIsNotJsonRpcError(File outputFile) {
|
||||||
if (outputFile.lengthSync() >= 1000) {
|
if (outputFile.lengthSync() >= 1000) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -213,7 +215,7 @@ class ScreenshotCommand extends FlutterCommand {
|
|||||||
encoding: const AsciiCodec(allowInvalid: true),
|
encoding: const AsciiCodec(allowInvalid: true),
|
||||||
);
|
);
|
||||||
if (content.startsWith('{"jsonrpc":"2.0", "error"')) {
|
if (content.startsWith('{"jsonrpc":"2.0", "error"')) {
|
||||||
throwToolExit('It appears the output file contains an error message, not valid skia output.');
|
throwToolExit('It appears the output file contains an error message, not valid output.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,4 +106,24 @@ void main() {
|
|||||||
message: 'File was not created, ensure path is valid'));
|
message: 'File was not created, ensure path is valid'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('Screenshot output validation', () {
|
||||||
|
testWithoutContext('successful', () async {
|
||||||
|
final MemoryFileSystem fs = MemoryFileSystem.test();
|
||||||
|
fs.file('test.png').createSync();
|
||||||
|
|
||||||
|
expect(() => ScreenshotCommand.ensureOutputIsNotJsonRpcError(fs.file('test.png')),
|
||||||
|
returnsNormally);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWithoutContext('failed', () async {
|
||||||
|
final MemoryFileSystem fs = MemoryFileSystem.test();
|
||||||
|
fs.file('test.png').writeAsStringSync('{"jsonrpc":"2.0", "error":"something"}');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
() => ScreenshotCommand.ensureOutputIsNotJsonRpcError(fs.file('test.png')),
|
||||||
|
throwsToolExit(
|
||||||
|
message: 'It appears the output file contains an error message, not valid output.'));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user