-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
'use strict'; | ||
|
||
var pathUtils = require('../../lib/path-utils'), | ||
readTests = require('../../lib/tests-reader'), | ||
logger = require('../../lib/utils').logger, | ||
makeConfigStub = require('../utils').makeConfigStub, | ||
_ = require('lodash'), | ||
q = require('q'); | ||
|
||
describe('tests-reader', function() { | ||
var sandbox = sinon.sandbox.create(); | ||
|
||
beforeEach(function() { | ||
sandbox.stub(pathUtils, 'expandPaths'); | ||
sandbox.stub(logger, 'warn'); | ||
|
||
pathUtils.expandPaths.returns(q([])); | ||
}); | ||
|
||
afterEach(function() { | ||
sandbox.restore(); | ||
}); | ||
|
||
function readTests_(opts) { | ||
opts = _.defaultsDeep(opts || {}, { | ||
testPaths: [], | ||
browsers: [], | ||
config: {} | ||
}); | ||
|
||
return readTests(opts.testPaths, opts.browsers, makeConfigStub(opts.config)); | ||
} | ||
|
||
it('should throw in case of invalid specs declaration', function() { | ||
return assert.throws(function() { | ||
readTests_({config: {specs: [12345]}}); | ||
}, /array of strings or\/and plain objects/); | ||
}); | ||
|
||
it('should assign specified browsers to specified test files in specs', function() { | ||
pathUtils.expandPaths | ||
.withArgs(['test1']).returns(q(['/test1'])) | ||
.withArgs(['test2']).returns(q(['/test2'])); | ||
|
||
var params = { | ||
config: { | ||
specs: [ | ||
{files: ['test1'], browsers: ['browser1']}, | ||
{files: ['test2'], browsers: ['browser2']} | ||
], | ||
browsers: ['browser1', 'browser2'] | ||
} | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {browser1: ['/test1'], browser2: ['/test2']}); | ||
}); | ||
|
||
it('should support intersection of test files in specs', function() { | ||
pathUtils.expandPaths.withArgs(['test']).returns(q(['/test'])); | ||
|
||
var params = { | ||
config: { | ||
specs: [ | ||
{files: ['test'], browsers: ['browser1']}, | ||
{files: ['test'], browsers: ['browser2']} | ||
], | ||
browsers: ['browser1', 'browser2'] | ||
} | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {browser1: ['/test'], browser2: ['/test']}); | ||
}); | ||
|
||
it('should support intersection of browsers in specs', function() { | ||
pathUtils.expandPaths | ||
.withArgs(['test1']).returns(q(['/test1'])) | ||
.withArgs(['test2']).returns(q(['/test2'])); | ||
|
||
var params = { | ||
config: { | ||
specs: [ | ||
{files: ['test1'], browsers: ['browser']}, | ||
{files: ['test2'], browsers: ['browser']} | ||
], | ||
browsers: ['browser'] | ||
} | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {browser: ['/test1', '/test2']}); | ||
}); | ||
|
||
it('should assign all browsers to test files which are specified as strings in specs', function() { | ||
pathUtils.expandPaths | ||
.withArgs(['test1']).returns(q(['/test1'])) | ||
.withArgs(['test2']).returns(q(['/test2'])); | ||
|
||
var params = { | ||
config: { | ||
specs: ['test1', 'test2'], | ||
browsers: ['browser1', 'browser2'] | ||
} | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {browser1: ['/test1', '/test2'], browser2: ['/test1', '/test2']}); | ||
}); | ||
|
||
it('should assign all browsers to test files which are specified as objects without `browsers` property', function() { | ||
pathUtils.expandPaths | ||
.withArgs(['test1']).returns(q(['/test1'])) | ||
.withArgs(['test2']).returns(q(['/test2'])); | ||
|
||
var params = { | ||
config: { | ||
specs: [{files: ['test1']}, {files: ['test2']}], | ||
browsers: ['browser1', 'browser2'] | ||
} | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {browser1: ['/test1', '/test2'], browser2: ['/test1', '/test2']}); | ||
}); | ||
|
||
it('should not assign unknown browsers to test files', function() { | ||
pathUtils.expandPaths.withArgs(['test']).returns(q(['/test'])); | ||
|
||
var params = { | ||
config: { | ||
specs: [{files: ['test'], browsers: ['unknown-browser']}], | ||
browsers: ['browser'] | ||
} | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {}); | ||
}); | ||
|
||
it('should log warning in case of unknown browsers in specs', function() { | ||
return readTests_({config: {specs: [{browsers: ['unknown-browser']}], browsers: ['browser']}}) | ||
.then(function() { | ||
assert.calledWithMatch(logger.warn, /unknown-browser.+browser/); | ||
}); | ||
}); | ||
|
||
it('should filter browsers from specs in case of input browsers', function() { | ||
pathUtils.expandPaths.withArgs(['test']).returns(q(['/test'])); | ||
|
||
var params = { | ||
config: { | ||
specs: ['test'], | ||
browsers: ['browser1', 'browser2'] | ||
}, | ||
browsers: ['browser1'] | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {browser1: ['/test']}); | ||
}); | ||
|
||
it('should not assign unknown input browsers to test files', function() { | ||
pathUtils.expandPaths.withArgs(['test']).returns(q(['/test'])); | ||
|
||
var params = { | ||
config: { | ||
specs: ['test'], | ||
browsers: ['browser'] | ||
}, | ||
browsers: ['unknown-browser'] | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {}); | ||
}); | ||
|
||
it('should log warning in case of unknown input browsers', function() { | ||
var params = { | ||
config: { | ||
browsers: ['browser'] | ||
}, | ||
browsers: ['unknown-browser'] | ||
}; | ||
|
||
return readTests_(params) | ||
.then(function() { | ||
assert.calledWithMatch(logger.warn, /unknown-browser.+browser/); | ||
}); | ||
}); | ||
|
||
it('should filter test files from specs in case of input test paths', function() { | ||
pathUtils.expandPaths | ||
.withArgs(['test1']).returns(q(['/test1'])) | ||
.withArgs(['test2']).returns(q(['/test2'])); | ||
|
||
var params = { | ||
config: { | ||
specs: ['test1', 'test2'], | ||
browsers: ['browser'] | ||
}, | ||
testPaths: ['test1'] | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {browser: ['/test1']}); | ||
}); | ||
|
||
it('should not assign browsers to unknown input test paths', function() { | ||
pathUtils.expandPaths | ||
.withArgs(['test']).returns(q(['/test'])) | ||
.withArgs(['unknown-test']).returns(q(['/unknown-test'])); | ||
|
||
var params = { | ||
config: { | ||
specs: ['test'], | ||
browsers: ['browser'] | ||
}, | ||
testPaths: ['unknown-test'] | ||
}; | ||
|
||
return assert.becomes(readTests_(params), {}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters