|
1 | 1 | import 'dart:io';
|
2 | 2 |
|
3 | 3 | import 'package:dart_frog_gen/dart_frog_gen.dart';
|
4 |
| -import 'package:mason/mason.dart' show HookContext, Logger, Progress, lightCyan; |
| 4 | +import 'package:mason/mason.dart' |
| 5 | + show HookContext, Logger, Progress, defaultForeground, lightCyan; |
5 | 6 | import 'package:mocktail/mocktail.dart';
|
6 | 7 | import 'package:path/path.dart' as path;
|
7 | 8 | import 'package:test/test.dart';
|
@@ -95,6 +96,7 @@ void main() {
|
95 | 96 | RouteFile(name: 'index', path: 'index.dart', route: '/'),
|
96 | 97 | RouteFile(name: 'hello', path: 'hello.dart', route: '/hello'),
|
97 | 98 | ],
|
| 99 | + rogueRoutes: [], |
98 | 100 | endpoints: {
|
99 | 101 | '/': [
|
100 | 102 | RouteFile(name: 'index', path: 'index.dart', route: '/'),
|
@@ -302,6 +304,66 @@ dev_dependencies:
|
302 | 304 | expect(exitCalls, equals([1]));
|
303 | 305 | });
|
304 | 306 | });
|
| 307 | + |
| 308 | + group('reportRogueRoutes', () { |
| 309 | + late HookContext context; |
| 310 | + late Logger logger; |
| 311 | + late RouteConfiguration configuration; |
| 312 | + |
| 313 | + setUp(() { |
| 314 | + context = _MockHookContext(); |
| 315 | + logger = _MockLogger(); |
| 316 | + configuration = _MockRouteConfiguration(); |
| 317 | + |
| 318 | + when(() => context.logger).thenReturn(logger); |
| 319 | + }); |
| 320 | + |
| 321 | + test('reports nothing when there are no rogue routes', () { |
| 322 | + final exitCalls = <int>[]; |
| 323 | + when(() => configuration.rogueRoutes).thenReturn([]); |
| 324 | + reportRogueRoutes(context, configuration, exitCalls.add); |
| 325 | + verifyNever(() => logger.err(any())); |
| 326 | + expect(exitCalls, isEmpty); |
| 327 | + }); |
| 328 | + |
| 329 | + test('reports single rogue route', () { |
| 330 | + final exitCalls = <int>[]; |
| 331 | + when(() => configuration.rogueRoutes).thenReturn( |
| 332 | + const [ |
| 333 | + RouteFile(name: 'hello', path: 'hello.dart', route: '/hello'), |
| 334 | + ], |
| 335 | + ); |
| 336 | + reportRogueRoutes(context, configuration, exitCalls.add); |
| 337 | + verify( |
| 338 | + () => logger.err( |
| 339 | + '''Rogue route detected.${defaultForeground.wrap(' ')}Rename ${lightCyan.wrap('routes/hello.dart')} to ${lightCyan.wrap('routes/hello/index.dart')}.''', |
| 340 | + ), |
| 341 | + ); |
| 342 | + expect(exitCalls, equals([1])); |
| 343 | + }); |
| 344 | + |
| 345 | + test('reports multiple rogue routes', () { |
| 346 | + final exitCalls = <int>[]; |
| 347 | + when(() => configuration.rogueRoutes).thenReturn( |
| 348 | + const [ |
| 349 | + RouteFile(name: 'hello', path: 'hello.dart', route: '/hello'), |
| 350 | + RouteFile(name: 'hi', path: 'hi.dart', route: '/hi'), |
| 351 | + ], |
| 352 | + ); |
| 353 | + reportRogueRoutes(context, configuration, exitCalls.add); |
| 354 | + verify( |
| 355 | + () => logger.err( |
| 356 | + '''Rogue route detected.${defaultForeground.wrap(' ')}Rename ${lightCyan.wrap('routes/hello.dart')} to ${lightCyan.wrap('routes/hello/index.dart')}.''', |
| 357 | + ), |
| 358 | + ); |
| 359 | + verify( |
| 360 | + () => logger.err( |
| 361 | + '''Rogue route detected.${defaultForeground.wrap(' ')}Rename ${lightCyan.wrap('routes/hi.dart')} to ${lightCyan.wrap('routes/hi/index.dart')}.''', |
| 362 | + ), |
| 363 | + ); |
| 364 | + expect(exitCalls, equals([1])); |
| 365 | + }); |
| 366 | + }); |
305 | 367 | });
|
306 | 368 |
|
307 | 369 | group('ExitOverrides', () {
|
|
0 commit comments