Skip to content

Commit c2f70f2

Browse files
committed
fix: revise README.md and add actual_data test
1 parent 6f39d2b commit c2f70f2

File tree

7 files changed

+476
-53
lines changed

7 files changed

+476
-53
lines changed

README.md

-22
Original file line numberDiff line numberDiff line change
@@ -314,28 +314,6 @@ class $AssetsImagesGen {
314314
}
315315
```
316316

317-
#### Support generate at **build.yaml**
318-
Support generates dart files based on the key **`targets.$default.builders`** and **`flutter_gen.options`**
319-
of [`build.yaml`](https://github.com/dart-lang/build/blob/master/build_config/README.md).
320-
321-
```yaml
322-
# build.yaml
323-
# ...
324-
325-
targets:
326-
$default:
327-
builders:
328-
flutter_gen:
329-
options:
330-
output: lib/build_gen/ # Optional (default: lib/gen/)
331-
line_length: 120 # Optional (default: 80)
332-
```
333-
##### Prority of configure (High -> Low)
334-
```
335-
build.yaml -> pubspec.yaml -> default_config
336-
```
337-
338-
339317
#### Including additional metadata
340318

341319
At build time, additional metadata may be included in the generated class, by using the

packages/core/test/assets_gen_test.dart

+9
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ void main() {
213213
final names = got.map((e) => e.name);
214214
expect(names.sorted(), tests.values.sorted());
215215
});
216+
217+
test('Assets on pubspec_assets.yaml and override with build_assets.yaml ', () async {
218+
const pubspec = 'test_resources/pubspec_assets.yaml';
219+
const build = 'test_resources/build_assets.yaml';
220+
const fact = 'test_resources/actual_data/build_assets.gen.dart';
221+
const generated = 'test_resources/lib/build_gen/assets.gen.dart';
222+
223+
await expectedAssetsGen(pubspec, generated, fact, build: build);
224+
});
216225
});
217226

218227
group('Test generatePackageNameForConfig', () {

packages/core/test/flutter_gen_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ void main() {
180180
expect(File('test_resources/lib/gen/$colors').existsSync(), false);
181181
});
182182

183-
test('with build_output.yaml', () async {
183+
test('With build_output.yaml', () async {
184184
const pubspec = 'test_resources/pubspec_normal.yaml';
185185
const build = 'test_resources/build_output.yaml';
186-
const assets = 'pubspec_assets.gen.dart';
187-
const colors = 'pubspec_colors.gen.dart';
188-
const fonts = 'pubspec_fonts.gen.dart';
186+
const assets = 'build_assets.gen.dart';
187+
const colors = 'build_colors.gen.dart';
188+
const fonts = 'build_fonts.gen.dart';
189189

190190
await FlutterGenerator(
191191
File(pubspec),

packages/core/test/gen_test_helper.dart

+15-8
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ Future<void> clearTestResults() async {}
1414
Future<List<String>> runAssetsGen(
1515
String pubspec,
1616
String generated,
17-
String fact,
18-
) async {
17+
String fact, {
18+
String? build,
19+
}) async {
20+
final pubspecFile = File(pubspec);
21+
22+
File? buildFile;
23+
if (build != null) buildFile = File(build);
24+
1925
await FlutterGenerator(
20-
File(pubspec),
26+
pubspecFile,
27+
buildFile: buildFile,
2128
assetsName: p.basename(generated),
2229
).build();
2330

24-
final pubspecFile = File(pubspec);
25-
final config = loadPubspecConfig(pubspecFile);
31+
final config = loadPubspecConfig(pubspecFile, buildFile: buildFile);
2632
final formatter = DartFormatter(
2733
pageWidth: config.pubspec.flutterGen.lineLength,
2834
lineEnding: '\n',
@@ -42,9 +48,10 @@ Future<List<String>> runAssetsGen(
4248
Future<void> expectedAssetsGen(
4349
String pubspec,
4450
String generated,
45-
String fact,
46-
) async {
47-
final results = await runAssetsGen(pubspec, generated, fact);
51+
String fact, {
52+
String? build,
53+
}) async {
54+
final results = await runAssetsGen(pubspec, generated, fact, build: build);
4855
final actual = results.first, expected = results.last;
4956
expect(
5057
File(generated).readAsStringSync(),

0 commit comments

Comments
 (0)