[bug]: When I delete a service it fails to delete tests correctly.
Describe the bug
Suppose I created a service using this command: stacked create service realtime
Now I want to delete this using this command: stacked delete service realtime
It deletes most of the things but fails to delete the test with this response:
[SEVERE] mockito:mockBuilder on test/helpers/test_helpers.dart:
Invalid @GenerateMocks annotation: Mockito cannot mock unknown type `RealtimeService`. Did you misspell it or forget to add a dependency on it?
[INFO] Running build completed, took 10.5s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 274ms
[SEVERE] Failed after 10.7s
Command complete. ExitCode: 1
I tried it multiple times but it gives me the same behaviour.
To reproduce
Create a service: stacked create service realtime
delete the created service: stacked delete service realtime
Stacked CLI version: 1.11.2
Expected behavior
It deletes all the test-related code correctly.
Screenshots
No response
Additional Context
No response
Hi @MDSADABWASIM , can you show me your test_helpers.dart file please?
@ferrarafer After adding the realtime service(test_helpers.dart):
import 'package:camio_truck_owner/app/app.locator.dart';
import 'package:mockito/annotations.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:camio_truck_owner/services/local_storage_service.dart';
import 'package:camio_truck_owner/services/realtime_service.dart';
// @stacked-import
import 'test_helpers.mocks.dart';
@GenerateMocks([], customMocks: [
MockSpec<NavigationService>(onMissingStub: OnMissingStub.returnDefault),
MockSpec<LocalStorageService>(onMissingStub: OnMissingStub.returnDefault),
MockSpec<RealtimeService>(onMissingStub: OnMissingStub.returnDefault),
// @stacked-mock-spec
])
void registerServices() {
getAndRegisterNavigationService();
getAndRegisterLocalStorageService();
getAndRegisterRealtimeService();
// @stacked-mock-register
}
MockNavigationService getAndRegisterNavigationService() {
_removeRegistrationIfExists<NavigationService>();
final service = MockNavigationService();
locator.registerSingleton<NavigationService>(service);
return service;
}
MockLocalStorageService getAndRegisterLocalStorageService() {
_removeRegistrationIfExists<LocalStorageService>();
final service = MockLocalStorageService();
locator.registerSingleton<LocalStorageService>(service);
return service;
}
MockRealtimeService getAndRegisterRealtimeService() {
_removeRegistrationIfExists<RealtimeService>();
final service = MockRealtimeService();
locator.registerSingleton<RealtimeService>(service);
return service;
}
// @stacked-mock-create
void _removeRegistrationIfExists<T extends Object>() {
if (locator.isRegistered<T>()) {
locator.unregister<T>();
}
}
It stays the same after deleting the service, I think it's happening cause CLI is deleting test_helpers.mocks.dart before removing the service from here.
Hi @MDSADABWASIM , I was able to reproduce the issue, I will fix it as soon as possible.
In the meantime, a workaround is to follow this steps on test_helpers.dart:
- Remove
MockSpec<RealtimeService>(onMissingStub: OnMissingStub.returnDefault),line - Remove
getAndRegisterRealtimeService();line - execute
stacked generate
Hello
i accidently deleted the test file and now i cant run stacked create service
what i can do