Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ void main() {
);
});

testServer(port: project1Server2Port, 'GET / on project 1 server 2',
(host) async {
testServer(port: project1Server2Port, 'GET / on project 1 server 2', (
host,
) async {
final response = await http.get(Uri.parse(host));
expect(response.statusCode, equals(HttpStatus.ok));
expect(response.body, equals('Welcome to Dart Frog!'));
Expand Down Expand Up @@ -233,8 +234,9 @@ void main() {
expect(response.isSuccess, isTrue);
});

testServer(port: project2ServerPort, 'GET /new_route on project 2',
(host) async {
testServer(port: project2ServerPort, 'GET /new_route on project 2', (
host,
) async {
final response = await http.get(Uri.parse(host));
expect(response.statusCode, equals(HttpStatus.ok));
expect(response.headers, contains('date'));
Expand All @@ -245,27 +247,27 @@ void main() {
});

test('try staggered-stop a dev server on project 1', () async {
final (response1, response2) =
await daemonStdio.sendStaggeredDaemonRequest(
(
DaemonRequest(
id: '${++requestCount}',
domain: 'dev_server',
method: 'stop',
params: {
'applicationId': project1Server1Id,
},
),
DaemonRequest(
id: '${++requestCount}',
domain: 'dev_server',
method: 'stop',
params: {
'applicationId': project1Server1Id,
},
),
),
);
final (response1, response2) = await daemonStdio
.sendStaggeredDaemonRequest(
(
DaemonRequest(
id: '${++requestCount}',
domain: 'dev_server',
method: 'stop',
params: {
'applicationId': project1Server1Id,
},
),
DaemonRequest(
id: '${++requestCount}',
domain: 'dev_server',
method: 'stop',
params: {
'applicationId': project1Server1Id,
},
),
),
);

expect(response1.isSuccess, isTrue);
expect(response1.result!['exitCode'], equals(0));
Expand Down Expand Up @@ -305,16 +307,18 @@ void main() {
});

testServer(
// TODO(renancaraujo): this fails on linux: https://github.com/dart-frog-dev/dart_frog/issues/807
skip: Platform.isLinux,
'GET on project 1 server 1: connection refused', (host) async {
final responseFuture = http.get(Uri.parse(host));

await expectLater(
responseFuture,
throwsA(isA<SocketException>()),
);
});
// TODO(renancaraujo): this fails on linux: https://github.com/dart-frog-dev/dart_frog/issues/807
skip: Platform.isLinux,
'GET on project 1 server 1: connection refused',
(host) async {
final responseFuture = http.get(Uri.parse(host));

await expectLater(
responseFuture,
throwsA(isA<SocketException>()),
);
},
);

testServer(
port: project2ServerPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,27 @@ void main() {
});

test('staggered-stop watcher', () async {
final (response1, response2) =
await daemonStdio.sendStaggeredDaemonRequest(
(
DaemonRequest(
id: '${requestCount++}',
domain: 'route_configuration',
method: 'watcherStop',
params: {
'watcherId': projectWatcherId,
},
),
DaemonRequest(
id: '${requestCount++}',
domain: 'route_configuration',
method: 'watcherStop',
params: {
'watcherId': projectWatcherId,
},
),
),
);
final (response1, response2) = await daemonStdio
.sendStaggeredDaemonRequest(
(
DaemonRequest(
id: '${requestCount++}',
domain: 'route_configuration',
method: 'watcherStop',
params: {
'watcherId': projectWatcherId,
},
),
DaemonRequest(
id: '${requestCount++}',
domain: 'route_configuration',
method: 'watcherStop',
params: {
'watcherId': projectWatcherId,
},
),
),
);

expect(response1.isSuccess, isTrue);
expect(response1.result?['exitCode'], equals(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ class DaemonStdioHelper {
Duration timeout = _defaultTimeout,
Matcher? withParamsThat,
}) async {
var wrappedMatcher = isA<DaemonEvent>()
.having((e) => '${e.domain}.${e.event}', 'is $methodKey', methodKey);
var wrappedMatcher = isA<DaemonEvent>().having(
(e) => '${e.domain}.${e.event}',
'is $methodKey',
methodKey,
);

if (withParamsThat != null) {
wrappedMatcher = wrappedMatcher.having(
Expand Down Expand Up @@ -237,7 +240,7 @@ class DaemonStdioHelper {
/// A matcher that matches a [DaemonMessage] to a daemon stdout line.
class _MatchMessageToStdoutLine extends CustomMatcher {
_MatchMessageToStdoutLine(Matcher matcher)
: super('Message to stdout line', 'message', matcher);
: super('Message to stdout line', 'message', matcher);

@override
Object? featureValueOf(dynamic actual) {
Expand Down
22 changes: 10 additions & 12 deletions packages/dart_frog_cli/e2e/test/helpers/dart_frog_new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ import 'run_process.dart';
Future<void> dartFrogNewRoute(
String routePath, {
required Directory directory,
}) =>
_dartFrogNew(
routePath: routePath,
what: 'route',
directory: directory,
);
}) => _dartFrogNew(
routePath: routePath,
what: 'route',
directory: directory,
);

Future<void> dartFrogNewMiddleware(
String routePath, {
required Directory directory,
}) =>
_dartFrogNew(
routePath: routePath,
what: 'middleware',
directory: directory,
);
}) => _dartFrogNew(
routePath: routePath,
what: 'middleware',
directory: directory,
);

Future<void> _dartFrogNew({
required String routePath,
Expand Down
10 changes: 5 additions & 5 deletions packages/dart_frog_cli/e2e/test/helpers/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ final doesNotExist = FileExistsMatcher(isFalse);

class FileExistsMatcher extends CustomMatcher {
FileExistsMatcher(Matcher matcher)
: super(
'File exists',
'file exists',
isA<File>().having((p) => p.existsSync(), 'exists', matcher),
);
: super(
'File exists',
'file exists',
isA<File>().having((p) => p.existsSync(), 'exists', matcher),
);
}
86 changes: 50 additions & 36 deletions packages/dart_frog_cli/e2e/test/new_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ void main() {
});

test('Creates a index route for an existing directory', () async {
Directory(path.join(routesDirectory.path, 'nested'))
.createSync(recursive: true);
Directory(
path.join(routesDirectory.path, 'nested'),
).createSync(recursive: true);

await dartFrogNewRoute('/nested', directory: projectDirectory);

Expand Down Expand Up @@ -118,8 +119,9 @@ void main() {
'Creates route normally when there is a non-dart file with the same '
'route path',
() async {
File(path.join(routesDirectory.path, 'something.py'))
.createSync(recursive: true);
File(
path.join(routesDirectory.path, 'something.py'),
).createSync(recursive: true);

await dartFrogNewRoute('/something', directory: projectDirectory);

Expand Down Expand Up @@ -222,14 +224,16 @@ void main() {
test('Excuse existing endpoints (existing rogue route)', () async {
await dartFrogNewRoute('/existing_rogue', directory: projectDirectory);

Directory(path.join(routesDirectory.path, 'existing_rogue'))
.createSync(recursive: true);
Directory(
path.join(routesDirectory.path, 'existing_rogue'),
).createSync(recursive: true);

await expectLater(
() =>
dartFrogNewRoute('/existing_rogue', directory: projectDirectory),
failsWith(
stderr: 'Failed to create route: Rogue route detected. '
stderr:
'Failed to create route: Rogue route detected. '
'Rename routes${slash}existing_rogue.dart to '
'routes${slash}existing_rogue${slash}index.dart.',
),
Expand All @@ -242,16 +246,18 @@ void main() {
directory: projectDirectory,
);

File(path.join(routesDirectory.path, 'conflicting_route/index.dart'))
.createSync(recursive: true);
File(
path.join(routesDirectory.path, 'conflicting_route/index.dart'),
).createSync(recursive: true);

await expectLater(
() async => dartFrogNewRoute(
'/conflicting_route',
directory: projectDirectory,
),
failsWith(
stderr: 'Failed to create route: '
stderr:
'Failed to create route: '
'Route conflict detected. '
'routes${slash}conflicting_route.dart and '
'routes${slash}conflicting_route${slash}index.dart '
Expand Down Expand Up @@ -384,7 +390,8 @@ void main() {
directory: projectDirectory,
),
failsWith(
stderr: 'There is already a middleware at '
stderr:
'There is already a middleware at '
'routes${slash}existing_middleware${slash}_middleware.dart',
),
);
Expand All @@ -406,7 +413,8 @@ void main() {
directory: projectDirectory,
),
failsWith(
stderr: 'Failed to create middleware: '
stderr:
'Failed to create middleware: '
'Duplicate parameter name found: id',
),
);
Expand Down Expand Up @@ -445,45 +453,51 @@ void main() {
test('Excuse middleware creation upon existing rogue routes', () async {
await dartFrogNewRoute('/existing_rogue', directory: projectDirectory);

Directory(path.join(routesDirectory.path, 'existing_rogue'))
.createSync(recursive: true);
Directory(
path.join(routesDirectory.path, 'existing_rogue'),
).createSync(recursive: true);

await expectLater(
() async => dartFrogNewMiddleware(
'/existing_rogue',
directory: projectDirectory,
),
failsWith(
stderr: 'Failed to create middleware: Rogue route detected. '
stderr:
'Failed to create middleware: Rogue route detected. '
'Rename routes${slash}existing_rogue.dart to '
'routes${slash}existing_rogue${slash}index.dart.',
),
);
});

test('Excuse middleware creation upon existing route conflicts',
() async {
await dartFrogNewRoute(
'/conflicting_route',
directory: projectDirectory,
);

File(path.join(routesDirectory.path, 'conflicting_route/index.dart'))
.createSync(recursive: true);

await expectLater(
() async => dartFrogNewMiddleware(
test(
'Excuse middleware creation upon existing route conflicts',
() async {
await dartFrogNewRoute(
'/conflicting_route',
directory: projectDirectory,
),
failsWith(
stderr: 'Failed to create middleware: Route conflict detected. '
'routes${slash}conflicting_route.dart and '
'routes${slash}conflicting_route${slash}index.dart both '
'resolve to /conflicting_route.',
),
);
});
);

File(
path.join(routesDirectory.path, 'conflicting_route/index.dart'),
).createSync(recursive: true);

await expectLater(
() async => dartFrogNewMiddleware(
'/conflicting_route',
directory: projectDirectory,
),
failsWith(
stderr:
'Failed to create middleware: Route conflict detected. '
'routes${slash}conflicting_route.dart and '
'routes${slash}conflicting_route${slash}index.dart both '
'resolve to /conflicting_route.',
),
);
},
);
});
});
}
Loading