Skip to content

Commit

Permalink
Merge 8a6b10d into 08ab760
Browse files Browse the repository at this point in the history
  • Loading branch information
vsiakka committed May 5, 2019
2 parents 08ab760 + 8a6b10d commit 8d1b092
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 11 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"eslint": "5.14.1",
"mocha": "5.2.0",
"mocha-sinon": "2.1.0",
"mock-fs": "4.9.0",
"nyc": "14.0.0",
"sinon": "6.2.0"
},
Expand Down
5 changes: 3 additions & 2 deletions src/feature-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function getFeatureFiles(args, ignoreArg) {
if (pattern == '.') {
fixedPattern = '**/*.feature';
} else if (pattern.match(/.*\/\*\*/)) {
fixedPattern = pattern.slice(0, -1) + '.feature';
fixedPattern = pattern + '/**.feature';
} else if (pattern.match(/.*\.feature/)) {
fixedPattern = pattern;
} else {
try {
if(fs.statSync(pattern).isDirectory()) {
if (fs.statSync(pattern).isDirectory()) {
fixedPattern = path.join(pattern, '**/*.feature');
}
} catch(e) {
Expand All @@ -34,6 +34,7 @@ function getFeatureFiles(args, ignoreArg) {
if (!fixedPattern) {
logger.boldError(`Invalid format of the feature file path/pattern: "${pattern}".\nTo run the linter please specify an existing feature file, directory or glob.`);
process.exit(1);
return; // This line will only be hit by tests that stub process.exit
}

var globOptions = {ignore: getIgnorePatterns(ignoreArg)};
Expand Down
89 changes: 81 additions & 8 deletions test/feature-finder/feature-finder.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,97 @@
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': ''
}
});
});

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([
'test/feature-finder/fixtures',
'test/feature-finder'
'folder/with/found/features/**',
'path/to/fake/**'
]);
assert.deepEqual(actual, [
'folder/with/found/features/a.feature',
'folder/with/found/features/folder/b.feature'
]);
assert.deepEqual(actual, ['test/feature-finder/fixtures/a.feature']);
});

it('ignores files when the --ignore argument is provided', function() {
var actual = featureFinder.getFeatureFiles(['test/feature-finder/**'],
['test/feature-finder/**']);
var actual = featureFinder.getFeatureFiles(['folder/with/found/features/**'],
['folder/with/found/features/**']);
assert.deepEqual(actual, []);
});

it('ignores files in the .gherkin-lintignore', function() {
featureFinder.defaultIgnoreFileName = 'test/feature-finder/fixtures/**';
var actual = featureFinder.getFeatureFiles(['test/feature-finder/**']);
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);
});
});
1 change: 0 additions & 1 deletion test/feature-finder/fixtures/.gherkin-lintignore

This file was deleted.

Empty file.

0 comments on commit 8d1b092

Please sign in to comment.