Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: 🐦 Setup Flutter SDK
uses: flutter-actions/setup-flutter@v3
with:
channel: stable
version: '3.29.0'
- name: 🎯 Setup Dart SDK
uses: dart-lang/setup-dart@v1

- name: 🛠 Install dependencies
run: flutter pub get
run: dart pub get --no-example

- name: 👨‍🎨 Validate formatting
run: dart format --set-exit-if-changed lib test

- name: 🕵️‍♀️ Analyze project source
run: flutter analyze . --fatal-infos
run: dart analyze --fatal-infos --format machine lib test

- name: 🤖 Install coverage
run: dart pub global activate coverage

- name: 🧪 Run tests
run: flutter test --coverage
run: dart pub global run coverage:test_with_coverage

- name: 🎯 Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v1
Expand All @@ -47,7 +47,7 @@ jobs:

- name: 📈 Check pana
run: |
flutter pub global activate pana
dart 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]
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.9.0] - Upgrade dependencies

* **BREAKING CHANGE**: The package doesn't provide pre-built steps anymore. Steps will appear in the `step` folder.
* Drop unused dependencies
* Upgrade `build` dependency

## [1.8.2] - Ignore linter warnings

* Ignore all lint or warning rules in generated code by (@lsaudon)
Expand Down
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,35 +204,6 @@ List of predefined steps:
* I tap {..} text
* The app is running

If you want to use predefined steps without having them in your `steps` folder then you may create a `build.yaml` file in the root of your project with the following content (see the `example` folder):
```yaml
targets:
$default:
builders:
bdd_widget_test|featureBuilder:
options:
externalSteps:
- package:bdd_widget_test/step/i_see_text.dart
- package:bdd_widget_test/step/i_dont_see_text.dart
- package:bdd_widget_test/step/i_see_multiple_texts.dart
- package:bdd_widget_test/step/i_tap_text.dart
- package:bdd_widget_test/step/i_see_icon.dart
- package:bdd_widget_test/step/i_dont_see_icon.dart
- package:bdd_widget_test/step/i_tap_icon.dart
- package:bdd_widget_test/step/i_see_rich_text.dart
- package:bdd_widget_test/step/i_dont_see_rich_text.dart
- package:bdd_widget_test/step/i_see_widget.dart
- package:bdd_widget_test/step/i_dont_see_widget.dart
- package:bdd_widget_test/step/i_see_exactly_widgets.dart
- package:bdd_widget_test/step/i_see_multiple_widgets.dart
- package:bdd_widget_test/step/i_enter_into_input_field.dart
- package:bdd_widget_test/step/i_see_disabled_elevated_button.dart
- package:bdd_widget_test/step/i_see_enabled_elevated_button.dart
- package:bdd_widget_test/step/i_wait.dart
- package:bdd_widget_test/step/i_dismiss_the_page.dart
```
That will tell the plugin to reuse steps from the plugin itself and do not put them into your code.

## Hooks
If you want to add hooks, you need to add the addHooks flag to the `build.yaml`. This will generate a file that allows you to handle a beforeAll, afterAll, beforeEach and afterEach call.
These hooks will be generated per directory, just like the steps. Also like with the steps, you can define a directory in the build.yaml to define one set location for the hooks. These hooks will then be used everywhere.
Expand Down
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
include: package:very_good_analysis/analysis_options.yaml

