Skip to content

Commit 97f8206

Browse files
committed
Fix cucumber get test cases
Fixes cucumber/cucumber-js#1489 Closes: purpleteam-labs/purpleteam#13
1 parent ec8bbfb commit 97f8206

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/api/app/models/app.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,6 @@ class App {
142142
const configuration = await cucumberCli.getConfiguration();
143143
const pickleFilter = (() => new (require('@cucumber/cucumber/lib/pickle_filter')).default(configuration.pickleFilterOptions))(); // eslint-disable-line global-require, new-cap
144144

145-
const flatten = (o) => [].concat(...Object.keys(o)
146-
.map((k) => (typeof o[k] === 'object'
147-
? flatten(o[k])
148-
: ({ [k]: o[k] }))));
149-
150-
const activeTags = flatten(pickleFilter.tagFilter.tagExpressionNode).map((tagObj) => tagObj.value);
151-
152145
const streamToArray = async (readableStream) => new Promise((resolve, reject) => {
153146
const items = [];
154147
readableStream.on('data', (item) => items.push(item));
@@ -157,11 +150,22 @@ class App {
157150
});
158151

159152
const activeFeatureFileUris = async () => {
160-
const envelopes = await streamToArray(GherkinStreams.fromPaths(configuration.featurePaths, { includeSource: false, includeGherkinDocument: false, includePickles: true }));
161-
const tagUriMaps = envelopes.map((e) => ({ tagName: e.pickle.tags[0].name, fileUri: e.pickle.uri }));
162-
const activeTagUriMaps = tagUriMaps.filter((tU) => activeTags.includes(tU.tagName));
163-
const activeUris = activeTagUriMaps.reduce((accum, cV) => [...accum, ...(accum.includes(cV.fileUri) ? [] : [cV.fileUri])], []);
164-
return activeUris;
153+
const envelopes = await streamToArray(GherkinStreams.fromPaths(configuration.featurePaths, { includeSource: false, includeGherkinDocument: true, includePickles: true }));
154+
let gherkinDocument = null;
155+
const pickles = [];
156+
157+
envelopes.forEach((e) => {
158+
if (e.gherkinDocument) {
159+
gherkinDocument = e.gherkinDocument;
160+
} else if (e.pickle && gherkinDocument) {
161+
const { pickle } = e;
162+
if (pickleFilter.matches({ gherkinDocument, pickle })) pickles.push({ pickle });
163+
}
164+
});
165+
166+
return pickles
167+
.map((p) => p.pickle.uri)
168+
.reduce((accum, cV) => [...accum, ...(accum.includes(cV) ? [] : [cV])], []);
165169
};
166170

167171
return activeFeatureFileUris();

test/api/app/models/app.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,26 @@ test('Given tagExpression: (@app_scan or @simple_math) - when getActiveFeatureFi
5656

5757
// Since cucumber.getTestCasesFromFilesystem was removed, the following test cases fail, including the ones not yet implemented.
5858

59-
test.failing('Given tagExpression: (@app_scan and @simple_math) - when getActiveFeatureFileUris is invoked - then no active feature file Uris should be returned', async (t) => {
59+
test('Given tagExpression: (@app_scan and @simple_math) - when getActiveFeatureFileUris is invoked - then no active feature file Uris should be returned', async (t) => {
6060
t.plan(1);
6161
// Active feature files are based on the cucumber.tagExpression defined in config.
6262
// https://cucumber.io/docs/cucumber/api/#tag-expressions
6363
// https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags
6464
const tagExpression = '(@app_scan and @simple_math)';
6565
const activeFeatureFileUris = await setupGetActiveFeatureFileUris({ tagExpression });
6666
t.deepEqual(activeFeatureFileUris, []);
67-
// What we get is: [`${appRootDir}/testResources/features/app_scan.feature`, `${appRootDir}/testResources/features/simple_math.feature`]
6867
});
6968

70-
test.failing('Given tagExpression: (not @simple_math) - when getActiveFeatureFileUris is invoked - then active feature file Uris app_scan.feature should be returned', async (t) => {
69+
test('Given tagExpression: (not @simple_math) - when getActiveFeatureFileUris is invoked - then active feature file Uris app_scan.feature should be returned', async (t) => {
7170
t.plan(1);
7271
// Active feature files are based on the cucumber.tagExpression defined in config.
7372
// https://cucumber.io/docs/cucumber/api/#tag-expressions
7473
// https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags
7574
const tagExpression = '(not @simple_math)';
7675
const activeFeatureFileUris = await setupGetActiveFeatureFileUris({ tagExpression });
7776
t.deepEqual(activeFeatureFileUris, [`${appRootDir}/testResources/features/app_scan.feature`]);
78-
// What we get is: [`${appRootDir}/testResources/features/simple_math.feature`]
7977
});
8078

81-
// The following are also not catered for currently.
8279
// Ideas for creating feature files with tags to test for here: https://cucumber.io/docs/cucumber/api/#tags
8380

8481
// @wip and not @slow

0 commit comments

Comments
 (0)