fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 300 forks source link

feat: mock mode #2248

Closed Tienisto closed 3 months ago

Tienisto commented 3 months ago

Changes

Fixes #2247.

Checklist

Remark for PR creator

welcome[bot] commented 3 months ago

Hi! Thanks for opening this pull request! :smile:

fzyzcjy commented 3 months ago

Good job! Some nits

  1. I am wondering, for user-facing API, whether we should make it a separate function initMock, or the same function with an extra arg init({..., bool mock})? (I think both have pros and cons...)
  2. To fix CI, try ./frb_internal precommit-generate (which takes at least several minutes to run since it runs codegen in debug mode for many folders)
Tienisto commented 3 months ago

Thanks for the quick response!

Actually, I had it like init({..., bool mock}) originally. However, I thought it would be unclear what parameters are used and I didn't like that api is optional while it is not when mock is true. A separate function would be more type safe in this case. I am fine with both solutions though.

Edit: I've run ./frb_internal precommit-generate but it doesn't seem to fix all issues. Do you know what's missing?

fzyzcjy commented 3 months ago

You are welcome!

However, I thought it would be unclear what parameters are used and I didn't like that api is optional while it is not when mock is true. A separate function would be more type safe in this case.

Looks pretty reasonable.

I've run ./frb_internal precommit-generate but it doesn't seem to fix all issues. Do you know what's missing?

Looks like need to edit https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_codegen/assets/integration_template/shared (e.g. copy-paste/modify things according to the CI hint) which is the template

Tienisto commented 3 months ago

Thanks! I am currently not at home so feel free to add it. Otherwise, I will add it tomorrow

fzyzcjy commented 3 months ago

@all-contributors please add @Tienisto for code

allcontributors[bot] commented 3 months ago

@fzyzcjy

I've put up a pull request to add @Tienisto! :tada:

welcome[bot] commented 3 months ago

Hi! Congrats on merging your first pull request! :tada:

fzyzcjy commented 3 months ago

@Tienisto Looks like codecov is unhappy (see below; not sure why codecov does not appear in this PR...). Maybe we can add a few lines in https://github.com/fzyzcjy/flutter_rust_bridge/blob/master/frb_example/pure_dart/test/mockability_test.dart to test this code path.

image

https://app.codecov.io/gh/fzyzcjy/flutter_rust_bridge/commit/c5bdedbbb1b222162bdc88d28e96313b687007a8

image