Skip to content

Commit 0315622

Browse files
committed
coverage
1 parent 0cd0ee8 commit 0315622

File tree

2 files changed

+180
-1
lines changed

2 files changed

+180
-1
lines changed

bricks/dart_frog_prod_server/hooks/pre_gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Future<void> preGen(
3636
final workspaceRoot = getWorkspaceRoot(projectDirectory.path);
3737
if (workspaceRoot == null) {
3838
context.logger.err(
39-
'Unable to determine workspace root for $projectDirectory',
39+
'Unable to determine workspace root for ${projectDirectory.path}',
4040
);
4141
return exit(1);
4242
}

bricks/dart_frog_prod_server/hooks/test/pre_gen_test.dart

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,185 @@ void main() {
163163
expect(exitCalls, equals([1]));
164164
});
165165

166+
test('exits(1) when unable to determine workspace root', () async {
167+
const configuration = RouteConfiguration(
168+
middleware: [],
169+
directories: [],
170+
routes: [],
171+
rogueRoutes: [],
172+
endpoints: {},
173+
);
174+
175+
final directory = Directory.systemTemp.createTempSync();
176+
final server = Directory(
177+
path.join(directory.path, 'server'),
178+
)..createSync();
179+
File(
180+
path.join(server.path, 'pubspec.yaml'),
181+
).writeAsStringSync('''
182+
name: server
183+
description: A new Dart Frog application
184+
version: 1.0.0+1
185+
publish_to: none
186+
resolution: workspace
187+
188+
environment:
189+
sdk: ^3.6.0
190+
191+
dependencies:
192+
dart_frog: ^1.1.0
193+
protocol: ^1.0.0
194+
''');
195+
final exitCalls = <int>[];
196+
await pre_gen.preGen(
197+
context,
198+
buildConfiguration: (_) => configuration,
199+
exit: exitCalls.add,
200+
directory: server,
201+
runProcess: successRunProcess,
202+
copyPath: (_, __) async {},
203+
);
204+
205+
expect(exitCalls, equals([1]));
206+
verify(
207+
() => logger.err(
208+
'Unable to determine workspace root for ${server.path}',
209+
),
210+
).called(1);
211+
directory.delete(recursive: true).ignore();
212+
});
213+
214+
test('exits(1) when unable to find package_config.json', () async {
215+
const configuration = RouteConfiguration(
216+
middleware: [],
217+
directories: [],
218+
routes: [],
219+
rogueRoutes: [],
220+
endpoints: {},
221+
);
222+
223+
final directory = Directory.systemTemp.createTempSync();
224+
File(
225+
path.join(directory.path, 'pubspec.yaml'),
226+
).writeAsStringSync('''
227+
name: _
228+
publish_to: none
229+
230+
environment:
231+
sdk: ^3.6.0
232+
233+
workspace:
234+
- packages/client
235+
- packages/protocol
236+
- packages/models
237+
- packages/server
238+
''');
239+
final server = Directory(
240+
path.join(directory.path, 'server'),
241+
)..createSync();
242+
File(
243+
path.join(server.path, 'pubspec.yaml'),
244+
).writeAsStringSync('''
245+
name: server
246+
description: A new Dart Frog application
247+
version: 1.0.0+1
248+
publish_to: none
249+
resolution: workspace
250+
251+
environment:
252+
sdk: ^3.6.0
253+
254+
dependencies:
255+
dart_frog: ^1.1.0
256+
protocol: ^1.0.0
257+
''');
258+
final exitCalls = <int>[];
259+
await pre_gen.preGen(
260+
context,
261+
buildConfiguration: (_) => configuration,
262+
exit: exitCalls.add,
263+
directory: server,
264+
runProcess: successRunProcess,
265+
copyPath: (_, __) async {},
266+
);
267+
268+
expect(exitCalls, equals([1]));
269+
verify(
270+
() => logger.err(
271+
'Unable to find package_config.json for ${directory.path}',
272+
),
273+
).called(1);
274+
directory.delete(recursive: true).ignore();
275+
});
276+
277+
test('exits(1) when unable to find package_graph.json', () async {
278+
const configuration = RouteConfiguration(
279+
middleware: [],
280+
directories: [],
281+
routes: [],
282+
rogueRoutes: [],
283+
endpoints: {},
284+
);
285+
286+
final directory = Directory.systemTemp.createTempSync();
287+
File(
288+
path.join(directory.path, '.dart_tool', 'package_config.json'),
289+
)
290+
..createSync(recursive: true)
291+
..writeAsStringSync(packageConfigWithDirectAndTransitiveDependencies);
292+
File(
293+
path.join(directory.path, 'pubspec.yaml'),
294+
).writeAsStringSync('''
295+
name: _
296+
publish_to: none
297+
298+
environment:
299+
sdk: ^3.6.0
300+
301+
workspace:
302+
- packages/client
303+
- packages/protocol
304+
- packages/models
305+
- packages/server
306+
''');
307+
final server = Directory(
308+
path.join(directory.path, 'server'),
309+
)..createSync();
310+
File(
311+
path.join(server.path, 'pubspec.yaml'),
312+
).writeAsStringSync('''
313+
name: server
314+
description: A new Dart Frog application
315+
version: 1.0.0+1
316+
publish_to: none
317+
resolution: workspace
318+
319+
environment:
320+
sdk: ^3.6.0
321+
322+
dependencies:
323+
dart_frog: ^1.1.0
324+
protocol: ^1.0.0
325+
''');
326+
final exitCalls = <int>[];
327+
await pre_gen.preGen(
328+
context,
329+
buildConfiguration: (_) => configuration,
330+
exit: exitCalls.add,
331+
directory: server,
332+
runProcess: successRunProcess,
333+
copyPath: (_, __) async {},
334+
);
335+
336+
expect(exitCalls, equals([1]));
337+
verify(
338+
() => logger.err(
339+
'Unable to find package_graph.json for ${directory.path}',
340+
),
341+
).called(1);
342+
directory.delete(recursive: true).ignore();
343+
});
344+
166345
test('works with workspaces', () async {
167346
const configuration = RouteConfiguration(
168347
middleware: [],

0 commit comments

Comments
 (0)