Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
rostik404 committed Aug 29, 2016
1 parent dd391a0 commit d476b62
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 25 deletions.
9 changes: 9 additions & 0 deletions lib/test-reader/files-filter/identity-filter.js
@@ -0,0 +1,9 @@
'use strict';

const FilesFilter = require('./index');

module.exports = class IdentityFilter extends FilesFilter {
filter(filesToFilter) {
return filesToFilter;
}
};
7 changes: 7 additions & 0 deletions lib/test-reader/files-filter/index.js
@@ -0,0 +1,7 @@
'use strict';

module.exports = class FileFilter {
filter() {
throw new Error('Cannot call method of the base class');
}
};
21 changes: 21 additions & 0 deletions lib/test-reader/files-filter/intersection-filter.js
@@ -0,0 +1,21 @@
'use strict';

const _ = require('lodash');

const FilesFilter = require('./index');

module.exports = class IntersectionFilter extends FilesFilter {
constructor(files) {
super();

this._files = files;
}

filter(filesToFilter) {
if (!_.isEmpty(filesToFilter)) {
return _.intersection(filesToFilter, this._files);
}

return this._files;
}
};
9 changes: 7 additions & 2 deletions lib/test-reader/index.js
Expand Up @@ -30,9 +30,14 @@ const filesExist = (configSets, cliPaths) => {
return !_.isEmpty(configSets) || !_.isEmpty(cliPaths);
};

const getGeminiPath = (projectRoot) => {
return path.resolve(projectRoot, 'gemini');
};

module.exports = (cli, config, emitter) => {
const geminiPath = path.resolve(config.system.projectRoot, 'gemini');
const files = filesExist(config.sets, cli.paths) ? cli.paths : [geminiPath];
const files = filesExist(config.sets, cli.paths)
? cli.paths
: [getGeminiPath(config.system.projectRoot)];

return q.all([
SetCollection.create(config, cli.sets),
Expand Down
22 changes: 11 additions & 11 deletions lib/test-reader/set-collection.js
Expand Up @@ -9,10 +9,14 @@ const Set = require('./set');

module.exports = class SetCollection {
static create(config, sets) {
const filteredSets = SetCollection._filter(config.sets, sets);
let filteredSets = SetCollection._filter(config.sets, sets);

if (_.isEmpty(filteredSets)) {
filteredSets = [{files: {}, browsers: config.getBrowserIds()}];
}

return SetCollection._expand(filteredSets, config.system.projectRoot)
.then((sets) => new SetCollection(sets, config));
.then((sets) => new SetCollection(sets));
}

static _filter(sets, setsToUse) {
Expand All @@ -31,7 +35,9 @@ module.exports = class SetCollection {
if (!_.isEmpty(unknownSets)) {
let error = `No such sets: ${unknownSets.join(', ')}.`;

!_.isEmpty(sets) && (error += ` Use one of the sets, specified in config file: ${_.keys(sets).join(', ')}`);
if (!_.isEmpty(sets)) {
error += ` Use one of the sets, specified in config file: ${_.keys(sets).join(', ')}`;
}

throw new GeminiError(error);
}
Expand All @@ -47,18 +53,12 @@ module.exports = class SetCollection {
.value();
}

constructor(sets, config) {
constructor(sets) {
this._sets = _.map(sets, (set) => Set.create(set));

this._config = config;
}

useFiles(files) {
if (!_.isEmpty(this._sets)) {
this._sets.forEach((set) => set.useFiles(files));
} else {
this._sets.push(Set.create({files, browsers: this._config.getBrowserIds()}));
}
this._sets.forEach((set) => set.useFiles(files));
}

forEachFile(cb) {
Expand Down
13 changes: 10 additions & 3 deletions lib/test-reader/set.js
Expand Up @@ -2,13 +2,22 @@

const _ = require('lodash');

const IdentityFilter = require('./files-filter/identity-filter');
const IntersectionFilter = require('./files-filter/intersection-filter');

module.exports = class Set {
static create(set) {
return new Set(set);
}

constructor(set) {
this._set = set;

if (_.isEmpty(this._set.files)) {
this._filesFilter = new IdentityFilter(this._set.files);
} else {
this._filesFilter = new IntersectionFilter(this._set.files);
}
}

getFiles() {
Expand All @@ -20,8 +29,6 @@ module.exports = class Set {
}

useFiles(files) {
if (!_.isEmpty(files)) {
this._set.files = _.intersection(files, this._set.files);
}
this._set.files = this._filesFilter.filter(files);
}
};
4 changes: 2 additions & 2 deletions test/unit/test-reader/index.test.js
Expand Up @@ -105,10 +105,10 @@ describe('test-reader', () => {
getBrowserIds: () => []
};

globExtra.expandPaths.withArgs(['/root/gemini']).returns(q(['/root/gemini']));
globExtra.expandPaths.withArgs(['/root/gemini']).returns(q(['/root/gemini/file.js']));

return readTests_({config})
.then(() => assert.calledWith(utils.requireWithNoCache, '/root/gemini'));
.then(() => assert.calledWith(utils.requireWithNoCache, '/root/gemini/file.js'));
});

it('should load suites related to sets from config', () => {
Expand Down
10 changes: 3 additions & 7 deletions test/unit/test-reader/set-collection.test.js
Expand Up @@ -38,17 +38,13 @@ describe('set-collection', () => {
assert.throws(() => SetCollection.create(mkConfigStub(), ['set3'], /set3/));
});

it('should create new set with passed files and browsers form config', () => {
sandbox.stub(Set, 'create');
it('should create new set with empty files and browsers form config', () => {
sandbox.stub(Set, 'create').returns(mkSetStub());

const getBrowserIds = sandbox.stub().returns(['b1', 'b2']);

return SetCollection.create(mkConfigStub({getBrowserIds}))
.then((setCollection) => {
setCollection.useFiles(['some/files/file.js']);

assert.calledWith(Set.create, {files: ['some/files/file.js'], browsers: ['b1', 'b2']});
});
.then(() => assert.calledWith(Set.create, {files: [], browsers: ['b1', 'b2']}));
});
});

Expand Down
9 changes: 9 additions & 0 deletions test/unit/test-reader/set.test.js
Expand Up @@ -46,5 +46,14 @@ describe('Set', () => {

assert.deepEqual(files, ['some/path/file.js']);
});

it('should return passed files if set files are empty', () => {
set = new Set({files: []});
set.useFiles(['some/path/file.js']);

const files = set.getFiles();

assert.deepEqual(files, ['some/path/file.js']);
});
});
});

0 comments on commit d476b62

Please sign in to comment.