-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2f99a7
commit 4b37cd2
Showing
3 changed files
with
270 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import 'package:changelog_bubbler/src/bubbler_shell.dart'; | ||
import 'package:changelog_bubbler/src/dependency_parser.dart'; | ||
import 'package:changelog_bubbler/src/global_dependencies.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:test_descriptor/test_descriptor.dart' as d; | ||
|
||
import 'test_helpers.dart'; | ||
|
||
void main() { | ||
setUp(() async { | ||
await registerMockGlobalDependencies(); | ||
await _prepareTestApp(); | ||
}); | ||
test( | ||
'includes transitive main dependencies ' | ||
'when includeTransitive', () async { | ||
final parser = DependencyParser(repoPath: d.sandbox); | ||
|
||
parser.parseDependencies( | ||
includeDev: true, | ||
includeTransitive: true, | ||
); | ||
|
||
expect(parser.dependencies.keys, contains('async')); | ||
}); | ||
|
||
test( | ||
'includes direct dev dependencies ' | ||
'when includeDev', () async { | ||
final parser = DependencyParser(repoPath: d.sandbox); | ||
|
||
parser.parseDependencies( | ||
includeDev: true, | ||
includeTransitive: true, | ||
); | ||
|
||
expect(parser.dependencies.keys, contains('mocktail')); | ||
}); | ||
test( | ||
'includes transitive dev dependencies ' | ||
'when includeDev and includeTransitive', () async { | ||
final parser = DependencyParser(repoPath: d.sandbox); | ||
|
||
parser.parseDependencies( | ||
includeDev: true, | ||
includeTransitive: true, | ||
); | ||
|
||
expect(parser.dependencies.keys, contains('matcher')); | ||
}); | ||
test( | ||
'excludes direct dev dependencies ' | ||
'when not includeDev', () async { | ||
final parser = DependencyParser(repoPath: d.sandbox); | ||
|
||
parser.parseDependencies( | ||
includeDev: false, | ||
includeTransitive: true, | ||
); | ||
|
||
expect( | ||
parser.dependencies.keys.contains('mocktail'), | ||
isFalse, | ||
); | ||
}); | ||
test( | ||
'excludes transitive dev dependencies ' | ||
'when includeDev and not includeTransitive', () async { | ||
final parser = DependencyParser(repoPath: d.sandbox); | ||
|
||
parser.parseDependencies( | ||
includeDev: true, | ||
includeTransitive: false, | ||
); | ||
|
||
expect( | ||
parser.dependencies.keys.contains('matcher'), | ||
isFalse, | ||
); | ||
}); | ||
} | ||
|
||
Future<void> _prepareTestApp() async { | ||
final pubYaml = d.file('pubspec.yaml'); | ||
await pubYaml.create(); | ||
pubYaml.io.writeAsStringSync(MockData.mockPubYamlContents); | ||
|
||
final pubLock = d.file('pubspec.lock'); | ||
await pubLock.create(); | ||
pubLock.io.writeAsStringSync(MockData.mockPubLockContents); | ||
|
||
final shell = getDep<BubblerShell>(); | ||
final mockResult = ProcessResultExt.mock(outText: MockData.mockPubDepsOutput); | ||
when( | ||
() => shell.stubbedRunSync('dart pub deps --no-dev --style compact'), | ||
).thenReturn(mockResult); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,90 @@ | ||
// test added packages | ||
// test removed packages | ||
|
||
import 'package:changelog_bubbler/src/bubbler_shell.dart'; | ||
import 'package:changelog_bubbler/src/dependency_parser.dart'; | ||
import 'package:changelog_bubbler/src/diff_builder.dart'; | ||
import 'package:changelog_bubbler/src/global_dependencies.dart'; | ||
import 'package:changelog_bubbler/src/package_wrapper.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:pub_semver/pub_semver.dart'; | ||
import 'package:pubspec_lock_parse/pubspec_lock_parse.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:test_descriptor/test_descriptor.dart' as d; | ||
|
||
import 'test_helpers.dart'; | ||
|
||
void main() { | ||
test('empty test', () { | ||
expect(2 + 2, 4); | ||
setUp(() async { | ||
await registerMockGlobalDependencies(); | ||
await _prepareTestApp(); | ||
}); | ||
test('creates new section for each host', () async { | ||
final previousParser = DependencyParser(repoPath: d.sandbox) | ||
..dependencies = _previousDependencyMap; | ||
final currentParser = DependencyParser(repoPath: d.sandbox) | ||
..dependencies = _currentDependencyMap; | ||
|
||
final diffBuilder = DiffBuilder( | ||
previous: previousParser, | ||
current: currentParser, | ||
changelogName: 'changelogName', | ||
); | ||
expect(await diffBuilder.buildDiff(), contains('async')); | ||
}); | ||
} | ||
|
||
Future<void> _prepareTestApp() async { | ||
final pubYaml = d.file('pubspec.yaml'); | ||
await pubYaml.create(); | ||
pubYaml.io.writeAsStringSync(MockData.mockPubYamlContents); | ||
|
||
final pubLock = d.file('pubspec.lock'); | ||
await pubLock.create(); | ||
pubLock.io.writeAsStringSync(MockData.mockPubLockContents); | ||
|
||
final shell = getDep<BubblerShell>(); | ||
final mockResult = ProcessResultExt.mock(outText: MockData.mockPubDepsOutput); | ||
when( | ||
() => shell.stubbedRunSync('dart pub deps --no-dev --style compact'), | ||
).thenReturn(mockResult); | ||
} | ||
|
||
final _previousDependencyMap = { | ||
'hosted': PackageWrapper( | ||
'hosted_dep', | ||
Package( | ||
dependency: 'direct main', | ||
description: HostedPackageDescription(name: 'name', url: 'hosted_url'), | ||
source: PackageSource.hosted, | ||
version: Version.parse('1.0.0'), | ||
), | ||
), | ||
'git_dep': PackageWrapper( | ||
'git_dep', | ||
Package( | ||
dependency: 'direct main', | ||
description: GitPackageDescription( | ||
path: 'path', ref: 'ref', resolvedRef: 'resolvedRef', url: 'git_url'), | ||
source: PackageSource.git, | ||
version: Version.parse('1.0.0'), | ||
), | ||
), | ||
}; | ||
final _currentDependencyMap = { | ||
'hosted_dep': PackageWrapper( | ||
'hosted_dep', | ||
Package( | ||
dependency: 'direct main', | ||
description: HostedPackageDescription(name: 'name', url: 'hosted_url'), | ||
source: PackageSource.hosted, | ||
version: Version.parse('2.0.0'), | ||
), | ||
), | ||
'pub_dev_dep': PackageWrapper( | ||
'pub_dev_dep', | ||
Package( | ||
dependency: 'direct dev', | ||
description: HostedPackageDescription(name: 'name', url: 'pub_dev_url'), | ||
source: PackageSource.hosted, | ||
version: Version.parse('2.0.0'), | ||
), | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters