@@ -225,6 +225,157 @@ void main() {
225
225
});
226
226
});
227
227
228
+ group ('Configurator' , () {
229
+ late MemoryFileSystem fs;
230
+ late FakeProcessManager fakeProcessManager;
231
+ late Directory publishRoot;
232
+ late Directory packageRoot;
233
+ late Directory docsRoot;
234
+ late File searchTemplate;
235
+ late apidocs.Configurator configurator;
236
+ late FakePlatform fakePlatform;
237
+ late apidocs.FlutterInformation flutterInformation;
238
+
239
+ void setUpWithEnvironment (Map <String , String > environment) {
240
+ fakePlatform = FakePlatform (environment: environment);
241
+ flutterInformation = apidocs.FlutterInformation (
242
+ filesystem: fs,
243
+ processManager: fakeProcessManager,
244
+ platform: fakePlatform,
245
+ );
246
+ apidocs.FlutterInformation .instance = flutterInformation;
247
+ }
248
+
249
+ setUp (() {
250
+ fs = MemoryFileSystem .test ();
251
+ publishRoot = fs.directory ('/path/to/publish' );
252
+ packageRoot = fs.directory ('/path/to/package' );
253
+ docsRoot = fs.directory ('/path/to/docs' );
254
+ searchTemplate = docsRoot.childDirectory ('lib' ).childFile ('opensearch.xml' );
255
+ fs.directory ('/home/user/flutter/packages' ).createSync (recursive: true );
256
+ fakeProcessManager = FakeProcessManager .empty ();
257
+ setUpWithEnvironment (< String , String > {});
258
+ publishRoot.createSync (recursive: true );
259
+ packageRoot.createSync (recursive: true );
260
+ docsRoot.createSync (recursive: true );
261
+ final List <String > files = < String > [
262
+ 'README.md' ,
263
+ 'analysis_options.yaml' ,
264
+ 'dartdoc_options.yaml' ,
265
+ searchTemplate.path,
266
+ publishRoot.childFile ('opensearch.xml' ).path,
267
+ ];
268
+ for (final String file in files) {
269
+ docsRoot.childFile (file).createSync (recursive: true );
270
+ }
271
+ searchTemplate.writeAsStringSync ('{SITE_URL}' );
272
+ configurator = apidocs.Configurator (
273
+ docsRoot: docsRoot,
274
+ packageRoot: packageRoot,
275
+ publishRoot: publishRoot,
276
+ filesystem: fs,
277
+ processManager: fakeProcessManager,
278
+ platform: fakePlatform,
279
+ );
280
+ fakeProcessManager.addCommands (< FakeCommand > [
281
+ const FakeCommand (
282
+ command: < String > ['flutter' , '--version' , '--machine' ],
283
+ stdout: testVersionInfo,
284
+ ),
285
+ const FakeCommand (
286
+ command: < Pattern > ['git' , 'status' , '-b' , '--porcelain' ],
287
+ stdout: '## $branchName ' ,
288
+ ),
289
+ const FakeCommand (
290
+ command: < String > ['git' , 'rev-parse' , 'HEAD' ],
291
+ ),
292
+ const FakeCommand (
293
+ command: < String > ['/flutter/bin/flutter' , 'pub' , 'global' , 'list' ],
294
+ ),
295
+ FakeCommand (
296
+ command: < Pattern > [
297
+ '/flutter/bin/flutter' ,
298
+ 'pub' ,
299
+ 'global' ,
300
+ 'run' ,
301
+ '--enable-asserts' ,
302
+ 'dartdoc' ,
303
+ '--output' ,
304
+ '/path/to/publish/flutter' ,
305
+ '--allow-tools' ,
306
+ '--json' ,
307
+ '--validate-links' ,
308
+ '--link-to-source-excludes' ,
309
+ '/flutter/bin/cache' ,
310
+ '--link-to-source-root' ,
311
+ '/flutter' ,
312
+ '--link-to-source-uri-template' ,
313
+ 'https://github.com/flutter/flutter/blob/main/%f%#L%l%' ,
314
+ '--inject-html' ,
315
+ '--use-base-href' ,
316
+ '--header' ,
317
+ '/path/to/docs/styles.html' ,
318
+ '--header' ,
319
+ '/path/to/docs/analytics-header.html' ,
320
+ '--header' ,
321
+ '/path/to/docs/survey.html' ,
322
+ '--header' ,
323
+ '/path/to/docs/snippets.html' ,
324
+ '--header' ,
325
+ '/path/to/docs/opensearch.html' ,
326
+ '--footer' ,
327
+ '/path/to/docs/analytics-footer.html' ,
328
+ '--footer-text' ,
329
+ '/path/to/package/footer.html' ,
330
+ '--allow-warnings-in-packages' ,
331
+ // match package names
332
+ RegExp (r'^(\w+,)+(\w+)$' ),
333
+ '--exclude-packages' ,
334
+ RegExp (r'^(\w+,)+(\w+)$' ),
335
+ '--exclude' ,
336
+ // match dart package URIs
337
+ RegExp (r'^([\w\/:.]+,)+([\w\/:.]+)$' ),
338
+ '--favicon' ,
339
+ '/path/to/docs/favicon.ico' ,
340
+ '--package-order' ,
341
+ 'flutter,Dart,${apidocs .kPlatformIntegrationPackageName },flutter_test,flutter_driver' ,
342
+ '--auto-include-dependencies' ,
343
+ ],
344
+ ),
345
+ ]);
346
+ });
347
+
348
+ test ('.generateConfiguration generates pubspec.yaml' , () async {
349
+ configurator.generateConfiguration ();
350
+ expect (packageRoot.childFile ('pubspec.yaml' ).existsSync (), isTrue);
351
+ expect (packageRoot.childFile ('pubspec.yaml' ).readAsStringSync (), contains ('flutter_gpu:' ));
352
+ expect (packageRoot.childFile ('pubspec.yaml' ).readAsStringSync (), contains ('dependency_overrides:' ));
353
+ expect (packageRoot.childFile ('pubspec.yaml' ).readAsStringSync (), contains ('platform_integration:' ));
354
+ });
355
+
356
+ test ('.generateConfiguration generates fake lib' , () async {
357
+ configurator.generateConfiguration ();
358
+ expect (packageRoot.childDirectory ('lib' ).existsSync (), isTrue);
359
+ expect (packageRoot.childDirectory ('lib' ).childFile ('temp_doc.dart' ).existsSync (), isTrue);
360
+ expect (packageRoot.childDirectory ('lib' ).childFile ('temp_doc.dart' ).readAsStringSync (), contains ('library temp_doc;' ));
361
+ expect (packageRoot.childDirectory ('lib' ).childFile ('temp_doc.dart' ).readAsStringSync (), contains ("import 'package:flutter_gpu/gpu.dart';" ));
362
+ });
363
+
364
+ test ('.generateConfiguration generates page footer' , () async {
365
+ configurator.generateConfiguration ();
366
+ expect (packageRoot.childFile ('footer.html' ).existsSync (), isTrue);
367
+ expect (packageRoot.childFile ('footer.html' ).readAsStringSync (), contains ('<script src="footer.js">' ));
368
+ expect (publishRoot.childDirectory ('flutter' ).childFile ('footer.js' ).existsSync (), isTrue);
369
+ expect (publishRoot.childDirectory ('flutter' ).childFile ('footer.js' ).readAsStringSync (), contains (RegExp (r'Flutter 2.5.0 •.*• stable' )));
370
+ });
371
+
372
+ test ('.generateConfiguration generates search metadata' , () async {
373
+ configurator.generateConfiguration ();
374
+ expect (publishRoot.childFile ('opensearch.xml' ).existsSync (), isTrue);
375
+ expect (publishRoot.childFile ('opensearch.xml' ).readAsStringSync (), contains ('https://api.flutter.dev/' ));
376
+ });
377
+ });
378
+
228
379
group ('DartDocGenerator' , () {
229
380
late apidocs.DartdocGenerator generator;
230
381
late MemoryFileSystem fs;
0 commit comments