feat: config bloc test

This commit is contained in:
appflowy 2022-02-19 16:48:57 +08:00
parent 2c3aade0f9
commit c559c5cc6b
9 changed files with 204 additions and 46 deletions

View File

@ -14,6 +14,7 @@ RUST_LOG = "info"
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_CRATE_FS_NAME = "dart_ffi" CARGO_MAKE_CRATE_FS_NAME = "dart_ffi"
CARGO_MAKE_CRATE_NAME = "dart-ffi" CARGO_MAKE_CRATE_NAME = "dart-ffi"
LIB_NAME = "dart_ffi"
VERSION = "0.0.3" VERSION = "0.0.3"
FEATURES = "flutter" FEATURES = "flutter"
PRODUCT_NAME = "AppFlowy" PRODUCT_NAME = "AppFlowy"
@ -31,6 +32,8 @@ RUST_COMPILE_TARGET = "x86_64-apple-darwin"
BUILD_FLAG = "debug" BUILD_FLAG = "debug"
FLUTTER_OUTPUT_DIR = "Debug" FLUTTER_OUTPUT_DIR = "Debug"
PRODUCT_EXT = "app" PRODUCT_EXT = "app"
CRATE_TYPE = "cdylib"
SDK_EXT = "dylib"
[env.production-mac-aarch64] [env.production-mac-aarch64]
BUILD_FLAG = "release" BUILD_FLAG = "release"
@ -39,6 +42,7 @@ RUST_COMPILE_TARGET = "aarch64-apple-darwin"
FLUTTER_OUTPUT_DIR = "Release" FLUTTER_OUTPUT_DIR = "Release"
PRODUCT_EXT = "app" PRODUCT_EXT = "app"
APP_ENVIRONMENT = "production" APP_ENVIRONMENT = "production"
CRATE_TYPE = "staticlib"
[env.production-mac-x86] [env.production-mac-x86]
BUILD_FLAG = "release" BUILD_FLAG = "release"
@ -153,7 +157,6 @@ script = [
] ]
script_runner = "@duckscript" script_runner = "@duckscript"
[tasks.test-build] [tasks.test-build]
condition = { env_set = [ "FLUTTER_FLOWY_SDK_PATH"] } condition = { env_set = [ "FLUTTER_FLOWY_SDK_PATH"] }
script = [ script = [

View File

@ -12,12 +12,22 @@ final DynamicLibrary _dl = _open();
/// Reference to the Dynamic Library, it should be only used for low-level access /// Reference to the Dynamic Library, it should be only used for low-level access
final DynamicLibrary dl = _dl; final DynamicLibrary dl = _dl;
DynamicLibrary _open() { DynamicLibrary _open() {
if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so'); if (Platform.environment.containsKey('FLUTTER_TEST')) {
if (Platform.isMacOS) return DynamicLibrary.executable(); final prefix = "${Directory.systemTemp.path}/appflowy";
if (Platform.isIOS) return DynamicLibrary.executable(); if (Platform.isLinux) return DynamicLibrary.open('${prefix}/libdart_ffi.so');
if (Platform.isWindows) return DynamicLibrary.open('dart_ffi.dll'); if (Platform.isAndroid) return DynamicLibrary.open('${prefix}/libdart_ffi.so');
if (Platform.isLinux) return DynamicLibrary.open('libdart_ffi.so'); if (Platform.isMacOS) return DynamicLibrary.open('${prefix}/libdart_ffi.dylib');
throw UnsupportedError('This platform is not supported.'); if (Platform.isIOS) return DynamicLibrary.open('${prefix}/libdart_ffi.dylib');
if (Platform.isWindows) return DynamicLibrary.open('${prefix}/dart_ffi.dll');
throw UnsupportedError('This platform is not supported.');
} else {
if (Platform.isLinux) return DynamicLibrary.open('libdart_ffi.so');
if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so');
if (Platform.isMacOS) return DynamicLibrary.executable();
if (Platform.isIOS) return DynamicLibrary.executable();
if (Platform.isWindows) return DynamicLibrary.open('dart_ffi.dll');
throw UnsupportedError('This platform is not supported.');
}
} }
/// C function `async_event`. /// C function `async_event`.

View File

@ -43,6 +43,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.0.2" version: "8.0.2"
bloc_test:
dependency: "direct dev"
description:
name: bloc_test
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.2"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
@ -211,6 +218,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.1" version: "3.0.1"
coverage:
dependency: transitive
description:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
cross_file: cross_file:
dependency: transitive dependency: transitive
description: description:
@ -702,6 +716,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.1" version: "1.0.1"
mocktail:
dependency: transitive
description:
name: mocktail
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
nested: nested:
dependency: transitive dependency: transitive
description: description:
@ -716,6 +737,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.2" version: "0.4.2"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
package_config: package_config:
dependency: transitive dependency: transitive
description: description:
@ -982,6 +1010,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
shelf_web_socket: shelf_web_socket:
dependency: transitive dependency: transitive
description: description:
@ -1008,6 +1050,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.1" version: "1.2.1"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.10"
source_span: source_span:
dependency: transitive dependency: transitive
description: description:
@ -1071,6 +1127,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
test:
dependency: transitive
description:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.19.5"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
@ -1078,6 +1141,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.8"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
textstyle_extensions: textstyle_extensions:
dependency: transitive dependency: transitive
description: description:
@ -1211,6 +1281,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.6" version: "2.0.6"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "7.5.0"
watcher: watcher:
dependency: transitive dependency: transitive
description: description:
@ -1225,6 +1302,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
win32: win32:
dependency: transitive dependency: transitive
description: description:

View File

@ -80,6 +80,7 @@ dev_dependencies:
sdk: flutter sdk: flutter
build_runner: build_runner:
freezed: "^0.14.2" freezed: "^0.14.2"
bloc_test: ^9.0.2
# The "flutter_lints" package below contains a set of recommended lints to # The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is # encourage good coding practices. The lint set provided by the package is

View File

@ -0,0 +1,42 @@
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flowy_sdk/log.dart';
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart';
import 'package:flutter/material.dart';
class FlowyTest {
static Future<FlowyTest> setup() async {
WidgetsFlutterBinding.ensureInitialized();
// await EasyLocalization.ensureInitialized();
System.run(FlowyTestApp());
return FlowyTest();
}
Future<UserProfile> signIn() async {
final authRepo = getIt<AuthRepository>();
const password = "AppFlowy123@";
final uid = uuid();
final userEmail = "$uid@appflowy.io";
final result = await authRepo.signUp(
name: "FlowyTestUser",
password: password,
email: userEmail,
);
return result.fold(
(user) => user,
(error) {
throw StateError("$error");
},
);
}
}
class FlowyTestApp implements EntryPoint {
@override
Widget create() {
return Container();
}
}

View File

@ -1 +0,0 @@

View File

@ -0,0 +1,30 @@
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart';
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:bloc_test/bloc_test.dart';
import 'util/test_env.dart';
void main() {
UserProfile? userInfo;
setUpAll(() async {
final flowyTest = await FlowyTest.setup();
userInfo = await flowyTest.signIn();
});
group('WelcomeBloc', () {
blocTest<WelcomeBloc, WelcomeState>(
"create workspace",
build: () => getIt<WelcomeBloc>(param1: userInfo),
act: (bloc) {
bloc.add(const WelcomeEvent.initial());
},
wait: const Duration(seconds: 2),
verify: (bloc) {
assert(bloc.state.isLoading == false);
assert((bloc.state.workspaces.length) == 1);
},
);
});
}

View File

@ -16,17 +16,17 @@ linux_alias = "flowy-sdk-dev-linux"
[tasks.flowy-sdk-dev-macos] [tasks.flowy-sdk-dev-macos]
category = "Build" category = "Build"
dependencies = ["env_check"] dependencies = ["env_check"]
run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type"] } run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type", "copy-to-sys-tmpdir"] }
[tasks.flowy-sdk-dev-windows] [tasks.flowy-sdk-dev-windows]
category = "Build" category = "Build"
dependencies = ["env_check"] dependencies = ["env_check"]
run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type"] } run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type", "copy-to-sys-tmpdir"] }
[tasks.flowy-sdk-dev-linux] [tasks.flowy-sdk-dev-linux]
category = "Build" category = "Build"
dependencies = ["env_check"] dependencies = ["env_check"]
run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type"] } run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type", "copy-to-sys-tmpdir"] }
# #
[tasks.sdk-build] [tasks.sdk-build]
@ -82,27 +82,29 @@ private = true
script = [ script = [
""" """
echo "🚀 🚀 🚀 Flowy-SDK(macOS) build success" echo "🚀 🚀 🚀 Flowy-SDK(macOS) build success"
dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages/flowy_sdk/${TARGET_OS}
lib = set lib${LIB_NAME}.${SDK_EXT}
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} \ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages/flowy_sdk/${TARGET_OS}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} ${dart_ffi_dir}/${lib}
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/packages/flowy_sdk/${TARGET_OS}/Classes/binding.h ${dart_ffi_dir}/Classes/binding.h
""", """,
] ]
script_runner = "@duckscript" script_runner = "@duckscript"
[tasks.post-desktop-windows] [tasks.post-desktop-windows]
private = true private = true
script = [ script = [
""" """
echo "🚀 🚀 🚀 Flowy-SDK(windows) build success" echo "🚀 🚀 🚀 Flowy-SDK(windows) build success"
dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/windows/flutter/dart_ffi dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/windows/flutter/dart_ffi
lib = set ${LIB_NAME}.${SDK_EXT}
# copy dll # copy dll
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} \ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \
${dart_ffi_dir}/${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} ${dart_ffi_dir}/${lib}
# copy binding.h # copy binding.h
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \
@ -117,10 +119,11 @@ script = [
""" """
echo "🚀 🚀 🚀 Flowy-SDK(linux) build success" echo "🚀 🚀 🚀 Flowy-SDK(linux) build success"
dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/linux/flutter/dart_ffi dart_ffi_dir= set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/linux/flutter/dart_ffi
lib = set lib${LIB_NAME}.${SDK_EXT}
# copy dll # copy dll
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} \ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \
${dart_ffi_dir}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} ${dart_ffi_dir}/${lib}
# copy binding.h # copy binding.h
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/binding.h \
@ -129,29 +132,28 @@ script = [
] ]
script_runner = "@duckscript" script_runner = "@duckscript"
#
[tasks.copy-to-sys-tmpdir] [tasks.copy-to-sys-tmpdir]
private = true private = true
condition = { profiles = [ "development-mac" ], platforms = ["mac"] }
script = [ script = [
""" """
# post the dylib target_path that use for flutter unit test # Copy the flowy_sdk lib to system temp directory for flutter unit test.
target_path = set ${TMPDIR}/appflowy/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} lib = set lib${LIB_NAME}.${SDK_EXT}
rm ${target_path} dest = set ${TMPDIR}/appflowy/${lib}
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/lib${CARGO_MAKE_CRATE_FS_NAME}.${SDK_EXT} ${target_path} echo ${dest}
rm ${dest}
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${RUST_COMPILE_TARGET}/${BUILD_FLAG}/${lib} \
${dest}
""", """,
] ]
script_runner = "@duckscript" script_runner = "@duckscript"
[tasks.check_protoc_cmd] [tasks.copy-to-sys-tmpdir.windows]
private = true
script = [ script = [
""" """
ret = which protoc # Doesn't work on windows
if is_empty ${ret}
echo Please make sure <protoc_installation_folder>/bin/ is in PATH env var
echo See BUILD_ON_{LINUX|WINDOWS}.md for how to get protoc
exit -1
end
""", """,
] ]
script_runner = "@duckscript" script_runner = "@duckscript"

View File

@ -52,19 +52,6 @@ dart pub global activate protoc_plugin
script_runner = "@shell" script_runner = "@shell"
[tasks.check_protoc_cmd]
script = [
"""
ret = which protoc
if is_empty ${ret}
echo Please make sure <protoc_installation_folder>/bin/ is in PATH env var
echo See BUILD_ON_{LINUX|WINDOWS}.md for how to get protoc
exit -1
end
""",
]
script_runner = "@duckscript"
[tasks.gen_pb_file] [tasks.gen_pb_file]
script = [ script = [
""" """