Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: made resetAdapters public #1014

Merged
merged 5 commits into from
Jun 30, 2022
Merged

Conversation

alestiago
Copy link
Contributor

@alestiago alestiago commented Jun 30, 2022

Status

READY

Breaking Changes

NO

Description

Makes the clearAdapters part of the public API.

When configuring integration tests one usually does the following:

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:my_app/main/main.dart' as app;

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized().framePolicy =
      LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;

  group('login', () {
    setUp(app.main); // This setup registers the adapters.

    testWidgets('unsuccessful when missing username', (tester) async {
      // Some logic here.
    });

    testWidgets('unsuccessful when missing password', (tester) async {
      // Some logic here.
    });
  });
}

However, only the test that runs first succeeds since when the second test aims to registerAdapter a HiveError is thrown since the adapter already exists.

// main.dart
...
  await Hive.initFlutter();
  Hive.registerAdapter(MobileSettingsAdapter());
...

There are workarounds to solve the above, like for example making use of the override flag in registerAdapter or checking if the adapter has been already registered before registering one. I dislike these approaches since they force to write logic in the codebase that is only used for and during testing purposes.

Ideally, I would prefer if one could tearDown and clearAdapters. And with the changes in this PR, one can tearDown and clearAdapters.

I'm open to other suggestions or existing solutions that only modify the test file.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

alestiago and others added 2 commits June 30, 2022 15:04
Co-authored-by: Misir Jafarov <misir.ceferov@gmail.com>
@alestiago alestiago requested a review from themisir June 30, 2022 14:07
Copy link
Contributor

@themisir themisir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants