-
Notifications
You must be signed in to change notification settings - Fork 73
/
feature-finder.js
99 lines (89 loc) · 3.36 KB
/
feature-finder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var assert = require('chai').assert;
var expect = require('chai').expect;
var featureFinder = require('../../dist/feature-finder.js');
var mockFs = require('mock-fs');
describe('Feature finder', function() {
beforeEach(function() {
this.sinon.stub(console, 'error');
this.sinon.stub(process, 'exit');
mockFs({
'folder/with/found/features': {
'a.feature': '',
'folder': { 'b.feature': '' },
'c.txt': ''
},
'../folder/with/unfound/features': {
'd.feature': '',
'e.txt': ''
},
'feature': {
'f.txt': ''
},
'directory.feature': {
}
});
});
afterEach(function() {
mockFs.restore();
console.error.restore(); // eslint-disable-line no-console
process.exit.restore();
});
it('returns all feature files found recursively in the current directory when no path is passed to the command line', function() {
var actual = featureFinder.getFeatureFiles([]);
assert.deepEqual(actual, [
'folder/with/found/features/a.feature',
'folder/with/found/features/folder/b.feature'
]);
});
it('returns all feature files in a directory and its subfolders when a "path/to/dir/**" pattern is used', function() {
var actual = featureFinder.getFeatureFiles(['folder/with/found/features/**']);
assert.deepEqual(actual, [
'folder/with/found/features/a.feature',
'folder/with/found/features/folder/b.feature'
]);
});
it('returns all feature files in a directory when a "path/to/dir/*.feature" pattern is used', function() {
var actual = featureFinder.getFeatureFiles(['folder/with/found/features/*.feature']);
assert.deepEqual(actual, [
'folder/with/found/features/a.feature'
]);
});
it('returns all feature files in a directory and its subfolders when a path to a directory is used', function() {
var actual = featureFinder.getFeatureFiles(['folder/with/found/features/']);
assert.deepEqual(actual, [
'folder/with/found/features/a.feature',
'folder/with/found/features/folder/b.feature'
]);
});
it('does not return duplicates', function() {
var actual = featureFinder.getFeatureFiles([
'folder/with/found/features/**',
'path/to/fake/**'
]);
assert.deepEqual(actual, [
'folder/with/found/features/a.feature',
'folder/with/found/features/folder/b.feature'
]);
});
it('ignores files when the --ignore argument is provided', function() {
var actual = featureFinder.getFeatureFiles(['folder/with/found/features/**'],
['folder/with/found/features/**']);
assert.deepEqual(actual, []);
});
it('ignores files in the .gherkin-lintignore when specified as glob patterns', function() {
mockFs({
'.gherkin-lintignore':
'folder/with/found/features/a.feature\n\n..folder/with/found/features/**'
});
var actual = featureFinder.getFeatureFiles(['folder/with/found/features/**']);
assert.deepEqual(actual, []);
});
it('prints an error message and exits with code 1 when a bad file pattern is used', function() {
featureFinder.getFeatureFiles(['badpattern**']);
var consoleErrorArgs = console.error.args.map(function (args) { // eslint-disable-line no-console
return args[0];
});
expect(consoleErrorArgs[0]).to.include('Invalid format of the feature file path/pattern:');
expect(process.exit.args[0][0]).to.equal(1);
});
});