Skip to content

Commit

Permalink
Merge pull request #78 from olexale/gen_code_formatting
Browse files Browse the repository at this point in the history
Format generated files
  • Loading branch information
olexale authored Jun 1, 2024
2 parents ad5ecf6 + f4e43dc commit 4c28a34
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 31 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: 🐦 Setup Flutter SDK
uses: flutter-actions/setup-flutter@v1
uses: flutter-actions/setup-flutter@v3
with:
version: '3.19.4'
channel: stable
version: '3.22.1'

- name: 🛠 Install dependencies
run: flutter pub get
Expand All @@ -37,9 +38,17 @@ jobs:

- name: 🎯 Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v1

- name: 🥇 Update coverage badge
if: github.event_name != 'pull_request'
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.github_token }}

- name: 📈 Check pana
run: |
flutter pub global activate pana
PANA=$(pana . --no-warning); PANA_SCORE=$(echo $PANA | sed -n "s/.*Points: \([0-9]*\)\/\([0-9]*\)./\1\/\2/p")
echo "score: $PANA_SCORE"
IFS='/'; read -a SCORE_ARR <<< "$PANA_SCORE"; SCORE=SCORE_ARR[0]; TOTAL=SCORE_ARR[1]
if (( $SCORE < $TOTAL )); then echo "minimum score not met!"; exit 1; fi
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.7.4] - Code formatting

* Generated code is now properly formatted

## [1.7.3] - Integration test improvements

* Integration test imports will not be added if `integration_test` package is not added to `dev_dependencies`
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Counter

Run
```
flutter packages pub run build_runner watch --delete-conflicting-outputs
dart run run build_runner watch --delete-conflicting-outputs
```

The output Dart file would be:
Expand Down
3 changes: 1 addition & 2 deletions example/integration_test/sample_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation

import patrol

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PatrolPlugin.register(with: registry.registrar(forPlugin: "PatrolPlugin"))
}
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ dependencies:
dev_dependencies:
bdd_widget_test:
path: ../
build_runner: ^2.4.6
build_runner: ^2.4.10
integration_test:
sdk: flutter
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
patrol: ^2.3.0
patrol: ^3.7.2
2 changes: 1 addition & 1 deletion example/test/patrol.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Feature: Counter
Background:
Given the patrol app is running

@scenarioParams: nativeAutomation: true
@scenarioParams: semanticsEnabled: false
Scenario: Initial counter value is 0
Then I see {'0'} label
15 changes: 9 additions & 6 deletions example/test/patrol_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions example/test/sample_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion example/test/songs_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions lib/bdd_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:bdd_widget_test/src/feature_file.dart';
import 'package:bdd_widget_test/src/generator_options.dart';
import 'package:bdd_widget_test/src/hook_file.dart';
import 'package:bdd_widget_test/src/step_file.dart';
import 'package:bdd_widget_test/src/util/dart_formatter.dart';
import 'package:bdd_widget_test/src/util/fs.dart';
import 'package:build/build.dart';
import 'package:path/path.dart' as p;
Expand Down Expand Up @@ -41,12 +42,15 @@ class FeatureBuilder implements Builder {
);

final featureDart = inputId.changeExtension('_test.dart');
await buildStep.writeAsString(featureDart, feature.dartContent);
await buildStep.writeAsString(
featureDart,
formatDartCode(feature.dartContent),
);

final steps = feature
.getStepFiles()
.whereType<NewStepFile>()
.map((e) => _createFileRecursively(e.filename, e.dartContent));
final steps = feature.getStepFiles().whereType<NewStepFile>().map(
(e) =>
_createFileRecursively(e.filename, formatDartCode(e.dartContent)),
);
await Future.wait(steps);

final hookFile = feature.hookFile;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/util/dart_formatter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:dart_style/dart_style.dart';

final _formatter = DartFormatter();

String formatDartCode(String input) => _formatter.format(input);
7 changes: 4 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bdd_widget_test
description: A BDD-style widget testing library. Generates Flutter widget tests from *.feature files.
version: 1.7.3
version: 1.7.4
repository: /~https://github.com/olexale/bdd_widget_test
issue_tracker: /~https://github.com/olexale/bdd_widget_test/issues

Expand All @@ -12,6 +12,7 @@ dependencies:
build_config: ^1.0.0
characters: ^1.2.0
collection: ^1.15.0
dart_style: ^2.3.6
diacritic: ^0.1.3
file: ^7.0.0
flutter:
Expand All @@ -23,6 +24,6 @@ dependencies:
yaml: ^3.1.0

dev_dependencies:
build_runner: ^2.4.6
build_test: ^2.2.1
build_runner: ^2.4.10
build_test: ^2.2.2
very_good_analysis: ^5.1.0
9 changes: 6 additions & 3 deletions test/feature_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ hookFolderName: hooksFolder
' Future<void> beforeEach(String title, [List<String>? tags]) async {\n'
' await Hooks.beforeEach(title, tags);\n'
' }\n'
' Future<void> afterEach(String title, bool success, [List<String>? tags]) async {\n'
'\n'
' Future<void> afterEach(String title, bool success,\n'
' [List<String>? tags]) async {\n'
' await Hooks.afterEach(title, success, tags);\n'
' }\n'
'\n'
" customName('''Testing scenario''', (tester) async {\n"
' var success = true;\n'
' try {\n'
" await beforeEach('''Testing scenario''' );\n"
' await theAppIsRunning(tester);\n'
" await beforeEach('''Testing scenario''');\n"
' await theAppIsRunning(tester);\n'
' } on TestFailure {\n'
' success = false;\n'
' rethrow;\n'
Expand Down

0 comments on commit 4c28a34

Please sign in to comment.