Skip to content

Commit

Permalink
Added first unit tests #11
Browse files Browse the repository at this point in the history
  • Loading branch information
sthzg committed Jul 7, 2016
1 parent 44decc0 commit f591388
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"fs-extra": "^0.30.0",
"generator-yoburger": "0.0.3",
"mocha": "^2.5.3",
"mock-fs": "^3.9.0",
"yeoman-assert": "^2.2.1",
"yeoman-test": "^1.4.0"
},
Expand Down
29 changes: 29 additions & 0 deletions test/_helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,38 @@ function moveDefaultFiles(dir, includeSubgenextJson = false, includeExtgen = fal
}


const mockedDirsForSearchPaths = {
structure: {
'/tmp/searchPath1': {
'sp1dir1': {
'foo': {},
'bar': {}
},
'sp1dir2': {},
'sp1dir3': {}
},
'/tmp/searchPath2': {
'sp2dir1': {
'dir21': {},
'dir22': {}
},
'sp2dir2': {},
'sp2dir3': {}
},
'/tmp/searchPath3': {}
},
roots: [
'/tmp/searchPath1',
'/tmp/searchPath2',
'/tmp/searchPath3'
]
};


module.exports = {
genPath,
nodeModDir,
resourcesDir,
mockedDirsForSearchPaths,
moveDefaultFiles
};
53 changes: 53 additions & 0 deletions test/utils/utilsTest.js
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
'use strict';

const after = require('mocha').after;
const before = require('mocha').before;
const describe = require('mocha').describe;
const it = require('mocha').it;

const chai = require('chai').assert;
const fs = require('fs');
const mockfs = require('mock-fs');
const path = require('path');
const tHelpers = require('../_helpers');
const utils = require('../../utils/utils');


describe('getInstalledPkgPaths()', () => {
describe('getInstalledPkgPaths()', function () {
before(function() {
mockfs(tHelpers.mockedDirsForSearchPaths.structure);
});

it('returns expected number of directories from the fs', function () {
const res = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots);
chai.isOk(res.length === 6, 'Expected number of dirs to be 6')
});

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


describe('populatePkgStoreFromPaths()', () => {
describe('populatePkgStoreFromPaths()', function () {
before(function() {
mockfs(tHelpers.mockedDirsForSearchPaths.structure);
this.pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots);
});

it('returns expected number of directories from the fs', function () {
const res = utils.populatePkgStoreFromPaths(this.pkgPaths);
chai.isOk(res.length === 6, 'Expected number of entries to be 6');
chai.isOk(
res.every(x => typeof x.path === 'string' && x.path !== ''),
'Expected all items to have a non-empty path prop '
);
});

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

0 comments on commit f591388

Please sign in to comment.