167970dea7
This reverts commitd0dff0e9ba. Reason for revert: fixed broken tests to reland. Original change's description: > Revert "Add DevTools Server test and test driver to DDS" > > This reverts commit02bff5bde2. > > Reason for revert: broken tests. (e.g. https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/pkg-mac-release/20638/overview) > > Original change's description: > > Add DevTools Server test and test driver to DDS > > > > Bug: https://github.com/dart-lang/sdk/issues/48300 > > Change-Id: I3b72274d111489448a482d65eb7cc23a9f263edf > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233320 > > Reviewed-by: Ben Konyi <bkonyi@google.com> > > Commit-Queue: Kenzie Davisson <kenzieschmoll@google.com> > > TBR=bkonyi@google.com,kenzieschmoll@google.com > > Change-Id: Iaca6b34a4e55ddd7b984b49821f3cc95337d696a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: https://github.com/dart-lang/sdk/issues/48300 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234114 > Reviewed-by: Kenzie Davisson <kenzieschmoll@google.com> > Commit-Queue: Kenzie Davisson <kenzieschmoll@google.com> # Not skipping CQ checks because original CL landed > 1 day ago. Bug: https://github.com/dart-lang/sdk/issues/48300 Change-Id: I60ffd0e8a394353014408530d636c5918e517a59 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234861 Reviewed-by: Ben Konyi <bkonyi@google.com> Reviewed-by: Kenzie Davisson <kenzieschmoll@google.com> Reviewed-by: Siva Annamalai <asiva@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com> Commit-Queue: Kenzie Davisson <kenzieschmoll@google.com>
94 lines
2.2 KiB
Dart
94 lines
2.2 KiB
Dart
// Copyright 2022 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:devtools_shared/devtools_test_utils.dart';
|
|
|
|
const verbose = true;
|
|
|
|
class DevToolsServerDriver {
|
|
DevToolsServerDriver._(
|
|
this._process,
|
|
this._stdin,
|
|
Stream<String> _stdout,
|
|
Stream<String> _stderr,
|
|
) : stdout = _convertToMapStream(_stdout),
|
|
stderr = _stderr.map((line) {
|
|
_trace('<== STDERR $line');
|
|
return line;
|
|
});
|
|
|
|
final Process _process;
|
|
final Stream<Map<String, dynamic>?> stdout;
|
|
final Stream<String> stderr;
|
|
final StringSink _stdin;
|
|
|
|
void write(Map<String, dynamic> request) {
|
|
final line = jsonEncode(request);
|
|
_trace('==> $line');
|
|
_stdin.writeln(line);
|
|
}
|
|
|
|
static Stream<Map<String, dynamic>?> _convertToMapStream(
|
|
Stream<String> stream,
|
|
) {
|
|
return stream.map((line) {
|
|
_trace('<== $line');
|
|
return line;
|
|
}).map((line) {
|
|
try {
|
|
return jsonDecode(line) as Map<String, dynamic>;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}).where((item) => item != null);
|
|
}
|
|
|
|
static void _trace(String message) {
|
|
if (verbose) {
|
|
print(message);
|
|
}
|
|
}
|
|
|
|
bool kill() => _process.kill();
|
|
|
|
static Future<DevToolsServerDriver> create({
|
|
int port = 0,
|
|
int? tryPorts,
|
|
List<String> additionalArgs = const [],
|
|
}) async {
|
|
final script =
|
|
Platform.script.resolveUri(Uri.parse('./serve_devtools.dart'));
|
|
final args = [
|
|
script.path,
|
|
'--machine',
|
|
'--port',
|
|
'$port',
|
|
...additionalArgs,
|
|
];
|
|
|
|
if (tryPorts != null) {
|
|
args.addAll(['--try-ports', '$tryPorts']);
|
|
}
|
|
|
|
if (useChromeHeadless && headlessModeIsSupported) {
|
|
args.add('--headless');
|
|
}
|
|
final Process process = await Process.start(
|
|
Platform.resolvedExecutable,
|
|
args,
|
|
);
|
|
|
|
return DevToolsServerDriver._(
|
|
process,
|
|
process.stdin,
|
|
process.stdout.transform(utf8.decoder).transform(const LineSplitter()),
|
|
process.stderr.transform(utf8.decoder).transform(const LineSplitter()),
|
|
);
|
|
}
|
|
}
|