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

Commit

Permalink
resolve files specified to use
Browse files Browse the repository at this point in the history
  • Loading branch information
rostik404 committed Dec 26, 2016
1 parent 23126c5 commit c00b17b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/sets-builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ module.exports = class SetsBuilder {
}

build(projectRoot, globOpts) {
const expandOpts = _.extend(EXPAND_OPTS, {root: projectRoot});
globOpts = globOpts || {};

return this._transformDirsToMasks()
.then(() => globExtra.expandPaths(this._filesToUse, EXPAND_OPTS, globOpts))
.then(() => this._resolvePaths(projectRoot))
.then(() => globExtra.expandPaths(this._filesToUse, expandOpts, globOpts))
.then((expandedFiles) => this._useFiles(expandedFiles))
.then(() => this._expandFiles(_.extend(EXPAND_OPTS, {root: projectRoot}), globOpts))
.then(() => this._expandFiles(expandOpts, globOpts))
.then(() => SetCollection.create(this._sets));
}

Expand All @@ -80,6 +82,10 @@ module.exports = class SetsBuilder {
return _.values(this._sets);
}

_resolvePaths(projectRoot) {
_.forEach(this._sets, (set) => set.resolveFiles(projectRoot));
}

_useFiles(filesToUse) {
_.forEach(this._sets, (set) => set.useFiles(filesToUse));

Expand Down
4 changes: 4 additions & 0 deletions lib/sets-builder/test-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module.exports = class TestSet {
.then((files) => this._set.files = files);
}

resolveFiles(projectRoot) {
this._set.files = this._set.files.map((file) => path.resolve(projectRoot, file));
}

getFiles() {
return this._set.files;
}
Expand Down
10 changes: 10 additions & 0 deletions test/sets-builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('sets-builder', () => {
beforeEach(() => {
sandbox.stub(SetCollection, 'create').returns(Promise.resolve());
sandbox.stub(globExtra, 'expandPaths').returns(Promise.resolve([]));
sandbox.stub(TestSet.prototype, 'resolveFiles');
sandbox.stub(fs, 'stat').yields(null, {isDirectory: () => false});
});

Expand Down Expand Up @@ -80,6 +81,15 @@ describe('sets-builder', () => {
assert.deepEqual(result, setCollection);
});
});

it('should resolve files by project root for each set', () => {
return createSetBuilder({default: {files: ['some/path']}})
.build('project/root')
.then(() => {
assert.calledOnce(TestSet.prototype.resolveFiles);
assert.calledWith(TestSet.prototype.resolveFiles, 'project/root');
});
});
});

describe('useSets', () => {
Expand Down
7 changes: 7 additions & 0 deletions test/sets-builder/test-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('TestSet', () => {
assert.deepEqual(set.getBrowsers(), ['bro1', 'bro2']);
});

it('should resolve set files using project root', () => {
const set = TestSet.create({files: ['some/path/file.js']});

set.resolveFiles('/project/root');
assert.deepEqual(set.getFiles(), ['/project/root/some/path/file.js']);
});

describe('getBrowsersForFile', () => {
it('should return all browsers for file', () => {
const set = TestSet.create({
Expand Down

0 comments on commit c00b17b

Please sign in to comment.