Skip to content

Commit b9f545a

Browse files
authored
Fix up unit tests & run them in CI (#336)
- remove mockito generated mocks, use nock instead - lots of test fixes - add testing matrix - added a makefile - added ocktokit scenarios - actually run tests in CI
1 parent 91454c5 commit b9f545a

File tree

16 files changed

+1870
-588
lines changed

16 files changed

+1870
-588
lines changed

.github/workflows/dart.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
container:
11-
image: dart:2.14
12-
9+
image: dart:2.17
1310
steps:
1411
- uses: actions/checkout@v1
1512
- name: Install dependencies
1613
run: dart pub get
1714
- name: Dart Analyzer
1815
run: dart analyze
1916
- name: Check Dart Format
20-
run: dart format --set-exit-if-changed -o none lib test tool example && echo Dart Format 👍 || echo Files needed Dart formatting 😢
17+
run: dart format --set-exit-if-changed -o none lib test tool example integration_test && echo Dart Format 👍 || echo Files needed Dart formatting 😢
2118
- name: Check if Publishable
2219
run: dart pub publish --dry-run

.github/workflows/release_unreleased_prs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
release:
1313
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
1414
runs-on: ubuntu-latest
15-
container: dart:2.14.4
15+
container: dart:2.17.7
1616
permissions:
1717
contents: write
1818

.github/workflows/tests.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ on:
66
branches: [ master ]
77
jobs:
88
test:
9-
runs-on: ubuntu-latest
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest]
13+
sdk: [2.14.4, 2.17.7, stable] # Test with at least the declared minimum Dart version
1014
steps:
11-
- uses: actions/checkout@v2
12-
- uses: dart-lang/setup-dart@v1
13-
- name: Install dependencies
14-
run: dart pub get
15-
# - name: Unit tests
16-
# run: dart test test
17-
# - name: Integration tests
18-
# run: dart test integration_test
15+
- uses: actions/checkout@v2
16+
- uses: dart-lang/[email protected]
17+
with:
18+
sdk: ${{ matrix.sdk }}
19+
- name: Install dependencies
20+
run: dart pub get
21+
- name: Unit tests
22+
run: dart test
23+
# - name: Integration tests
24+
# run: dart test integration_test

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.DEFAULT_GOAL := help
2+
SHELL=/bin/bash -o pipefail
3+
4+
# Cite: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
5+
.PHONY: help
6+
help: ## Display this help page
7+
@grep -E '^[a-zA-Z0-9/_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
8+
9+
.PHONY: fixtures
10+
fixtures: ## Run octokit-fixtures-server for scenario tests
11+
@npx octokit-fixtures-server &
12+
13+
.PHONY: stop
14+
stop: ## Stop the fixtures server
15+
@killall node
16+
17+
.PHONY: test
18+
test: fixtures ## Run tests
19+
@dart test -P all
20+
make stop

dart_test.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tags:
2+
scenarios:
3+
skip: |
4+
Not run by default when running dart test. To run:
5+
npx octokit-fixtures-server
6+
dart test -P scenarios
7+
or run all tests with:
8+
make test
9+
10+
presets:
11+
scenarios:
12+
include_tags: scenarios
13+
run_skipped: true
14+
all:
15+
run_skipped: true

lib/src/common/model/misc.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ class RateLimit {
4444
///
4545
/// API docs: https://developer.github.com/v3/rate_limit/
4646
factory RateLimit.fromRateLimitResponse(Map<String, dynamic> response) {
47-
final rateJson = response['rate'] as Map<String, dynamic>;
48-
final limit = rateJson['limit'] as int?;
49-
final remaining = rateJson['remaining'] as int?;
50-
final resets = DateTime.fromMillisecondsSinceEpoch(rateJson['reset']!);
47+
final rateJson = response['rate'] == null
48+
? null
49+
: response['rate'] as Map<String, dynamic>;
50+
final limit = rateJson?['limit'] as int?;
51+
final remaining = rateJson?['remaining'] as int?;
52+
final resets = rateJson?['reset'] == null
53+
? null
54+
: DateTime.fromMillisecondsSinceEpoch(rateJson?['reset']);
5155
return RateLimit(limit, remaining, resets);
5256
}
5357

lib/src/common/model/repos_releases.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class CreateRelease {
175175

176176
String? discussionCategoryName;
177177

178+
@JsonKey(defaultValue: false)
178179
bool generateReleaseNotes = false;
179180

180181
CreateRelease(this.tagName);

lib/src/common/model/repos_releases.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ dev_dependencies:
2121
json_serializable: ^6.0.0
2222
lints: ^1.0.0
2323
mockito: ^5.0.0
24-
pub_semver:
24+
nock: ^1.0.0
25+
pub_semver: ^2.0.0
2526
test: ^1.16.0
2627
yaml: ^3.0.0
2728
yaml_edit:

0 commit comments

Comments
 (0)