Skip to content

Commit

Permalink
Hotfix for ".." in step folder name
Browse files Browse the repository at this point in the history
  • Loading branch information
olexale committed May 22, 2021
1 parent bfb37bb commit 771db4a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## [1.0.3+1] - Custom step folder name hotix

* Hotfix for ".." in custom step names

## [1.0.3] - Custom step folder name

* Add `stepFolderName` parameter that changes the step folder name
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Expand Up @@ -35,7 +35,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.3"
version: "1.0.3+1"
boolean_selector:
dependency: transitive
description:
Expand Down
27 changes: 17 additions & 10 deletions lib/src/existing_steps.dart
Expand Up @@ -2,27 +2,34 @@ import 'dart:io';

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

/// key - step filename, value - path for import (ex: {'i_have_a_step.dart': 'step/common'})
Map<String, String> getExistingStepSubfolders(
String featureDir, String stepFolderName) {
String featureDir,
String stepFolderName,
) {
final stepFolder = p.join(featureDir, stepFolderName);
final steps = Directory(stepFolder);
if (!steps.existsSync()) {
return {};
}
return steps.listSync(recursive: true).asMap().map(
(key, value) => MapEntry<String, String>(
p.basename(value.path),
_getStepFolder(
value.uri.pathSegments,
(_, step) => MapEntry<String, String>(
p.basename(step.path),
_getStepSubfolders(
steps.uri.pathSegments.length,
step.uri.pathSegments,
stepFolderName,
),
),
);
}

String _getStepFolder(List<String> pathSegments, String stepFolderName) {
final stepFolderIndex = pathSegments.indexOf(stepFolderName);
final stepFolder =
pathSegments.getRange(stepFolderIndex, pathSegments.length - 1);
return p.joinAll(stepFolder);
String _getStepSubfolders(
int stepFolderPathSegmentsLength,
List<String> currentStepPath,
String stepFolderName,
) {
final pathDiff = currentStepPath.getRange(
stepFolderPathSegmentsLength - 1, currentStepPath.length - 1);
return p.joinAll([stepFolderName, ...pathDiff]);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: bdd_widget_test
description: A BDD-style widget testing library. Generates Flutter widget tests from *.feature files.
version: 1.0.3
version: 1.0.3+1
author: Oleksandr Leuschenko <olexa.le@gmail.com>
homepage: https://github.com/olexale/bdd_widget_test

Expand Down
5 changes: 3 additions & 2 deletions test/step_folder_name_test.dart
Expand Up @@ -17,7 +17,7 @@ Feature: Testing feature
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import './custom_steps/the_app_is_running.dart';
import './../../../custom_steps/the_app_is_running.dart';
void main() {
group('Testing feature', () {
Expand All @@ -32,7 +32,8 @@ void main() {
featureDir: 'test.feature',
package: 'test',
input: featureFile,
generatorOptions: const GeneratorOptions(stepFolderName: 'custom_steps'),
generatorOptions:
const GeneratorOptions(stepFolderName: '../../../custom_steps'),
);
expect(feature.dartContent, expectedFeatureDart);
});
Expand Down

0 comments on commit 771db4a

Please sign in to comment.