Skip to content

Commit 963ea91

Browse files
authored
Revert "Unit test against local backend. (#3278)" (#3280)
This reverts commit 16e82bb.
1 parent 16e82bb commit 963ea91

File tree

14 files changed

+42
-174
lines changed

14 files changed

+42
-174
lines changed

.github/workflows/dartpad_ui.yml

-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ jobs:
3535
- run: flutter pub get
3636
- run: flutter analyze
3737
- run: dart format --set-exit-if-changed .
38-
- name: Create template projects and populate the custom pub cache
39-
run: dart run grinder build-project-templates
40-
working-directory: pkgs/dart_services/
4138
- run: flutter build web
4239
- run: flutter test test/presubmit
4340
- run: sh ./tool/check_cycles.sh

pkgs/dart_services/lib/server.dart

-38
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import 'dart:async';
66
import 'dart:io';
77

88
import 'package:args/args.dart';
9-
import 'package:dartpad_shared/services.dart';
10-
import 'package:http/http.dart' as http;
119
import 'package:logging/logging.dart';
12-
import 'package:meta/meta.dart';
1310
import 'package:shelf/shelf.dart';
1411
import 'package:shelf/shelf_io.dart' as shelf;
1512
import 'package:shelf_gzip/shelf_gzip.dart';
@@ -178,38 +175,3 @@ Middleware exceptionResponse() {
178175
};
179176
};
180177
}
181-
182-
@visibleForTesting
183-
Future<TestServerRunner> startTestServer() async {
184-
final runner = TestServerRunner();
185-
await runner.start();
186-
return runner;
187-
}
188-
189-
@visibleForTesting
190-
class TestServerRunner {
191-
late final ServicesClient client;
192-
late final EndpointsServer _server;
193-
final sdk = Sdk.fromLocalFlutter();
194-
195-
Completer<void>? _started;
196-
197-
Future<ServicesClient> start() async {
198-
assert(_started == null, 'Server should not be started');
199-
_started = Completer<void>();
200-
_server = await EndpointsServer.serve(8080, sdk, null, 'nnbd_artifacts');
201-
client = ServicesClient(
202-
http.Client(),
203-
rootUrl: 'http://localhost:${_server.port}/',
204-
);
205-
_started!.complete();
206-
return client;
207-
}
208-
209-
Future<void> stop() async {
210-
assert(_started != null, 'Server should be started before stopping');
211-
await _started!.future;
212-
client.dispose();
213-
await _server.close();
214-
}
215-
}

