From c688dca0300bacefac0e16c3655ed3611c304fee Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:43:56 +0200 Subject: [PATCH] Added unit tests for findExternalSubgens() #11 --- test/_helpers/index.js | 19 ++++++++++--------- test/utils/utilsTest.js | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/test/_helpers/index.js b/test/_helpers/index.js index 81cfb80..7a05ce7 100644 --- a/test/_helpers/index.js +++ b/test/_helpers/index.js @@ -42,6 +42,9 @@ function moveDefaultFiles(dir, includeSubgenextJson = false, includeExtgen = fal } +const buildPkgJson = (name='', version='1.0.0') => { return {name, version} }; + + const mockedDirsForSearchPaths = { structure: { '/tmp/searchPath1': { @@ -49,21 +52,19 @@ const mockedDirsForSearchPaths = { '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': {} }, diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index cee87fa..d98bf78 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -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); }); @@ -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(); + }); + }); });