Skip to content

Commit

Permalink
Write tests on 'tests-reader'
Browse files Browse the repository at this point in the history
  • Loading branch information
eGavr committed Mar 25, 2016
1 parent 9b654ee commit a40043d
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 0 deletions.
215 changes: 215 additions & 0 deletions test/lib/tests-reader.js
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), {});
});
});
2 changes: 2 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ function browserWithId(id) {

function makeConfigStub(opts) {
opts = _.defaults(opts || {}, {
specs: [],
browsers: ['some-default-browser'],
retry: 0
});

var config = {
specs: opts.specs,
browsers: {},
reporters: [],
plugins: opts.plugins
Expand Down

0 comments on commit a40043d

Please sign in to comment.