analyzer:
exclude: [test/**_test.dart, example/test/**_test.dart]

linter:
rules:
avoid_positional_boolean_parameters: false
Expand Down
3 changes: 0 additions & 3 deletions example/bdd_options.yaml

This file was deleted.

38 changes: 19 additions & 19 deletions example/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ targets:
# testMethodName: customTestMethodName
# addHooks: true # if true, hooks will be added to the test; default is false
# hookFolderName: bdd_hooks
include: package:bdd_widget_test/bdd_options.yaml # you may add defaul external steps with this line
# include: package:<package1>/bdd_options.yaml # you may add defaul external steps with this line
externalSteps: # or list only steps that you need
- package:bdd_widget_test/step/i_see_text.dart
# - package:bdd_widget_test/step/i_dont_see_text.dart
# - package:bdd_widget_test/step/i_see_multiple_texts.dart
# - package:bdd_widget_test/step/i_tap_text.dart
# - package:bdd_widget_test/step/i_see_icon.dart
# - package:bdd_widget_test/step/i_dont_see_icon.dart
# - package:bdd_widget_test/step/i_tap_icon.dart
# - package:bdd_widget_test/step/i_see_rich_text.dart
# - package:bdd_widget_test/step/i_dont_see_rich_text.dart
# - package:bdd_widget_test/step/i_see_widget.dart
# - package:bdd_widget_test/step/i_dont_see_widget.dart
# - package:bdd_widget_test/step/i_see_exactly_widgets.dart
# - package:bdd_widget_test/step/i_see_multiple_widgets.dart
# - package:bdd_widget_test/step/i_enter_into_input_field.dart
# - package:bdd_widget_test/step/i_see_disabled_elevated_button.dart
# - package:bdd_widget_test/step/i_see_enabled_elevated_button.dart
# - package:bdd_widget_test/step/i_wait.dart
# - package:bdd_widget_test/step/i_dismiss_the_page.dart
# - package:<package2>/step/i_see_text.dart
# - package:<package2>/step/i_dont_see_text.dart
# - package:<package2>/step/i_see_multiple_texts.dart
# - package:<package2>/step/i_tap_text.dart
# - package:<package2>/step/i_see_icon.dart
# - package:<package2>/step/i_dont_see_icon.dart
# - package:<package2>/step/i_tap_icon.dart
# - package:<package2>/step/i_see_rich_text.dart
# - package:<package2>/step/i_dont_see_rich_text.dart
# - package:<package2>/step/i_see_widget.dart
# - package:<package2>/step/i_dont_see_widget.dart
# - package:<package2>/step/i_see_exactly_widgets.dart
# - package:<package2>/step/i_see_multiple_widgets.dart
# - package:<package2>/step/i_enter_into_input_field.dart
# - package:<package2>/step/i_see_disabled_elevated_button.dart
# - package:<package2>/step/i_see_enabled_elevated_button.dart
# - package:<package2>/step/i_wait.dart
# - package:<package2>/step/i_dismiss_the_page.dart
generate_for:
- test/**
- integration_test/**
Expand Down
4 changes: 2 additions & 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.

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.10
build_runner: ^2.7.0
flutter_driver:
sdk: flutter
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
patrol: ^3.7.2
patrol: ^3.19.0

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

4 changes: 2 additions & 2 deletions example/test/sample_test.dart

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

14 changes: 7 additions & 7 deletions example/test/songs_test.dart

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

File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion example/test/step/i_tap_icon_times.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:bdd_widget_test/step/i_tap_icon.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import 'i_tap_icon.dart';

Future<void> iTapIconTimes(
WidgetTester tester,
IconData icon,
Expand Down
19 changes: 0 additions & 19 deletions lib/bdd_options.yaml

This file was deleted.

111 changes: 111 additions & 0 deletions lib/bdd_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,124 @@ import 'package:build/build.dart';
import 'package:path/path.dart' as p;
import 'package:yaml/yaml.dart';

/// Creates a [FeatureBuilder] instance with the provided build options.
///
/// This function is the main entry point for the BDD Widget Test code
/// generation system. It's used by the build system to create a builder
/// that processes `.feature` files and generates corresponding Dart test files.
///
/// The [options] parameter contains configuration settings from `build.yaml`
/// and/or `bdd_options.yaml` files, which are converted to [GeneratorOptions]
/// and used to customize the code generation behavior.
///
/// Example usage in `build.yaml`:
/// ```yaml
/// targets:
/// $default:
/// builders:
/// bdd_widget_test|featureBuilder:
/// options:
/// testMethodName: testGoldens
/// stepFolderName: ./custom_steps
/// ```
///
/// Returns a [FeatureBuilder] instance configured with the specified options.
Builder featureBuilder(BuilderOptions options) => FeatureBuilder(
GeneratorOptions.fromMap(options.config),
);

/// A code generator builder that transforms BDD feature files into Dart test files.
///
/// [FeatureBuilder] is responsible for parsing Gherkin feature files (`.feature`)
/// and generating corresponding Dart test files (`_test.dart`) that can be executed
/// as Flutter widget tests. It handles the complete transformation process including:
///
/// - Parsing feature files written in Gherkin syntax
/// - Generating executable Dart test code with proper test structure
/// - Creating step definition files for new steps
/// - Managing existing step definitions and imports
/// - Handling hooks for setup and teardown operations
/// - Supporting integration test configurations
/// - Applying customizable generation options
///
/// The builder processes files with the `.feature` extension and outputs
/// corresponding `_test.dart` files in the same directory structure.
///
/// Features supported:
/// - Scenarios and Scenario Outlines
/// - Data Tables and Examples
/// - Tags for conditional execution
/// - Background steps
/// - Hooks (Before/After)
/// - Custom test method names
/// - Custom tester types and names
/// - Integration test binding
/// - External step definitions
///
/// Example feature file:
/// ```gherkin
/// Feature: Counter App
/// Scenario: Initial counter value is 0
/// Given the app is running
/// Then I see {'0'} text
/// ```
///
/// Generated test file:
/// ```dart
/// void main() {
/// group('''Counter App''', () {
/// testWidgets('''Initial counter value is 0''', (tester) async {
/// await theAppIsRunning(tester);
/// await iSeeText(tester, '0');
/// });
/// });
/// }
/// ```
class FeatureBuilder implements Builder {
/// Creates a new [FeatureBuilder] with the specified generator options.
///
/// The [generatorOptions] parameter defines how the builder should generate
/// test code, including:
/// - Test method names (e.g., `testWidgets`, `testGoldens`)
/// - Tester types and names (e.g., `WidgetTester`, `PatrolIntegrationTester`)
/// - Step folder locations and naming conventions
/// - Hook configurations for setup and teardown
/// - Integration test settings
/// - External step definitions
///
/// This constructor is typically called by the [featureBuilder] function
/// rather than being invoked directly.
///
/// Example:
/// ```dart
/// final builder = FeatureBuilder(
/// GeneratorOptions(
/// testMethodName: 'testGoldens',
/// stepFolderName: './custom_steps',
/// testerType: 'PatrolIntegrationTester',
/// ),
/// );
/// ```
FeatureBuilder(this.generatorOptions);

/// Configuration options that control how feature files are processed and
/// what kind of Dart test code is generated.
///
/// These options can be customized through:
/// - `build.yaml` builder configuration
/// - `bdd_options.yaml` project-specific settings
/// - Included external configuration files
///
/// The options are merged in priority order, with builder options taking
/// precedence over file-based options.
///
/// Common configuration properties:
/// - `testMethodName`: The Flutter test method to use (default: 'testWidgets')
/// - `testerType`: The type of tester parameter (default: 'WidgetTester')
/// - `testerName`: The name of the tester parameter (default: 'tester')
/// - `stepFolderName`: Directory for step definition files (default: './step')
/// - `addHooks`: Whether to generate hook files (default: false)
/// - `includeIntegrationTestBinding`: Integration test support (default: true)
final GeneratorOptions generatorOptions;

@override
Expand Down
9 changes: 0 additions & 9 deletions lib/step/i_dismiss_the_page.dart

This file was deleted.

10 changes: 0 additions & 10 deletions lib/step/i_dont_see_icon.dart

This file was deleted.

Loading