Skip to content

feat: made resetAdapters public#1014

Merged
themisir merged 5 commits into
isar:masterfrom
alestiago:feat/reset-adapters
Jun 30, 2022
Merged

feat: made resetAdapters public#1014
themisir merged 5 commits into
isar:masterfrom
alestiago:feat/reset-adapters

Conversation

@alestiago

@alestiago alestiago commented Jun 30, 2022

Copy link
Copy Markdown
Contributor

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

Comment thread hive/lib/src/hive.dart
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

@themisir themisir left a comment

Copy link
Copy Markdown
Contributor

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