diff --git a/lib/path-utils.js b/lib/path-utils.js deleted file mode 100644 index bee66a10a..000000000 --- a/lib/path-utils.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -const q = require('q'); -const qfs = require('q-io/fs'); -const _ = require('lodash'); -const glob = require('glob'); - -const getFilesByMask = (mask) => { - return q.denodeify(glob)(mask) - .then((paths) => _.isEmpty(paths) - ? q.reject('Cannot find files by mask ' + mask) - : paths - ); -}; - -const listJsFiles = (path) => { - return qfs.listTree(path) - .then((paths) => paths.filter((path) => qfs.extension(path) === '.js')); -}; - -const expandPath = (path) => { - return qfs.stat(path) - .then((stat) => stat.isDirectory() ? listJsFiles(path) : [path]) - .then((paths) => paths.map((path) => qfs.absolute(path))); -}; - -const processPaths = (paths, callback) => { - return _(paths) - .map(callback) - .thru(q.all).value() - .then(_.flatten) - .then(_.uniq); -}; - -exports.expandPaths = (paths) => { - return processPaths(paths, getFilesByMask) - .then((matchedPaths) => processPaths(matchedPaths, expandPath)); -}; diff --git a/lib/tests-reader.js b/lib/tests-reader.js index 7f415faa3..66f88c217 100644 --- a/lib/tests-reader.js +++ b/lib/tests-reader.js @@ -1,10 +1,12 @@ 'use strict'; -var pathUtils = require('./path-utils'), +var globExtra = require('glob-extra'), _ = require('lodash'), q = require('q'), validateUnknownBrowsers = require('./validators').validateUnknownBrowsers; +const expandJsPaths = (paths) => globExtra.expandPaths(paths, {formats: ['.js']}); + module.exports = function(testPaths, browsers, config) { var specs = config.specs, configBrowsers = _.keys(config.browsers), @@ -14,7 +16,7 @@ module.exports = function(testPaths, browsers, config) { return q.all([ expandSpecs(specs, configBrowsers), - pathUtils.expandPaths(testPaths) + expandJsPaths(testPaths) ]) .spread(function(specs, testFiles) { return filterSpecs(specs, testFiles, browsers); @@ -35,7 +37,7 @@ function expandSpecs(specs, configBrowsers) { var paths = _.isString(spec) ? [spec] : spec.files; - return pathUtils.expandPaths(paths) + return expandJsPaths(paths) .then(function(files) { return { files: files, diff --git a/package.json b/package.json index aaadd1d73..0677d01c0 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,11 @@ "chalk": "^1.1.1", "clear-require": "^1.0.1", "commander": "^2.9.0", - "glob": "^7.0.5", + "glob-extra": "^1.1.0", "inherit": "^2.2.2", "lodash": "~3.10.1", "mocha": "~2.4.5", "q": "^2.0.0", - "q-io": "^2.0.6", "q-promise-utils": "^1.0.0", "qemitter": "^1.1.0", "teamcity-service-messages": "^0.1.6", diff --git a/test/lib/cli.js b/test/lib/cli.js index 7b47b5199..b964967f4 100644 --- a/test/lib/cli.js +++ b/test/lib/cli.js @@ -1,7 +1,7 @@ 'use strict'; const q = require('q'); -const pathUtils = require('../../lib/path-utils'); +const globExtra = require('glob-extra'); const cli = require('../../lib/cli'); const logger = require('../../lib/utils').logger; const ConfigReader = require('../../lib/config-reader'); @@ -12,7 +12,7 @@ describe('exit codes', () => { const sandbox = sinon.sandbox.create(); beforeEach(() => { - sandbox.stub(pathUtils, 'expandPaths').returns(q([])); + sandbox.stub(globExtra, 'expandPaths').returns(q([])); sandbox.stub(logger); sandbox.stub(process, 'exit'); sandbox.stub(ConfigReader.prototype, 'read'); diff --git a/test/lib/path-utils.js b/test/lib/path-utils.js deleted file mode 100644 index de310889e..000000000 --- a/test/lib/path-utils.js +++ /dev/null @@ -1,81 +0,0 @@ -'use strict'; - -const proxyquire = require('proxyquire'); -const qfs = require('q-io/fs'); -const q = require('q'); - -describe('path-utils', () => { - const sandbox = sinon.sandbox.create(); - - let glob; - let pathUtils; - - beforeEach(() => { - sandbox.stub(qfs, 'listTree'); - sandbox.stub(qfs, 'absolute'); - sandbox.stub(qfs, 'stat').returns(q({isDirectory: () => false})); - - glob = sandbox.stub(); - - pathUtils = proxyquire('../../lib/path-utils', {glob}); - }); - - afterEach(() => sandbox.restore()); - - it('should get absolute file path from passed mask', () => { - glob.withArgs('some/deep/**/*.js').yields(null, ['some/deep/path/file.js']); - - qfs.absolute.withArgs('some/deep/path/file.js').returns('/absolute/some/deep/path/file.js'); - - return pathUtils.expandPaths(['some/deep/**/*.js']) - .then((absolutePaths) => { - assert.deepEqual(absolutePaths, ['/absolute/some/deep/path/file.js']); - }); - }); - - it('should get absolute js file path from passed directory path', () => { - glob.withArgs('some/path/').yields(null, ['some/path/']); - - qfs.stat.returns(q({isDirectory: () => true})); - - qfs.listTree.withArgs('some/path/').returns(q(['some/path/first.js', 'some/path/second.txt'])); - - qfs.absolute.withArgs('some/path/first.js').returns('/absolute/some/path/first.js'); - - return pathUtils.expandPaths(['some/path/']) - .then((absolutePaths) => { - assert.deepEqual(absolutePaths, ['/absolute/some/path/first.js']); - }); - }); - - it('should return uniq absolute file path', () => { - glob.withArgs('some/path/file.js').yields(null, ['some/path/file.js']); - - qfs.absolute.withArgs('some/path/file.js').returns('/absolute/some/path/file.js'); - - return pathUtils.expandPaths(['some/path/file.js', 'some/path/file.js']) - .then((absolutePaths) => { - assert.deepEqual(absolutePaths, ['/absolute/some/path/file.js']); - }); - }); - - it('should get absolute file path from passed file path', () => { - glob.withArgs('some/path/file.js').yields(null, ['some/path/file.js']); - - qfs.absolute.withArgs('some/path/file.js').returns('/absolute/some/path/file.js'); - - return pathUtils.expandPaths(['some/path/file.js']) - .then((absolutePaths) => { - assert.deepEqual(absolutePaths, ['/absolute/some/path/file.js']); - }); - }); - - it('should throw an error if a mask is bad', () => { - glob.withArgs('bad/mask/*.js').yields(null, []); - - return pathUtils.expandPaths(['bad/mask/*.js']) - .catch((globError) => { - assert.equal(globError, 'Cannot find files by mask bad/mask/*.js'); - }); - }); -}); diff --git a/test/lib/tests-reader.js b/test/lib/tests-reader.js index 263922e5f..159afbbd8 100644 --- a/test/lib/tests-reader.js +++ b/test/lib/tests-reader.js @@ -1,6 +1,6 @@ 'use strict'; -var pathUtils = require('../../lib/path-utils'), +var globExtra = require('glob-extra'), readTests = require('../../lib/tests-reader'), logger = require('../../lib/utils').logger, makeConfigStub = require('../utils').makeConfigStub, @@ -11,10 +11,10 @@ describe('tests-reader', function() { var sandbox = sinon.sandbox.create(); beforeEach(function() { - sandbox.stub(pathUtils, 'expandPaths'); + sandbox.stub(globExtra, 'expandPaths'); sandbox.stub(logger, 'warn'); - pathUtils.expandPaths.returns(q([])); + globExtra.expandPaths.returns(q([])); }); afterEach(function() { @@ -40,7 +40,7 @@ describe('tests-reader', function() { }); it('should assign specified browsers to specified test files in specs', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['test1']).returns(q(['/test1'])) .withArgs(['dir']).returns(q(['/dir/test2', '/dir/test3'])); @@ -61,7 +61,7 @@ describe('tests-reader', function() { }); it('should support intersection of test paths in specs', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['dir', 'dir1']).returns(q(['/dir/test', '/dir1/test'])) .withArgs(['dir', 'dir2']).returns(q(['/dir/test', '/dir2/test'])); @@ -82,7 +82,7 @@ describe('tests-reader', function() { }); it('should support intersection of subpaths in specs', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['dir']).returns(q(['/dir/sub-dir/test'])) .withArgs(['dir/sub-dir']).returns(q(['/dir/sub-dir/test'])); @@ -103,7 +103,7 @@ describe('tests-reader', function() { }); it('should support intersection of browsers in specs', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['test1']).returns(q(['/test1'])) .withArgs(['test2']).returns(q(['/test2'])); @@ -125,7 +125,7 @@ describe('tests-reader', function() { }); it('should assign all browsers to test files which are specified as strings in specs', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['test1']).returns(q(['/test1'])) .withArgs(['test2']).returns(q(['/test2'])); @@ -143,7 +143,7 @@ describe('tests-reader', function() { }); it('should assign all browsers to test files which are specified as objects without `browsers` property', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['test1']).returns(q(['/test1'])) .withArgs(['test2']).returns(q(['/test2'])); @@ -161,7 +161,7 @@ describe('tests-reader', function() { }); it('should support string and object notations in specs', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['test1']).returns(q(['/test1'])) .withArgs(['test2']).returns(q(['/test2'])); @@ -179,7 +179,7 @@ describe('tests-reader', function() { }); it('should not assign unknown browsers to test files', function() { - pathUtils.expandPaths.withArgs(['test']).returns(q(['/test'])); + globExtra.expandPaths.withArgs(['test']).returns(q(['/test'])); var params = { config: { @@ -206,7 +206,7 @@ describe('tests-reader', function() { }); it('should filter browsers from specs in case of input browsers', function() { - pathUtils.expandPaths.withArgs(['test']).returns(q(['/test'])); + globExtra.expandPaths.withArgs(['test']).returns(q(['/test'])); var params = { config: { @@ -220,7 +220,7 @@ describe('tests-reader', function() { }); it('should not assign unknown input browsers to test files', function() { - pathUtils.expandPaths.withArgs(['test']).returns(q(['/test'])); + globExtra.expandPaths.withArgs(['test']).returns(q(['/test'])); var params = { config: { @@ -248,7 +248,7 @@ describe('tests-reader', function() { }); it('should filter test files from specs in case of input test paths', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['test1']).returns(q(['/test1'])) .withArgs(['test2']).returns(q(['/test2'])); @@ -264,7 +264,7 @@ describe('tests-reader', function() { }); it('should not assign browsers to unknown input test paths', function() { - pathUtils.expandPaths + globExtra.expandPaths .withArgs(['test']).returns(q(['/test'])) .withArgs(['unknown-test']).returns(q(['/unknown-test']));