Skip to content

Commit 10336d2

Browse files
committed
feat: add dartTest (#3)
1 parent 4db0c6b commit 10336d2

File tree

10 files changed

+318
-26
lines changed

10 files changed

+318
-26
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 0.1.0 (2022-03-09)
2+
3+
### Features
4+
5+
- add dartTest ([#3](https://github.com/VeryGoodOpenSource/very_good_test_runner/issues/3)) ([6686fdd](https://github.com/VeryGoodOpenSource/very_good_test_runner/commit/6686fdd6871fd3b401259ac3b1453112614a81a7))
6+
- add flutterTest ([#2](https://github.com/VeryGoodOpenSource/very_good_test_runner/issues/2)) ([4db0c6b](https://github.com/VeryGoodOpenSource/very_good_test_runner/commit/4db0c6b0da2d99acad0582a33b8e5885bdc6bf36))
7+
- export TestEvents ([#1](https://github.com/VeryGoodOpenSource/very_good_test_runner/issues/1)) ([1de845a](https://github.com/VeryGoodOpenSource/very_good_test_runner/commit/1de845a0f6ce3fcbdfc77d10f76fe38f4c77a858))
8+
- generate package via very_good_cli 🦄 ([3001cef](https://github.com/VeryGoodOpenSource/very_good_test_runner/commit/3001cef12ee5fb5c52a1652ff24209037a225ece))

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
- Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faqs

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing to Very Good Test Runner
2+
3+
First off, thanks for taking the time to contribute! 🎉👍
4+
5+
This project is opinionated and follows patterns and practices used by the team at [Very Good Ventures][very_good_ventures_link]. **At this time, we welcome bug tickets but will not be accepting feature requests because the roadmap and scope of this project is still being defined.**
6+
7+
## Creating a Bug Report
8+
9+
We highly recommend [creating an issue][bug_report_link] if you have found a bug rather than immediately opening a pull request. This lets us reach an agreement on a fix before you put significant effort into a pull request. Please use the built-in [Bug Report][bug_report_link] template and provide as much information as possible including detailed reproduction steps. Once one of the package maintainers has reviewed the issue and an agreement is reached regarding the fix, a pull request can be created.
10+
11+
## Creating a Pull Request
12+
13+
Before creating a pull request please:
14+
15+
1. Fork the repository and create your branch from `main`.
16+
1. Install all dependencies (`flutter packages get` or `pub get`).
17+
1. Squash your commits and ensure you have a meaningful, [semantic][conventional_commits_link] commit message.
18+
1. Add tests! Pull Requests without 100% test coverage will not be approved.
19+
1. Ensure the existing test suite passes locally.
20+
1. Format your code (`dart format .`).
21+
1. Analyze your code (`dart analyze --fatal-infos --fatal-warnings .`).
22+
1. Create the Pull Request.
23+
1. Verify that all status checks are passing.
24+
25+
While the prerequisites above must be satisfied prior to having your
26+
pull request reviewed, the reviewer(s) may ask you to complete additional
27+
work, tests, or other changes before your pull request can be ultimately
28+
accepted.
29+
30+
[conventional_commits_link]: https://www.conventionalcommits.org/en/v1.0.0
31+
[bug_report_link]: https://github.com/VeryGoodOpenSource/very_good_test_runner/issues/new?assignees=&labels=bug&template=bug_report.md&title=fix%3A+
32+
[very_good_ventures_link]: https://verygood.ventures

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Very Good Ventures
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ A test runner for Flutter and Dart created by Very Good Ventures.
1919
import 'package:very_good_test_runner/very_good_test_runner.dart';
2020
2121
void main() {
22+
// Run `dart test` in `path/to/project`.
23+
dartTest(workingDirectory: 'path/to/project').listen((TestEvent event) {
24+
// React to `TestEvent` instances.
25+
print(event);
26+
});
27+
28+
// Run `flutter test` in `path/to/project`.
2229
flutterTest(workingDirectory: 'path/to/project').listen((TestEvent event) {
2330
// React to `TestEvent` instances.
24-
// See https://github.com/dart-lang/test/blob/master/pkgs/test/doc/json_reporter.md#json-reporter-protocol
2531
print(event);
2632
});
2733
}
File renamed without changes.

lib/src/flutter_test_runner.dart renamed to lib/src/very_good_test_runner.dart

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ typedef StartProcess = Future<Process> Function(
1515
ProcessStartMode mode,
1616
});
1717

18+
/// Runs `dart test` and returns a stream of [TestEvent]
19+
/// reported by the process.
20+
///
21+
/// ```dart
22+
/// void main() {
23+
/// // React to `TestEvent` instances.
24+
/// dartTest().listen(print);
25+
/// }
26+
/// ```
27+
Stream<TestEvent> dartTest({
28+
List<String>? arguments,
29+
String? workingDirectory,
30+
Map<String, String>? environment,
31+
bool runInShell = false,
32+
StartProcess startProcess = Process.start,
33+
}) {
34+
return _runTestProcess(
35+
() => startProcess(
36+
'dart',
37+
['test', ...?arguments, '--reporter=json'],
38+
environment: environment,
39+
workingDirectory: workingDirectory,
40+
runInShell: runInShell,
41+
),
42+
);
43+
}
44+
1845
/// Runs `flutter test` and returns a stream of [TestEvent]
1946
/// reported by the process.
2047
///
@@ -31,19 +58,27 @@ Stream<TestEvent> flutterTest({
3158
bool runInShell = false,
3259
StartProcess startProcess = Process.start,
3360
}) {
61+
return _runTestProcess(
62+
() => startProcess(
63+
'flutter',
64+
['test', ...?arguments, '--reporter=json'],
65+
environment: environment,
66+
workingDirectory: workingDirectory,
67+
runInShell: runInShell,
68+
),
69+
);
70+
}
71+
72+
Stream<TestEvent> _runTestProcess(
73+
Future<Process> Function() processRunner,
74+
) {
3475
final controller = StreamController<TestEvent>();
3576
late StreamSubscription testEventSubscription;
3677
late StreamSubscription errorSubscription;
3778
late Future<Process> processFuture;
3879

3980
Future<void> _onListen() async {
40-
processFuture = startProcess(
41-
'flutter',
42-
['test', ...?arguments, '--reporter=json'],
43-
environment: environment,
44-
workingDirectory: workingDirectory,
45-
runInShell: runInShell,
46-
);
81+
processFuture = processRunner();
4782
final process = await processFuture;
4883
final errors = process.stderr.map((e) => utf8.decode(e).trim());
4984
final testEvents = process.stdout.mapToTestEvents();
@@ -72,20 +107,24 @@ Stream<TestEvent> flutterTest({
72107
extension on Stream<List<int>> {
73108
Stream<TestEvent> mapToTestEvents() {
74109
return map(utf8.decode)
75-
.expand<String>((msg) sync* {
76-
for (final value in msg.split('\n')) {
77-
final trimmedValue = value.trim();
78-
if (trimmedValue.isNotEmpty) yield trimmedValue;
79-
}
80-
})
81-
.expand<Object?>((j) {
82-
try {
83-
return [json.decode(j)];
84-
} on FormatException {
85-
return [];
86-
}
87-
})
88-
.cast<Map<Object?, Object?>>()
89-
.map((json) => TestEvent.fromJson(Map<String, dynamic>.from(json)));
110+
.expand<String>(_splitLines)
111+
.map<Map<String, Object?>>(_tryDecode)
112+
.where((value) => value.isNotEmpty)
113+
.map(TestEvent.fromJson);
114+
}
115+
116+
Iterable<String> _splitLines(String content) sync* {
117+
for (final line in content.split('\n')) {
118+
yield line.trim();
119+
}
120+
}
121+
122+
Map<String, Object?> _tryDecode(String value) {
123+
try {
124+
if (value.isEmpty) return const {};
125+
return json.decode(value) as Map<String, Object?>;
126+
} on FormatException {
127+
return const {};
128+
}
90129
}
91130
}

lib/very_good_test_runner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// A test runner for Flutter and Dart created by Very Good Ventures.
22
library very_good_test_runner;
33

4-
export 'src/flutter_test_runner.dart' show flutterTest;
54
export 'src/models/models.dart';
5+
export 'src/very_good_test_runner.dart' show dartTest, flutterTest;

pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: very_good_test_runner
22
description: A test runner for Flutter and Dart created by Very Good Ventures
3-
version: 1.0.0+1
4-
publish_to: none
3+
version: 0.1.0
54

65
environment:
76
sdk: ">=2.16.0 <3.0.0"

0 commit comments

Comments
 (0)