Skip to content

Commit

Permalink
✅ Fix tests (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Oct 1, 2024
1 parent aadf5f9 commit c4ed388
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 151 deletions.
10 changes: 8 additions & 2 deletions packages/command/bin/flutter_gen_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ void main(List<String> args) {
}

final pubspecPath = safeCast<String>(results['config']);
final pubspecFile = File(pubspecPath!).absolute;
if (pubspecPath == null || pubspecPath.trim().isEmpty) {
throw ArgumentError('Invalid value $pubspecPath', 'config');
}
final pubspecFile = File(pubspecPath).absolute;

final buildPath = safeCast<String>(results['build']);
final buildFile = File(buildPath!).absolute;
if (buildPath == null || buildPath.trim().isEmpty) {
throw ArgumentError('Invalid value $buildPath', 'build');
}
final buildFile = File(buildPath).absolute;

FlutterGenerator(pubspecFile, buildFile: buildFile).build();
}
11 changes: 6 additions & 5 deletions packages/core/lib/settings/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:path/path.dart';
import 'package:yaml/yaml.dart';

class Config {
Config._({required this.pubspec, required this.pubspecFile});
const Config._({required this.pubspec, required this.pubspecFile});

final Pubspec pubspec;
final File pubspecFile;
Expand All @@ -19,9 +19,6 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) {
final pubspecLocaleHint = normalize(
join(basename(pubspecFile.parent.path), basename(pubspecFile.path)),
);
final buildLocaleHint = buildFile != null && buildFile.existsSync()
? join(basename(buildFile.parent.path), basename(buildFile.path))
: '';

stdout.writeln(
'$flutterGenVersion Loading ...',
Expand All @@ -40,11 +37,15 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) {
if (buildFile != null && buildFile.existsSync()) {
final buildContent = buildFile.readAsStringSync();
final rawMap = loadYaml(buildContent) as Map?;
final optionBuildMap = rawMap?['targets']?[r'$default']?['builders']?['flutter_gen']?['options'];
final optionBuildMap = rawMap?['targets']?[r'$default']?['builders']
?['flutter_gen']?['options'];

if (optionBuildMap != null) {
final buildMap = {'flutter_gen': optionBuildMap};
mergedMap = mergeMap([mergedMap, buildMap]);
final buildLocaleHint = normalize(
join(basename(buildFile.parent.path), basename(buildFile.path)),
);
stdout.writeln(
'Reading FlutterGen options from $buildLocaleHint',
);
Expand Down
19 changes: 11 additions & 8 deletions packages/core/test/assets_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,17 @@ void main() {
expect(names.sorted(), tests.values.sorted());
});

test('Assets on pubspec_assets.yaml and override with build_assets.yaml ', () async {
const pubspec = 'test_resources/pubspec_assets.yaml';
const build = 'test_resources/build_assets.yaml';
const fact = 'test_resources/actual_data/build_assets.gen.dart';
const generated = 'test_resources/lib/build_gen/assets.gen.dart';

await expectedAssetsGen(pubspec, generated, fact, build: build);
});
test(
'Assets on pubspec_assets.yaml and override with build_assets.yaml ',
() async {
const pubspec = 'test_resources/pubspec_assets.yaml';
const build = 'test_resources/build_assets.yaml';
const fact = 'test_resources/actual_data/build_assets.gen.dart';
const generated = 'test_resources/lib/build_gen/assets.gen.dart';

await expectedAssetsGen(pubspec, generated, fact, build: build);
},
);
});

group('Test generatePackageNameForConfig', () {
Expand Down
Loading

0 comments on commit c4ed388

Please sign in to comment.