update analytics in generate api docs site to use new UA4 (#136497)

Change the analytics instance that the generated api.flutter.dev and master-api.flutter.dev use.
This commit is contained in:
Christopher Fujino
2023-10-16 12:47:48 -07:00
committed by GitHub
parent bb7f0b2326
commit 4dcd1598b7
6 changed files with 287 additions and 35 deletions

View File

@@ -10,6 +10,7 @@ import 'package:test/test.dart';
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
import '../create_api_docs.dart' as apidocs;
import '../dartdoc_checker.dart';
void main() {
group('FlutterInformation', () {
@@ -223,6 +224,235 @@ void main() {
expect(info['engineRealm'], equals('realm'));
});
});
group('DartDocGenerator', () {
late apidocs.DartdocGenerator generator;
late MemoryFileSystem fs;
late FakeProcessManager processManager;
late Directory publishRoot;
setUp(() {
fs = MemoryFileSystem.test();
publishRoot = fs.directory('/path/to/publish');
processManager = FakeProcessManager.empty();
generator = apidocs.DartdocGenerator(
packageRoot: fs.directory('/path/to/package'),
publishRoot: publishRoot,
docsRoot: fs.directory('/path/to/docs'),
filesystem: fs,
processManager: processManager,
);
final Directory repoRoot = fs.directory('/flutter');
repoRoot.childDirectory('packages').createSync(recursive: true);
apidocs.FlutterInformation.instance = apidocs.FlutterInformation(
filesystem: fs,
processManager: processManager,
platform: FakePlatform(environment: <String, String>{
'FLUTTER_ROOT': repoRoot.path,
}),
);
});
test('.generateDartDoc() invokes dartdoc with the correct command line arguments', () async {
processManager.addCommands(<FakeCommand>[
const FakeCommand(command: <String>['/flutter/bin/flutter', 'pub', 'get']),
const FakeCommand(
command: <String>['/flutter/bin/flutter', '--version', '--machine'],
stdout: testVersionInfo,
),
const FakeCommand(
command: <Pattern>['git', 'status', '-b', '--porcelain'],
stdout: '## $branchName',
),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
),
const FakeCommand(
command: <String>['/flutter/bin/flutter', 'pub', 'global', 'list'],
),
FakeCommand(
command: <Pattern>[
'/flutter/bin/flutter',
'pub',
'global',
'run',
'--enable-asserts',
'dartdoc',
'--output',
'/path/to/publish/flutter',
'--allow-tools',
'--json',
'--validate-links',
'--link-to-source-excludes',
'/flutter/bin/cache',
'--link-to-source-root',
'/flutter',
'--link-to-source-uri-template',
'https://github.com/flutter/flutter/blob/master/%f%#L%l%',
'--inject-html',
'--use-base-href',
'--header',
'/path/to/docs/styles.html',
'--header',
'/path/to/docs/analytics-header.html',
'--header',
'/path/to/docs/survey.html',
'--header',
'/path/to/docs/snippets.html',
'--header',
'/path/to/docs/opensearch.html',
'--footer',
'/path/to/docs/analytics-footer.html',
'--footer-text',
'/path/to/package/footer.html',
'--allow-warnings-in-packages',
// match package names
RegExp(r'^(\w+,)+(\w+)$'),
'--exclude-packages',
RegExp(r'^(\w+,)+(\w+)$'),
'--exclude',
// match dart package URIs
RegExp(r'^([\w\/:.]+,)+([\w\/:.]+)$'),
'--favicon',
'/path/to/docs/favicon.ico',
'--package-order',
'flutter,Dart,${apidocs.kPlatformIntegrationPackageName},flutter_test,flutter_driver',
'--auto-include-dependencies',
],
),
]);
// This will throw while sanity checking generated files, which is tested independently
await expectLater(
() => generator.generateDartdoc(),
throwsA(
isA<Exception>().having(
(Exception e) => e.toString(),
'message',
contains(RegExp(r'Missing .* which probably means the documentation failed to build correctly.')),
),
),
);
expect(processManager, hasNoRemainingExpectations);
});
test('sanity checks spot check generated files', () async {
processManager.addCommands(<FakeCommand>[
const FakeCommand(command: <String>['/flutter/bin/flutter', 'pub', 'get']),
const FakeCommand(
command: <String>['/flutter/bin/flutter', '--version', '--machine'],
stdout: testVersionInfo,
),
const FakeCommand(
command: <Pattern>['git', 'status', '-b', '--porcelain'],
stdout: '## $branchName',
),
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
),
const FakeCommand(
command: <String>['/flutter/bin/flutter', 'pub', 'global', 'list'],
),
FakeCommand(
command: <Pattern>[
'/flutter/bin/flutter',
'pub',
'global',
'run',
'--enable-asserts',
'dartdoc',
'--output',
'/path/to/publish/flutter',
'--allow-tools',
'--json',
'--validate-links',
'--link-to-source-excludes',
'/flutter/bin/cache',
'--link-to-source-root',
'/flutter',
'--link-to-source-uri-template',
'https://github.com/flutter/flutter/blob/master/%f%#L%l%',
'--inject-html',
'--use-base-href',
'--header',
'/path/to/docs/styles.html',
'--header',
'/path/to/docs/analytics-header.html',
'--header',
'/path/to/docs/survey.html',
'--header',
'/path/to/docs/snippets.html',
'--header',
'/path/to/docs/opensearch.html',
'--footer',
'/path/to/docs/analytics-footer.html',
'--footer-text',
'/path/to/package/footer.html',
'--allow-warnings-in-packages',
// match package names
RegExp(r'^(\w+,)+(\w+)$'),
'--exclude-packages',
RegExp(r'^(\w+,)+(\w+)$'),
'--exclude',
// match dart package URIs
RegExp(r'^([\w\/:.]+,)+([\w\/:.]+)$'),
'--favicon',
'/path/to/docs/favicon.ico',
'--package-order',
'flutter,Dart,${apidocs.kPlatformIntegrationPackageName},flutter_test,flutter_driver',
'--auto-include-dependencies',
],
onRun: () {
for (final File canary in generator.canaries) {
canary.createSync(recursive: true);
}
for (final String path in dartdocDirectiveCanaryFiles) {
publishRoot.childDirectory('flutter').childFile(path).createSync(recursive: true);
}
for (final String path in dartdocDirectiveCanaryLibraries) {
publishRoot.childDirectory('flutter').childDirectory(path).createSync(recursive: true);
}
publishRoot.childDirectory('flutter').childFile('index.html').createSync();
final Directory widgetsDir = publishRoot
.childDirectory('flutter')
.childDirectory('widgets')
..createSync(recursive: true);
widgetsDir.childFile('showGeneralDialog.html').writeAsStringSync('''
<pre id="longSnippet1">
<code class="language-dart">
import &#39;package:flutter&#47;material.dart&#39;;
</code>
</pre>
''',
);
expect(publishRoot.childDirectory('flutter').existsSync(), isTrue);
(widgetsDir
.childDirectory('ModalRoute')
..createSync(recursive: true))
.childFile('barrierColor.html')
.writeAsStringSync('''
<pre id="sample-code">
<code class="language-dart">
class FooClass {
Color get barrierColor => FooColor();
}
</code>
</pre>
''');
const String queryParams = 'split=1&run=true&sample_id=widgets.Listener.123&sample_channel=master&channel=master';
widgetsDir.childFile('Listener-class.html').writeAsStringSync('''
<iframe class="snippet-dartpad" src="https://dartpad.dev/embed-flutter.html?$queryParams">
</iframe>
''');
}
),
]);
await generator.generateDartdoc();
});
});
}
const String branchName = 'stable';