pkgs/dart_services/lib/src/analysis.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class AnalysisServerWrapper {
283283
errors.map((error) {
284284
final issue = api.AnalysisIssue(
285285
kind: error.severity.toLowerCase(),
286-
message: utils.normalizeImports(error.message),
286+
message: utils.normalizeFilePaths(error.message),
287287
code: error.code.toLowerCase(),
288288
location: api.Location(
289289
charStart: error.location.offset,
@@ -294,12 +294,12 @@ class AnalysisServerWrapper {
294294
correction:
295295
error.correction == null
296296
? null
297-
: utils.normalizeImports(error.correction!),
297+
: utils.normalizeFilePaths(error.correction!),
298298
url: error.url,
299299
contextMessages:
300300
error.contextMessages?.map((m) {
301301
return api.DiagnosticMessage(
302-
message: utils.normalizeImports(m.message),
302+
message: utils.normalizeFilePaths(m.message),
303303
location: api.Location(
304304
charStart: m.location.offset,
305305
charLength: m.location.length,

pkgs/dart_services/lib/src/project_templates.dart

+2-12
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import 'package:analyzer/dart/ast/ast.dart';
88
import 'package:meta/meta.dart';
99
import 'package:path/path.dart' as path;
1010

11-
import 'utils.dart';
12-
1311
/// Sets of project template directory paths.
1412
class ProjectTemplates {
1513
ProjectTemplates._({
@@ -39,16 +37,8 @@ class ProjectTemplates {
3937

4038
static ProjectTemplates projectTemplates = ProjectTemplates();
4139

42-
static String _baseTemplateProject() {
43-
final dir = path.join(
44-
Directory.current.path,
45-
'..',
46-
'dart_services',
47-
'project_templates',
48-
);
49-
50-
return normalizeFilePath(dir);
51-
}
40+
static String _baseTemplateProject() =>
41+
path.join(Directory.current.path, 'project_templates');
5242
}
5343

5444
/// The set of supported Flutter-oriented packages.

pkgs/dart_services/lib/src/utils.dart

+1-30
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'package:path/path.dart' as path;
2121
///
2222
/// "Unused import: 'package:flutter/material.dart'" ->
2323
/// "Unused import: 'package:flutter/material.dart'"
24-
String normalizeImports(String text) {
24+
String normalizeFilePaths(String text) {
2525
return text.replaceAllMapped(_possiblePathPattern, (match) {
2626
final possiblePath = match.group(0)!;
2727

@@ -45,35 +45,6 @@ String normalizeImports(String text) {
4545
});
4646
}
4747

48-
/// Normalizes an absolute file path by removing all occurrences of "..".
49-
String normalizeFilePath(String filePath) {
50-
const parent = '..';
51-
final parts = path.split(filePath);
52-
assert(parts[0] == Platform.pathSeparator);
53-
parts.removeAt(0);
54-
assert(parts[0] != Platform.pathSeparator);
55-
56-
String? atOrNull(int index) {
57-
if (index < 0) return null;
58-
return parts.elementAtOrNull(index);
59-
}
60-
61-
while (true) {
62-
var index = parts.lastIndexOf(parent);
63-
64-
while (atOrNull(index - 1) == parent) {
65-
index = index - 1;
66-
}
67-
68-
if (index == -1 || index == 0) break;
69-
70-
parts.removeAt(index);
71-
parts.removeAt(index - 1);
72-
}
73-
74-
return '${Platform.pathSeparator}${path.joinAll(parts)}';
75-
}
76-
7748
Future<Process> runWithLogging(
7849
String executable, {
7950
List<String> arguments = const [],

pkgs/dart_services/test/server_test.dart

+15-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import 'package:collection/collection.dart';
66
import 'package:dart_services/server.dart';
7+
import 'package:dart_services/src/sdk.dart';
78
import 'package:dartpad_shared/services.dart';
9+
import 'package:http/http.dart';
810
import 'package:test/test.dart';
911

1012
import 'src/sample_code.dart';
@@ -13,16 +15,24 @@ void main() => defineTests();
1315

1416
void defineTests() {
1517
group('server', () {
16-
final runner = TestServerRunner();
18+
final sdk = Sdk.fromLocalFlutter();
19+
late final EndpointsServer server;
20+
late final Client httpClient;
1721
late final ServicesClient client;
1822

1923
setUpAll(() async {
20-
await runner.start();
21-
client = runner.client;
24+
server = await EndpointsServer.serve(0, sdk, null, 'nnbd_artifacts');
25+
26+
httpClient = Client();
27+
client = ServicesClient(
28+
httpClient,
29+
rootUrl: 'http://localhost:${server.port}/',
30+
);
2231
});
2332

2433
tearDownAll(() async {
25-
await runner.stop();
34+
client.dispose();
35+
await server.close();
2636
});
2737

2838
test('version', () async {
@@ -334,7 +344,7 @@ void main() {
334344
(request) => client.compileDDC(request),
335345
expectDeltaDill: false,
336346
);
337-
if (runner.sdk.dartMajorVersion >= 3 && runner.sdk.dartMinorVersion >= 8) {
347+
if (sdk.dartMajorVersion >= 3 && sdk.dartMinorVersion >= 8) {
338348
testDDCEndpoint(
339349
'compileNewDDC',
340350
(request) => client.compileNewDDC(request),

pkgs/dart_services/test/utils_test.dart

+10-22
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,52 @@ import 'package:test/test.dart';
88
void main() => defineTests();
99

1010
void defineTests() {
11-
void expectNormalizeImports(String input, String output) {
12-
expect(normalizeImports(input), equals(output));
11+
void expectNormalizeFilePaths(String input, String output) {
12+
expect(normalizeFilePaths(input), equals(output));
1313
}
1414

15-
group('expectNormalizeImports', () {
15+
group('expectNormalizeFilePaths', () {
1616
test('strips a temporary directory path', () {
17-
expectNormalizeImports(
17+
expectNormalizeFilePaths(
1818
'List is defined in /var/folders/4p/y54w9nqj0_n6ryqwn7lxqz6800m6cw/T/DartAnalysisWrapperintLAw/main.dart',
1919
'List is defined in main.dart',
2020
);
2121
});
2222

2323
test('replaces a SDK path with "dart:core"', () {
24-
expectNormalizeImports(
24+
expectNormalizeFilePaths(
2525
'List is defined in /path/dart/dart/sdk/lib/core/list.dart',
2626
'List is defined in dart:core/list.dart',
2727
);
2828
});
2929

3030
test('replaces a specific SDK path with "dart:core"', () {
31-
expectNormalizeImports(
31+
expectNormalizeFilePaths(
3232
"The argument type 'List<int> (where List is defined in /Users/username/sdk/dart/2.10.5/lib/core/list.dart)' can't be assigned to the parameter type 'List<int> (where List is defined in /var/folders/4p/tmp/T/DartAnalysisWrapperintLAw/main.dart)'.",
3333
"The argument type 'List<int> (where List is defined in dart:core/list.dart)' can't be assigned to the parameter type 'List<int> (where List is defined in main.dart)'.",
3434
);
3535
});
3636

3737
test('keeps a "package:" path intact', () {
38-
expectNormalizeImports(
38+
expectNormalizeFilePaths(
3939
"Unused import: 'package:flutter/material.dart'.",
4040
"Unused import: 'package:flutter/material.dart'.",
4141
);
4242
});
4343

4444
test('keeps a "dart:core" path intact', () {
45-
expectNormalizeImports('dart:core/foo.dart', 'dart:core/foo.dart');
45+
expectNormalizeFilePaths('dart:core/foo.dart', 'dart:core/foo.dart');
4646
});
4747

4848
test('keeps a web URL intact', () {
49-
expectNormalizeImports(
49+
expectNormalizeFilePaths(
5050
'See http://dart.dev/go/non-promo-property',
5151
'See http://dart.dev/go/non-promo-property',
5252
);
5353
});
5454

5555
test('strips a Flutter SDK path', () {
56-
expectNormalizeImports(
56+
expectNormalizeFilePaths(
5757
"The argument type 'StatelessWidget (where StatelessWidget is defined in /Users/username/path/to/dart-services/project_templates/flutter_project/main.dart)' can't be assigned to the parameter type 'StatelessWidget (where StatelessWidget is defined in /Users/username/path/to/dart-services/flutter-sdk/packages/flutter/lib/src/widgets/framework.dart)'.",
5858
"The argument type 'StatelessWidget (where StatelessWidget is defined in main.dart)' can't be assigned to the parameter type 'StatelessWidget (where StatelessWidget is defined in package:flutter/framework.dart)'.",
5959
);
@@ -97,16 +97,4 @@ void defineTests() {
9797
expect(lines.columnForOffset(3), 4);
9898
});
9999
});
100-
101-
group('normalizeFilePath', () {
102-
test('removes ".." from the path', () {
103-
expect(normalizeFilePath('/path/to/../file.dart'), '/path/file.dart');
104-
expect(normalizeFilePath('/path/../to/file.dart'), '/to/file.dart');
105-
expect(normalizeFilePath('/path/to/../../file.dart'), '/file.dart');
106-
expect(normalizeFilePath('/path/../../to/file.dart'), '/../to/file.dart');
107-
expect(normalizeFilePath('/path/../to/../../file.dart'), '/../file.dart');
108-
expect(normalizeFilePath('/path/../../to/../file.dart'), '/../file.dart');
109-
expect(normalizeFilePath('/../path/../to/file.dart'), '/../to/file.dart');
110-
});
111-
});
112100
}

pkgs/dartpad_shared/lib/services.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ class ServicesClient {
1616

1717
ServicesClient(this.client, {required this.rootUrl});
1818

19-
Future<VersionResponse> version() async {
20-
print('Fetching version from $rootUrl');
21-
final result = await _requestGet('version', VersionResponse.fromJson);
22-
print('Version: $result');
23-
return result;
24-
}
19+
Future<VersionResponse> version() =>
20+
_requestGet('version', VersionResponse.fromJson);
2521

2622
Future<AnalysisResponse> analyze(SourceRequest request) =>
2723
_requestPost('analyze', request.toJson(), AnalysisResponse.fromJson);

pkgs/dartpad_ui/lib/main.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ void main() async {
4747
}
4848

4949
class DartPadApp extends StatefulWidget {
50-
const DartPadApp({super.key, this.channel});
51-
52-
/// If initialized, will override URL parameter for channel.
53-
@visibleForTesting
54-
final String? channel;
50+
const DartPadApp({super.key});
5551

5652
@override
5753
State<DartPadApp> createState() => _DartPadAppState();
@@ -132,7 +128,7 @@ class _DartPadAppState extends State<DartPadApp> {
132128
final gistId = gist ?? state.uri.queryParameters['id'];
133129
final builtinSampleId = state.uri.queryParameters['sample'];
134130
final flutterSampleId = state.uri.queryParameters['sample_id'];
135-
final channelParam = widget.channel ?? state.uri.queryParameters['channel'];
131+
final channelParam = state.uri.queryParameters['channel'];
136132
final embedMode = state.uri.queryParameters['embed'] == 'true';
137133
final runOnLoad = state.uri.queryParameters['run'] == 'true';
138134
useGenUI = state.uri.queryParameters['genui'] == 'true';

pkgs/dartpad_ui/lib/model.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ class AppServices {
261261
});
262262
}
263263

264-
Future<VersionResponse> populateVersions() => services.version();
264+
Future<VersionResponse> populateVersions() async {
265+
final version = await services.version();
266+
appModel.runtimeVersions.value = version;
267+
return version;
268+
}
265269

266270
Future<void> performInitialLoad({
267271
String? gistId,
@@ -594,7 +598,7 @@ enum Channel {
594598
beta('Beta', 'https://beta.api.dartpad.dev/'),
595599
main('Main', 'https://master.api.dartpad.dev/'),
596600
// This channel is only used for local development.
597-
localhost('Localhost', 'http://127.0.0.1:8080/');
601+
localhost('Localhost', 'http://localhost:8080/');
598602

599603
final String displayName;
600604
final String url;

pkgs/dartpad_ui/pubspec.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ dev_dependencies:
4040
sdk: flutter
4141
flutter_lints: ^5.0.0
4242
test: ^1.25.7
43-
dart_services:
44-
path: ../dart_services
4543

4644
flutter:
4745
uses-material-design: true

pkgs/dartpad_ui/test/presubmit/main_test.dart

-44
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)