Skip to content

Commit 4a4da14

Browse files
committed
Absolute and relative step folder
1 parent c987d09 commit 4a4da14

14 files changed

Lines changed: 113 additions & 47 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ targets:
311311
stepFolderName: bdd_steps
312312
```
313313

314+
That will tell the plugin to create a `bdd_steps` folder under `test` (instead of `step` near each feature) and put all the steps there.
315+
314316
You may set a relative path here (like `../../bdd_steps`), just be sure that the target folder is still somewhere under the `test` folder.
315317

316318
### How to write integration tests?
@@ -333,7 +335,7 @@ targets:
333335
```
334336
3. (Optional) If you plan to re-use steps between integration and widget tests set a common step folder in the `build.yaml` file like that (here is the full [sample](example/build.yaml)):
335337
```yaml
336-
stepFolderName: ../test/step
338+
stepFolderName: step
337339
```
338340
4. Done. Now you may create feature files in `integration_test` folder. You may want to review the [official documentation](https://flutter.dev/docs/testing/integration-tests) for instructions on how to run integration tests.
339341

analysis_options.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
include: package:very_good_analysis/analysis_options.yaml
22

3-
analyzer:
4-
exclude:
5-
# workaround for https://github.com/dart-lang/sdk/issues/42910
6-
- 'example/**'
7-
83
linter:
94
rules:
105
avoid_positional_boolean_parameters: false

example/build.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ targets:
88
builders:
99
bdd_widget_test|featureBuilder:
1010
options:
11-
# stepFolderName: bdd_steps
12-
stepFolderName: ../test/step # this trick is required to share steps between widget and integration tests
11+
stepFolderName: step # this trick is required to share steps between widget and integration tests
1312
# testMethodName: customTestMethodName
1413
include: package:bdd_widget_test/bdd_options.yaml # you may add defaul external steps with this line
1514
externalSteps: # or list only steps that you need
@@ -32,5 +31,5 @@ targets:
3231
# - package:bdd_widget_test/step/i_wait.dart
3332
# - package:bdd_widget_test/step/i_dismiss_the_page.dart
3433
generate_for:
35-
- test/*.feature
36-
- integration_test/*.feature
34+
- test/**
35+
- integration_test/**

example/integration_test/sample_test.dart

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@slow
2+
@ui
3+
Feature: Counter
4+
@important
5+
@simple
6+
Scenario: Initial counter value is 0
7+
Given the app is running
8+
Then I see {'0'} text

example/test/features/sub-feature/sub-sub-feature/sample_test.dart

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/test/sample_test.dart

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/existing_steps.dart

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:bdd_widget_test/src/util/constants.dart';
12
import 'package:bdd_widget_test/src/util/fs.dart';
23
import 'package:path/path.dart' as p;
34

@@ -6,31 +7,26 @@ Map<String, String> getExistingStepSubfolders(
67
String featureDir,
78
String stepFolderName,
89
) {
9-
final stepFolder = p.join(featureDir, stepFolderName);
10+
final stepFolder = p.join(
11+
stepFolderName.startsWith('./') || stepFolderName.startsWith('../')
12+
? featureDir
13+
: testFolderName,
14+
stepFolderName,
15+
);
16+
1017
final steps = fs.directory(stepFolder);
1118
if (!steps.existsSync()) {
1219
return {};
1320
}
1421
return steps.listSync(recursive: true).asMap().map(
1522
(_, step) => MapEntry<String, String>(
1623
p.basename(step.path),
17-
_getStepSubfolders(
18-
steps.uri.pathSegments.length,
19-
step.uri.pathSegments,
20-
stepFolderName,
24+
p.dirname(
25+
p.relative(
26+
step.path,
27+
from: featureDir,
28+
),
2129
),
2230
),
2331
);
2432
}
25-
26-
String _getStepSubfolders(
27-
int stepFolderPathSegmentsLength,
28-
List<String> currentStepPath,
29-
String stepFolderName,
30-
) {
31-
final pathDiff = currentStepPath.getRange(
32-
stepFolderPathSegmentsLength - 1,
33-
currentStepPath.length - 1,
34-
);
35-
return p.joinAll([stepFolderName, ...pathDiff]);
36-
}

lib/src/generator_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:bdd_widget_test/src/util/isolate_helper.dart';
33
import 'package:yaml/yaml.dart';
44

55
const _defaultTestName = 'testWidgets';
6-
const _stepFolderName = 'step';
6+
const _stepFolderName = './step';
77

88
class GeneratorOptions {
99
const GeneratorOptions({

lib/src/step_file.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:bdd_widget_test/src/generator_options.dart';
22
import 'package:bdd_widget_test/src/step_generator.dart';
3+
import 'package:bdd_widget_test/src/util/constants.dart';
34
import 'package:path/path.dart' as p;
45

56
abstract class StepFile {
@@ -27,9 +28,19 @@ abstract class StepFile {
2728
return ExternalStepFile._(externalStep);
2829
}
2930

30-
final import =
31-
p.join('.', generatorOptions.stepFolder, file).replaceAll(r'\', '/');
32-
final filename = p.join(featureDir, generatorOptions.stepFolder, file);
31+
if (generatorOptions.stepFolder.startsWith('./') ||
32+
generatorOptions.stepFolder.startsWith('../')) {
33+
final import =
34+
p.join(generatorOptions.stepFolder, file).replaceAll(r'\', '/');
35+
final filename = p.join(featureDir, generatorOptions.stepFolder, file);
36+
return NewStepFile._(import, filename, package, line);
37+
}
38+
39+
final pathToTestFolder = p.relative(testFolderName, from: featureDir);
40+
final import = p
41+
.join(pathToTestFolder, generatorOptions.stepFolder, file)
42+
.replaceAll(r'\', '/');
43+
final filename = p.join(testFolderName, generatorOptions.stepFolder, file);
3344
return NewStepFile._(import, filename, package, line);
3445
}
3546
}

0 commit comments

Comments
 (0)