-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwebdev_server_test.dart
More file actions
59 lines (51 loc) · 1.82 KB
/
Copy pathwebdev_server_test.dart
File metadata and controls
59 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2019 Workiva Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
@TestOn('vm')
import 'package:http/http.dart' as http;
import 'package:test/test.dart';
import 'package:webdev_proxy/src/port_utils.dart';
import 'package:webdev_proxy/src/webdev_proc_utils.dart';
import 'package:webdev_proxy/src/webdev_server.dart';
import 'util.dart';
void main() async {
late WebdevServer? webdevServer;
setUpAll(() async {
await activateWebdev(webdevCompatibility.toString());
});
tearDown(() async {
await webdevServer?.close();
});
test('Serves a directory', () async {
final port = await findUnusedPort();
webdevServer = await WebdevServer.start(['test:$port']);
// We don't have a good way of knowing when the `webdev serve` process has
// started listening on the port, so we send a request periodically until it
// succeeds. If the code under test is broken, this test will timeout.
http.Response response;
while (true) {
try {
response =
await http.get(Uri.parse('http://localhost:$port/web/index.dart'));
} catch (_) {
await Future.delayed(Duration(milliseconds: 250));
continue;
}
if (response.statusCode == 200) {
break;
}
}
expect(response.statusCode, 200);
expect(response.body, isNotEmpty);
});
}