Skip to content

[markdown] fix crash test #2067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkgs/markdown/test/crash_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ void main() async {
var lastStatus = DateTime(0);
void status(String Function() message) {
if (DateTime.now().difference(lastStatus) >
const Duration(seconds: 30)) {
const Duration(seconds: 5)) {
lastStatus = DateTime.now();
print(message());
}
}

final c = http.RetryClient(http.Client());
Future<dynamic> getJson(String url) async {
Future<Map<String, dynamic>?> getJson(String url) async {
final u = Uri.tryParse(url);
if (u == null) {
return null;
}
try {
final data = await c.read(u);
try {
return jsonDecode(data);
return jsonDecode(data) as Map<String, dynamic>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that pub.dev/api returns some other type of JSON, but in practice, they are always maps!

Another approach would be to return Object? and force folks to cast. 🤷

} on FormatException {
return null;
}
Expand All @@ -70,7 +70,7 @@ void main() async {
}

final packages =
((await getJson('https://pub.dev/api/package-names'))['packages']
((await getJson('https://pub.dev/api/package-names'))!['packages']
as List)
.cast<String>();
//.take(3).toList(); // useful when testing
Expand All @@ -84,7 +84,7 @@ void main() async {
final response = await getJson(
'https://pub.dev/api/packages/$package',
);
final entry = response['latest'] as Map?;
final entry = response?['latest'] as Map?;
if (entry != null) {
packageVersions.add(PackageVersion(
package: package,
Expand Down