Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jxstxn1 committed Mar 7, 2024
1 parent 6a4a572 commit d8a5db4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
9 changes: 4 additions & 5 deletions lib/src/models/pubspec_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:pubspec/pubspec.dart';
import 'package:yaml/yaml.dart';

/// {@template pubspec_extensions}
/// Extensions on [PubSpec] to provide additional functionality.
Expand All @@ -15,11 +14,11 @@ extension PubspecExtensions on PubSpec {
String? issueTracker() => unParsedYaml?['issue_tracker'];

/// Optional. List of URLs where users can sponsor development of the package.
YamlList? funding() => unParsedYaml?['funding'];
List? funding() => unParsedYaml?['funding'];

/// Optional. Specify files to ignore when conducting a pre-publishing search
/// for potential leaks of secrets.
YamlList? falseSecrets() => unParsedYaml?['false_secrets'];
List? falseSecrets() => unParsedYaml?['false_secrets'];

/// Optional. Specify a list of screenshot files to display on pub.dev
List<Screenshot>? screenshots() {
Expand All @@ -35,10 +34,10 @@ extension PubspecExtensions on PubSpec {
}

/// Optional field to list the topics that this packages belongs to.
YamlList? topics() => unParsedYaml?['topics'];
List? topics() => unParsedYaml?['topics'];

/// Optional. List of ignored security advisories.
YamlList? ignoredAdvisories() => unParsedYaml?['ignored_advisories'];
List? ignoredAdvisories() => unParsedYaml?['ignored_advisories'];
}

/// {@template screenshot}
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
oauth2: ^2.0.2
path: ^1.8.3
pubspec: ^2.3.0
yaml: ^3.1.2

dev_dependencies:
build_runner: ^2.4.6
Expand Down
15 changes: 4 additions & 11 deletions test/pubspec_extensions_test.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import 'package:pub_api_client/pub_api_client.dart';
import 'package:pubspec/pubspec.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

void main() {
test('Should be able to parse repository field', () async {
final pubspec = await PubSpec.loadFile('test/example_pubspec.yaml');
expect(pubspec.repository(), 'https://foo.bar/repo');
});

test('Should be able to parse issue tracker field', () async {
final pubspec = await PubSpec.loadFile('test/example_pubspec.yaml');
expect(pubspec.issueTracker(), 'https://foo.bar/issues');
});

test('Should be able to parse funding field', () async {
final pubspec = await PubSpec.loadFile('test/example_pubspec.yaml');
final sponsors = pubspec.funding();
expect(sponsors, isA<YamlList>());
expect(sponsors, isA<List>());
expect(sponsors, hasLength(2));
expect(sponsors?[0], 'https://foo.bar/sponsor1');
expect(sponsors?[1], 'https://foo.bar/sponsor2');
});

test('Should be able to parse false secrets field', () async {
final pubspec = await PubSpec.loadFile('test/example_pubspec.yaml');
final falseSecrets = pubspec.falseSecrets();
expect(falseSecrets, isA<YamlList>());
expect(falseSecrets, isA<List>());
expect(falseSecrets, hasLength(2));
expect(falseSecrets?[0], '/lib/foo/bar.dart');
expect(falseSecrets?[1], '/lib/bar/foo.dart');
Expand All @@ -45,18 +40,16 @@ void main() {
});

test('Should be able to parse topics field', () async {
final pubspec = await PubSpec.loadFile('test/example_pubspec.yaml');
final topics = pubspec.topics();
expect(topics, isA<YamlList>());
expect(topics, isA<List>());
expect(topics, hasLength(2));
expect(topics?[0], 'bar');
expect(topics?[1], 'foo');
});

test('Should be able to parse ignoredAdvisories field', () async {
final pubspec = await PubSpec.loadFile('test/example_pubspec.yaml');
final ignoredAdvisories = pubspec.ignoredAdvisories();
expect(ignoredAdvisories, isA<YamlList>());
expect(ignoredAdvisories, isA<List>());
expect(ignoredAdvisories, hasLength(2));
expect(ignoredAdvisories?[0], 'foo-bar');
expect(ignoredAdvisories?[1], 'bar-foo');
Expand Down

0 comments on commit d8a5db4

Please sign in to comment.