Skip to content

Commit 1c1c5d8

Browse files
committed
fix: coverage
1 parent 275f3a9 commit 1c1c5d8

1 file changed

Lines changed: 73 additions & 7 deletions

File tree

test/src/commands/create/commands/flutter_plugin_test.dart

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@ import 'package:mason/mason.dart';
99
import 'package:mocktail/mocktail.dart';
1010
import 'package:path/path.dart' as path;
1111
import 'package:test/test.dart';
12+
import 'package:very_good_cli/src/cli/cli.dart';
1213
import 'package:very_good_cli/src/commands/commands.dart';
1314

1415
import '../../../../helpers/helpers.dart';
1516

17+
class _TestProcess {
18+
Future<ProcessResult> run(
19+
String command,
20+
List<String> args, {
21+
bool runInShell = false,
22+
String? workingDirectory,
23+
}) {
24+
throw UnimplementedError();
25+
}
26+
}
27+
28+
class _MockProcess extends Mock implements _TestProcess {}
29+
1630
class _MockLogger extends Mock implements Logger {}
1731

1832
class _MockProgress extends Mock implements Progress {}
@@ -143,9 +157,7 @@ void main() {
143157
vars: any(named: 'vars'),
144158
logger: any(named: 'logger'),
145159
),
146-
).thenAnswer((_) async {
147-
return generatedFiles;
148-
});
160+
).thenAnswer((_) async => generatedFiles);
149161

150162
when(() => generator.id).thenReturn('generator_id');
151163
when(() => generator.description).thenReturn('generator description');
@@ -169,6 +181,26 @@ void main() {
169181
File(path.join(target.dir.path, 'pubspec.yaml'))
170182
..createSync(recursive: true)
171183
..writeAsStringSync(pubspec);
184+
185+
for (final platform in ['android', 'ios', 'windows']) {
186+
Directory(
187+
path.join(
188+
target.dir.path,
189+
'my_plugin_$platform',
190+
'pigeons',
191+
),
192+
).createSync(recursive: true);
193+
194+
File(
195+
path.join(
196+
target.dir.path,
197+
'my_plugin_$platform',
198+
'pigeons',
199+
'messages.dart',
200+
),
201+
).writeAsStringSync('');
202+
}
203+
172204
return generatedFiles;
173205
});
174206
});
@@ -177,6 +209,8 @@ void main() {
177209
final tempDirectory = Directory.systemTemp.createTempSync();
178210
addTearDown(() => tempDirectory.deleteSync(recursive: true));
179211

212+
const platforms = ['android', 'ios', 'windows'];
213+
180214
final argResults = _MockArgResults();
181215
final command = CreateFlutterPlugin(
182216
logger: logger,
@@ -189,26 +223,43 @@ void main() {
189223
when(() => argResults.rest).thenReturn(['my_plugin']);
190224
when(
191225
() => argResults['platforms'] as List<String>,
192-
).thenReturn(['android', 'ios', 'windows']);
226+
).thenReturn(platforms);
193227

194-
final result = await command.run();
228+
final process = _MockProcess();
229+
when(
230+
() => process.run(
231+
any(),
232+
any(),
233+
runInShell: any(named: 'runInShell'),
234+
workingDirectory: any(named: 'workingDirectory'),
235+
),
236+
).thenAnswer(
237+
(_) async => ProcessResult(42, ExitCode.success.code, '', ''),
238+
);
239+
240+
final result = await ProcessOverrides.runZoned(
241+
command.run,
242+
runProcess: process.run,
243+
);
195244

196245
expect(command.template.name, 'flutter_plugin');
197246
expect(result, equals(ExitCode.success.code));
198247

199248
verify(() => logger.progress('Bootstrapping')).called(1);
249+
200250
verify(
201251
() => hooks.preGen(
202252
vars: <String, dynamic>{
203253
'project_name': 'my_plugin',
204254
'description': '',
205255
'org_name': 'com.example.verygoodcore',
206256
'publishable': false,
207-
'platforms': ['android', 'ios', 'windows'],
257+
'platforms': platforms,
208258
},
209259
onVarsChanged: any(named: 'onVarsChanged'),
210260
),
211261
);
262+
212263
verify(
213264
() => generator.generate(
214265
any(),
@@ -217,14 +268,29 @@ void main() {
217268
'description': '',
218269
'org_name': 'com.example.verygoodcore',
219270
'publishable': false,
220-
'platforms': ['android', 'ios', 'windows'],
271+
'platforms': platforms,
221272
},
222273
logger: logger,
223274
),
224275
).called(1);
276+
225277
verify(
226278
() => logger.info('Created a Very Good Flutter Plugin! 🦄'),
227279
).called(1);
280+
281+
verify(
282+
() => process.run(
283+
'dart',
284+
[
285+
'run',
286+
'pigeon',
287+
'--input',
288+
path.join('pigeons', 'messages.dart'),
289+
],
290+
runInShell: any(named: 'runInShell'),
291+
workingDirectory: any(named: 'workingDirectory'),
292+
),
293+
).called(platforms.length);
228294
});
229295
});
230296
});

0 commit comments

Comments
 (0)