Open tienlocbui1110 opened 2 years ago
Great bug report, thanks! Definitely a bug somewhere in mockito, analyzer, build, code_builder, or source_gen...
@srawlins can you elaborate more so we can help because we are facing the same issue?
I don't have a repro and have not investigated, but looking at @tienlocbui1110 's code above, in the first case, FocusNode
is imported from 'package:flutter/material.dart'
, and in the second, 'package:flutter/cupertino.dart'
. This is the only difference I see.
yes, this is exactly the problem.
for us, in CI we check if the files have been generated or not by running the command and checking the git status. when this ranom thingy happens, the PR fails.
we need the mocks to be the same if the source files haven't changed.
The problem is that both 'package:flutter/material.dart'
and 'package:flutter/cupertino.dart'
export 'package:flutter/widgets.dart'
, so the contents of the latter is kinda imported twice, and I guess Mockito's codegen randomly picks one at runtime, assuming there will be only one. We need to sort the possible imports before picking one, that would fix the issue.
I didn't debug it, but I'd try changing https://github.com/dart-lang/mockito/blob/cca4858ad0f1e3930ebdcc6faf4a918616cca48c/lib/src/builder.dart#L151
to use SplayTreeSet
instead and see if it helps.
Description
Problem
Let's take a look at the code below.
dummy_widget.dart
dummy_test.dart
After generate multiple times, I have two output here:
dummy_test.mocks.dart
dummy_test.mocks.dart
As you can see, the different between two files all about randomly import. FocusNode can be imported from cupertino and material as well, so they randomly change the contents, which I don't want.
I have try to import in dummy_widget.dart like this, but have no effect.
Environment
Dart SDK version: 2.15.0 build_runner: 2.1.5 mockito: 5.1.0
Question