Skip to content

Commit

Permalink
Added unit tests for findExternalSubgens() #11
Browse files Browse the repository at this point in the history
  • Loading branch information
sthzg committed Jul 8, 2016
1 parent 2c257b2 commit 15b93cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
19 changes: 10 additions & 9 deletions test/_helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,29 @@ function moveDefaultFiles(dir, includeSubgenextJson = false, includeExtgen = fal
}


const buildPkgJson = (name='', version='1.0.0') => { return {name, version} };


const mockedDirsForSearchPaths = {
structure: {
'/tmp/searchPath1': {
'sp1dir1': {
'generators': {
'hello': {}
},
'package.json': JSON.stringify({
name: 'sp1dir1pkg',
version: '1.0.0'
})
'package.json': JSON.stringify(buildPkgJson('sp1dir1', '1.0.0'))
},
'sp1dir2': {},
'sp1dir3': {}
},
'/tmp/searchPath2': {
'sp2dir1': {
'dir21': {},
'dir22': {}
'contrib-subgen-sp1dir-hello': {
'package.json': JSON.stringify(buildPkgJson('hello'))
},
'contrib-subgen-sp1dir-bye': {
'package.json': JSON.stringify(buildPkgJson('bye'))
},
'sp2dir2': {},
'sp2dir3': {}
'sp2dir3': {},
},
'/tmp/searchPath3': {}
},
Expand Down
24 changes: 20 additions & 4 deletions test/utils/utilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ describe('getPkgInfo()', () => {
const pkgQ = utils.getPkgInfo('sp1dir1', this.store);
chai.equal(pkgQ.hasError, false);
chai.equal(pkgQ.pkg.version, '1.0.0');
chai.equal(pkgQ.pkg.name, 'sp1dir1pkg');
chai.equal(pkgQ.pkg.name, 'sp1dir1');
chai.equal(pkgQ.pkg.path, '/tmp/searchPath1/sp1dir1');
});

it('returns data for a matching substring with exact=fasle', function () {
const pkgQ = utils.getPkgInfo('sp1', this.store, false);
chai.equal(pkgQ.pkg.name, 'sp1dir1pkg');
chai.equal(pkgQ.pkg.name, 'sp1dir1');
});

it(`returns an error if pkg can't be found`, function () {
it('returns an error if pkg can\'t be found', function () {
const pkgQ = utils.getPkgInfo('xyz', this.store);
chai.equal(pkgQ.hasError, true);
});
Expand Down Expand Up @@ -142,6 +142,22 @@ describe('checkActivationState()', () => {
});


// TODO
describe('findExternalSubgens()', () => {
describe('with mocked file system', function () {
before(function () {
this.prefixes = require('../../utils/constants').SUBGEN_PREFIX_PATTERNS;
mockfs(tHelpers.mockedDirsForSearchPaths.structure);
const pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots);
this.store = utils.populatePkgStoreFromPaths(pkgPaths);
});

it('finds packages that qualify as external subgens', function () {
const res = utils.findExternalSubgens(this.prefixes, 'sp1dir', this.store).results;
chai.ok(res.length, 2);
});

after(function () {
mockfs.restore();
});
});
});

0 comments on commit 15b93cd

Please sign in to comment.