Skip to content

Commit 771db4a

Browse files
committed
Hotfix for ".." in step folder name
1 parent bfb37bb commit 771db4a

5 files changed

Lines changed: 26 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.0.3+1] - Custom step folder name hotix
2+
3+
* Hotfix for ".." in custom step names
4+
15
## [1.0.3] - Custom step folder name
26

37
* Add `stepFolderName` parameter that changes the step folder name

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ packages:
3535
path: ".."
3636
relative: true
3737
source: path
38-
version: "1.0.3"
38+
version: "1.0.3+1"
3939
boolean_selector:
4040
dependency: transitive
4141
description:

lib/src/existing_steps.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@ import 'dart:io';
22

33
import 'package:path/path.dart' as p;
44

5+
/// key - step filename, value - path for import (ex: {'i_have_a_step.dart': 'step/common'})
56
Map<String, String> getExistingStepSubfolders(
6-
String featureDir, String stepFolderName) {
7+
String featureDir,
8+
String stepFolderName,
9+
) {
710
final stepFolder = p.join(featureDir, stepFolderName);
811
final steps = Directory(stepFolder);
912
if (!steps.existsSync()) {
1013
return {};
1114
}
1215
return steps.listSync(recursive: true).asMap().map(
13-
(key, value) => MapEntry<String, String>(
14-
p.basename(value.path),
15-
_getStepFolder(
16-
value.uri.pathSegments,
16+
(_, step) => MapEntry<String, String>(
17+
p.basename(step.path),
18+
_getStepSubfolders(
19+
steps.uri.pathSegments.length,
20+
step.uri.pathSegments,
1721
stepFolderName,
1822
),
1923
),
2024
);
2125
}
2226

23-
String _getStepFolder(List<String> pathSegments, String stepFolderName) {
24-
final stepFolderIndex = pathSegments.indexOf(stepFolderName);
25-
final stepFolder =
26-
pathSegments.getRange(stepFolderIndex, pathSegments.length - 1);
27-
return p.joinAll(stepFolder);
27+
String _getStepSubfolders(
28+
int stepFolderPathSegmentsLength,
29+
List<String> currentStepPath,
30+
String stepFolderName,
31+
) {
32+
final pathDiff = currentStepPath.getRange(
33+
stepFolderPathSegmentsLength - 1, currentStepPath.length - 1);
34+
return p.joinAll([stepFolderName, ...pathDiff]);
2835
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: bdd_widget_test
22
description: A BDD-style widget testing library. Generates Flutter widget tests from *.feature files.
3-
version: 1.0.3
3+
version: 1.0.3+1
44
author: Oleksandr Leuschenko <olexa.le@gmail.com>
55
homepage: https://github.com/olexale/bdd_widget_test
66

test/step_folder_name_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Feature: Testing feature
1717
import 'package:flutter/material.dart';
1818
import 'package:flutter_test/flutter_test.dart';
1919
20-
import './custom_steps/the_app_is_running.dart';
20+
import './../../../custom_steps/the_app_is_running.dart';
2121
2222
void main() {
2323
group('Testing feature', () {
@@ -32,7 +32,8 @@ void main() {
3232
featureDir: 'test.feature',
3333
package: 'test',
3434
input: featureFile,
35-
generatorOptions: const GeneratorOptions(stepFolderName: 'custom_steps'),
35+
generatorOptions:
36+
const GeneratorOptions(stepFolderName: '../../../custom_steps'),
3637
);
3738
expect(feature.dartContent, expectedFeatureDart);
3839
});

0 commit comments

Comments
 (0)