Skip to content

Commit 861116f

Browse files
committed
Add integration test for serve cases
1 parent 3d5e5b9 commit 861116f

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

webdev/test/e2e_test.dart

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
@Timeout(const Duration(minutes: 8))
5+
@Timeout(const Duration(minutes: 5))
66

77
import 'dart:io';
88

@@ -69,6 +69,61 @@ void main() {
6969
});
7070
}
7171
});
72+
73+
group('should serve with valid configuration', () {
74+
for (var withDDC in [true, false]) {
75+
test(withDDC ? 'DDC' : 'dart2js', () async {
76+
var openPort = await getOpenPort();
77+
var args = ['serve', 'web:$openPort'];
78+
if (!withDDC) {
79+
args.add('--release');
80+
}
81+
82+
var process = await runWebDev(args, workingDirectory: exampleDirectory);
83+
84+
var expectedItems = <Object>['[INFO] Succeeded'];
85+
if (!withDDC) {
86+
expectedItems.add(anyOf(
87+
contains('with 0 outputs'), contains('Running dart2js with')));
88+
}
89+
90+
var hostUrl = 'http://localhost:$openPort';
91+
92+
await expectLater(
93+
process.stdout, emitsThrough('Serving `web` on $hostUrl'));
94+
95+
var client = new HttpClient();
96+
97+
try {
98+
for (var entry in _testItems.entries) {
99+
var url = Uri.parse('$hostUrl/${entry.key}');
100+
101+
var request = await client.getUrl(url);
102+
var response = await request.close();
103+
104+
var shouldExist = (entry.value ?? withDDC) == withDDC;
105+
106+
if (entry.key == 'main.ddc.js') {
107+
// This file SHOULD NOT be output in dart2js mode
108+
// But there is an issue here
109+
// https://github.com/dart-lang/build/issues/1033
110+
shouldExist = true;
111+
}
112+
113+
var expectedStatusCode = shouldExist ? 200 : 404;
114+
115+
expect(response.statusCode, expectedStatusCode);
116+
}
117+
} finally {
118+
client.close(force: true);
119+
}
120+
121+
process.signal(ProcessSignal.SIGTERM);
122+
123+
await process.shouldExit(-15);
124+
});
125+
}
126+
});
72127
}
73128

74129
/// Returns an environment map that includes `PUB_ENVIRONMENT`.

webdev/test/test_utils.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:io';
67

78
import 'package:path/path.dart' as p;
89
import 'package:test/test.dart';
@@ -27,3 +28,22 @@ Future checkProcessStdout(TestProcess process, List items) async {
2728
expect(output, item);
2829
}
2930
}
31+
32+
/// Returns an open port by creating a temporary Socket
33+
Future<int> getOpenPort() async {
34+
ServerSocket socket;
35+
36+
try {
37+
socket = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
38+
} catch (_) {
39+
// try again v/ V6 only. Slight possibility that V4 is disabled
40+
socket = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0,
41+
v6Only: true);
42+
}
43+
44+
try {
45+
return socket.port;
46+
} finally {
47+
await socket.close();
48+
}
49+
}

0 commit comments

Comments
 (0)