Setup:
- Clone repository
- Run
chromedriver --port=4444
in another terminal - Run
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/example_test.dart -d chrome
It seems like the test is running twice as there are two documents inserted into Firestore where there should only be one document inserted.
This behavior is only happening on web, it doesn't produce the same behavior on iOS
If you clone the repo and test it for yourself please change the collection name of examples
to something else to not clash with other testers
Code for when the repository is removed
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
final now = DateTime.now();
const String collectionName = 'examples';
String currentMinute = DateFormat.yMd().add_jm().format(now);
documentsInsertedThisMinute() async {
var collection = FirebaseFirestore.instance.collection(collectionName);
var snapshots =
await collection.where('foobar', isEqualTo: currentMinute).get();
return snapshots.size;
}
setUpAll(() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
});
testWidgets(
'Single document created',
(WidgetTester tester) async {
int preExistingDocuments = await documentsInsertedThisMinute();
print('Pre-existing documents: $preExistingDocuments');
await tester.pumpWidget(const MyApp());
await FirebaseFirestore.instance
.collection(collectionName)
.doc()
.set({'foobar': currentMinute});
int documentsAfterSingleInsert = await documentsInsertedThisMinute();
expect(documentsAfterSingleInsert, 1);
},
);
}
I had the same issues with running the code twice when using
-d chrome
with or without--headless
flag.What I use:
Multiline Linux
Multiline Windows (Powershell)
Also documented here, of course it doesn't specify if you run it in
-d chrome
it will behave as such.