43 lines
1.4 KiB
Dart
43 lines
1.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|||
|
|
import 'package:openchamber/api/dev_tunnel.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
test('loopback hosts and ports are recognised', () {
|
||
|
|
for (final host in [
|
||
|
|
'localhost',
|
||
|
|
'127.0.0.1',
|
||
|
|
'::1',
|
||
|
|
'[::1]',
|
||
|
|
'0.0.0.0',
|
||
|
|
'::',
|
||
|
|
]) {
|
||
|
|
expect(isLoopbackDevHost(host), isTrue, reason: host);
|
||
|
|
}
|
||
|
|
expect(isLoopbackDevHost('192.168.1.10'), isFalse);
|
||
|
|
expect(devServerPort(Uri.parse('http://localhost:5173/')), 5173);
|
||
|
|
expect(devServerPort(Uri.parse('http://127.0.0.1')), 80);
|
||
|
|
expect(devServerPort(Uri.parse('https://localhost')), 443);
|
||
|
|
expect(devServerPort(Uri.parse('https://example.com:8443')), isNull);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the tunnel keeps path, query and fragment', () {
|
||
|
|
final local = localTunnelUri(
|
||
|
|
Uri.parse('http://localhost:5173/a/b?x=1#top'), 4000);
|
||
|
|
expect(local.toString(), 'http://127.0.0.1:4000/a/b?x=1#top');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the address bar is mapped back to the dev server', () {
|
||
|
|
expect(
|
||
|
|
displayUrlFor('http://127.0.0.1:4000/a', 4000, 'http://localhost:5173'),
|
||
|
|
'http://localhost:5173/a',
|
||
|
|
);
|
||
|
|
expect(
|
||
|
|
displayUrlFor('http://127.0.0.1:4000', 4000, 'http://localhost:5173'),
|
||
|
|
'http://localhost:5173',
|
||
|
|
);
|
||
|
|
expect(
|
||
|
|
displayUrlFor('https://example.com/x', 4000, 'http://localhost:5173'),
|
||
|
|
'https://example.com/x',
|
||
|
|
);
|
||
|
|
});
|
||
|
|
}
|