From f5913887992dd2d72ce5e4c0e55f420eb4318122 Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 21:31:22 +0200 Subject: [PATCH 01/23] Added first unit tests #11 --- package.json | 1 + test/_helpers/index.js | 29 ++++++++++++++++++++++ test/utils/utilsTest.js | 53 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/package.json b/package.json index 4f22fcc..aa695de 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/_helpers/index.js b/test/_helpers/index.js index cf22cba..1706dfe 100644 --- a/test/_helpers/index.js +++ b/test/_helpers/index.js @@ -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 }; diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index ad9a93a..d6bf017 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -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(); + }); + }); +}); From bbd8ba0d72d4027d8e9d6c53a50cc91288739cae Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 22:40:13 +0200 Subject: [PATCH 02/23] Added more unit tests for utils.js #11 --- test/_helpers/index.js | 6 +++++- test/utils/utilsTest.js | 23 +++++++++++++++++++++++ utils/utils.js | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/test/_helpers/index.js b/test/_helpers/index.js index 1706dfe..092b027 100644 --- a/test/_helpers/index.js +++ b/test/_helpers/index.js @@ -47,7 +47,11 @@ const mockedDirsForSearchPaths = { '/tmp/searchPath1': { 'sp1dir1': { 'foo': {}, - 'bar': {} + 'bar': {}, + 'package.json': JSON.stringify({ + name: 'sp1dir1pkg', + version: '1.0.0' + }) }, 'sp1dir2': {}, 'sp1dir3': {} diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index d6bf017..47ee470 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -52,3 +52,26 @@ describe('populatePkgStoreFromPaths()', () => { }); }); }); + + +describe('getPkgInfo()', () => { + describe('getPkgInfo()', function () { + before(function () { + mockfs(tHelpers.mockedDirsForSearchPaths.structure); + const pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); + this.store = utils.populatePkgStoreFromPaths(pkgPaths); + }); + + it('returns data from package.json', function () { + const pkg = utils.getPkgInfo('sp1dir1', this.store); + chai.equal(pkg.hasError, false); + chai.equal(pkg.pkg.version, '1.0.0'); + chai.equal(pkg.pkg.name, 'sp1dir1pkg'); + chai.equal(pkg.pkg.path, '/tmp/searchPath1/sp1dir1'); + }); + + after(function () { + mockfs.restore(); + }); + }); +}); diff --git a/utils/utils.js b/utils/utils.js index bc4ea81..a55945a 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,5 +1,6 @@ 'use strict'; +var readFileSync = require('fs').readFileSync; var existsSync = require('fs').existsSync; var globby = require('globby'); var path = require('path'); @@ -203,7 +204,7 @@ function findExternalSubgens(prefixes, host, installed) { * @returns {*} */ function loadPkgJsonFromPkgPath(dir) { - return require(path.join(dir, 'package.json')); + return JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8')); } From 5922cad51108268dd6f41233a24d55154817c1f9 Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 23:15:29 +0200 Subject: [PATCH 03/23] Added more unit tests for getPkgInfo #11 Fixed bug for returning an error along the way --- test/utils/utilsTest.js | 20 +++++++++++++++----- utils/utils.js | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 47ee470..0ef9bfe 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -63,11 +63,21 @@ describe('getPkgInfo()', () => { }); it('returns data from package.json', function () { - const pkg = utils.getPkgInfo('sp1dir1', this.store); - chai.equal(pkg.hasError, false); - chai.equal(pkg.pkg.version, '1.0.0'); - chai.equal(pkg.pkg.name, 'sp1dir1pkg'); - chai.equal(pkg.pkg.path, '/tmp/searchPath1/sp1dir1'); + 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.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'); + }); + + it(`returns an error if pkg can't be found`, function () { + const pkgQ = utils.getPkgInfo('xyz', this.store); + chai.equal(pkgQ.hasError, true); }); after(function () { diff --git a/utils/utils.js b/utils/utils.js index a55945a..bc3e7e5 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -108,7 +108,7 @@ function getPkgInfo(pkgName, installed, exact=true) { return buildSuccess({ pkg: pkg }); } else { - buildError(`${pkgName} not found in installed packages.`); + return buildError(`${pkgName} not found in installed packages.`); } } From 3349062c7cd21bd16ec1872d78672ade98d29ece Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 23:30:32 +0200 Subject: [PATCH 04/23] Connected to Coveralls #11 --- .travis.yml | 2 ++ package.json | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 318df40..543d0a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ language: node_js node_js: - "6.2" +after_success: + - coveralls diff --git a/package.json b/package.json index aa695de..9223a75 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,11 @@ "devDependencies": { "chai": "^3.5.0", "contrib-subgen-yoburger-bbq": "0.0.2", + "coveralls": "^2.11.9", "fs-extra": "^0.30.0", "generator-yoburger": "0.0.3", "mocha": "^2.5.3", + "mocha-lcov-reporter": "^1.2.0", "mock-fs": "^3.9.0", "yeoman-assert": "^2.2.1", "yeoman-test": "^1.4.0" From bc5d537a68e356564dff116631882286e9d212b6 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 00:19:53 +0200 Subject: [PATCH 05/23] Added istanbul and updated travis.yml #11 --- .travis.yml | 1 + package.json | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 543d0a2..95c916a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: - "6.2" +script: npm run-script test:travis after_success: - coveralls diff --git a/package.json b/package.json index 9223a75..d313db4 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "coveralls": "^2.11.9", "fs-extra": "^0.30.0", "generator-yoburger": "0.0.3", + "istanbul": "^0.4.4", "mocha": "^2.5.3", "mocha-lcov-reporter": "^1.2.0", "mock-fs": "^3.9.0", @@ -42,6 +43,8 @@ "scripts": { "test": "mocha", "test:watch": "mocha -w", + "test:coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly && rm -rf ./coverage", + "test:travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", "release:major": "npm version prerelease && git push --follow-tags && npm publish --tag poc", "release:minor": "npm version prerelease && git push --follow-tags && npm publish --tag poc", "release:patch": "npm version prerelease && git push --follow-tags && npm publish --tag poc" From 65d0684a35b7b6a5ac189242c7c626aea720b5e4 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 00:37:11 +0200 Subject: [PATCH 06/23] Removed unnecessary travis config #11 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95c916a..5923031 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,3 @@ language: node_js node_js: - "6.2" script: npm run-script test:travis -after_success: - - coveralls From 9d9dbb07d07dc423dd2f3231334b947fd40b03d6 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:03:20 +0200 Subject: [PATCH 07/23] Added first unit tests for getSubgenBaseName() #11 --- test/utils/utilsTest.js | 15 ++++++++++++++- utils/utils.js | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 0ef9bfe..8ff2a12 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -43,7 +43,7 @@ describe('populatePkgStoreFromPaths()', () => { 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 ' + 'Expected all items to have a non-empty path prop' ); }); @@ -85,3 +85,16 @@ describe('getPkgInfo()', () => { }); }); }); + + +describe('getSubgenBaseName()', () => { + it('returns expected basename for contrib-subgen-foobar-helloworld', function () { + let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'contrib-subgen-foobar-helloworld'); + chai.equal(bn, 'helloworld'); + }); + + it('returns expected basename for subgen-foobar-helloworld', function () { + let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'subgen-foobar-helloworld'); + chai.equal(bn, 'helloworld'); + }); +}); diff --git a/utils/utils.js b/utils/utils.js index bc3e7e5..119654f 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -132,6 +132,7 @@ function buildPrefixRegexps(patterns, host) { * @returns {string|void|XML|*} */ function getSubgenBaseName(host, patterns, pkgName) { + // TODO gh_issue 13, return Success or Error record const sorted = sortCharArrByLength(patterns); const regexps = buildPrefixRegexps(sorted, host); const prefix = regexps.find(regex => regex.exec(pkgName) !== null); @@ -227,6 +228,7 @@ module.exports = { checkPkgExists, getPkgInfo, getInstalledPkgPaths, + getSubgenBaseName, findExternalSubgens, populatePkgStoreFromPaths }; From 55c806fb7226b1664e4818a8f3dd1953a2cc0b85 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:12:51 +0200 Subject: [PATCH 08/23] Added unit tests for buildPrefixRegexps() #11 --- test/utils/utilsTest.js | 25 +++++++++++++++++++++++++ utils/utils.js | 1 + 2 files changed, 26 insertions(+) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 8ff2a12..1f4d902 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -87,6 +87,21 @@ describe('getPkgInfo()', () => { }); +describe('buildPrefixRegexps()', () => { + it('returns expected regexps', function () { + let regexps = utils.buildPrefixRegexps(['contrib-subgen-', 'subgen-'], 'foobar'); + chai.equal(regexps.length, 2); + chai.equal(regexps[0], '/^contrib-subgen-foobar-/'); + chai.equal(regexps[1], '/^subgen-foobar-/'); + }); + + it('returns expected basename for subgen-foobar-helloworld', function () { + let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'subgen-foobar-helloworld'); + chai.equal(bn, 'helloworld'); + }); +}); + + describe('getSubgenBaseName()', () => { it('returns expected basename for contrib-subgen-foobar-helloworld', function () { let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'contrib-subgen-foobar-helloworld'); @@ -98,3 +113,13 @@ describe('getSubgenBaseName()', () => { chai.equal(bn, 'helloworld'); }); }); + + +// TODO +describe('checkActivationState()', () => { +}); + + +// TODO +describe('findExternalSubgens()', () => { +}); diff --git a/utils/utils.js b/utils/utils.js index 119654f..f05304b 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -224,6 +224,7 @@ function sortCharArrByLength(arr, desc=true) { module.exports = { + buildPrefixRegexps, checkActivationState, checkPkgExists, getPkgInfo, From 2c257b2e106f677859ae2b1725703ff15f5a6b88 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:30:28 +0200 Subject: [PATCH 09/23] Added unit tests for checkActivationState() #11 --- test/_helpers/index.js | 5 +++-- test/utils/utilsTest.js | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/test/_helpers/index.js b/test/_helpers/index.js index 092b027..81cfb80 100644 --- a/test/_helpers/index.js +++ b/test/_helpers/index.js @@ -46,8 +46,9 @@ const mockedDirsForSearchPaths = { structure: { '/tmp/searchPath1': { 'sp1dir1': { - 'foo': {}, - 'bar': {}, + 'generators': { + 'hello': {} + }, 'package.json': JSON.stringify({ name: 'sp1dir1pkg', version: '1.0.0' diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 1f4d902..cee87fa 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -115,8 +115,30 @@ describe('getSubgenBaseName()', () => { }); -// TODO describe('checkActivationState()', () => { + describe('with mocked file system', function () { + before(function () { + mockfs(tHelpers.mockedDirsForSearchPaths.structure); + const pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); + this.store = utils.populatePkgStoreFromPaths(pkgPaths); + }); + + it('reports activated subgen', function () { + const hostPkg = utils.getPkgInfo('sp1dir1', this.store).pkg; + const res = utils.checkActivationState(hostPkg, 'hello'); + chai.ok(res.result); + }); + + it('reports deactiaved', function () { + const hostPkg = utils.getPkgInfo('sp1dir1', this.store).pkg; + const res = utils.checkActivationState(hostPkg, 'nonExistent'); + chai.notOk(res.result); + }); + + after(function () { + mockfs.restore(); + }); + }); }); From 15b93cd330f02947cb80aa663f36d79b8fd451d1 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:43:56 +0200 Subject: [PATCH 10/23] 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(); + }); + }); }); From d0e0a0e8d054fbbf01998d4c3fe9c60b426054cc Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:45:21 +0200 Subject: [PATCH 11/23] Unified outer describe msg on mock-fs-based tests #11 --- test/utils/utilsTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index d98bf78..f8704a3 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -14,7 +14,7 @@ const utils = require('../../utils/utils'); describe('getInstalledPkgPaths()', () => { - describe('getInstalledPkgPaths()', function () { + describe('with mocked file system', function () { before(function() { mockfs(tHelpers.mockedDirsForSearchPaths.structure); }); @@ -32,7 +32,7 @@ describe('getInstalledPkgPaths()', () => { describe('populatePkgStoreFromPaths()', () => { - describe('populatePkgStoreFromPaths()', function () { + describe('with mocked file system', function () { before(function() { mockfs(tHelpers.mockedDirsForSearchPaths.structure); this.pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); @@ -55,7 +55,7 @@ describe('populatePkgStoreFromPaths()', () => { describe('getPkgInfo()', () => { - describe('getPkgInfo()', function () { + describe('with mocked file system', function () { before(function () { mockfs(tHelpers.mockedDirsForSearchPaths.structure); const pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); From 1aecea63a0e6d1bf988687dcd89272d8c9f592dd Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 21:31:22 +0200 Subject: [PATCH 12/23] Added first unit tests #11 --- package.json | 1 + test/_helpers/index.js | 29 ++++++++++++++++++++++ test/utils/utilsTest.js | 53 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/package.json b/package.json index 4f22fcc..aa695de 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/_helpers/index.js b/test/_helpers/index.js index cf22cba..1706dfe 100644 --- a/test/_helpers/index.js +++ b/test/_helpers/index.js @@ -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 }; diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index ad9a93a..d6bf017 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -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(); + }); + }); +}); From 7ae5dff3598ad0325a3a20e34938ee2a20a8053d Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 22:40:13 +0200 Subject: [PATCH 13/23] Added more unit tests for utils.js #11 --- test/_helpers/index.js | 6 +++++- test/utils/utilsTest.js | 23 +++++++++++++++++++++++ utils/utils.js | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/test/_helpers/index.js b/test/_helpers/index.js index 1706dfe..092b027 100644 --- a/test/_helpers/index.js +++ b/test/_helpers/index.js @@ -47,7 +47,11 @@ const mockedDirsForSearchPaths = { '/tmp/searchPath1': { 'sp1dir1': { 'foo': {}, - 'bar': {} + 'bar': {}, + 'package.json': JSON.stringify({ + name: 'sp1dir1pkg', + version: '1.0.0' + }) }, 'sp1dir2': {}, 'sp1dir3': {} diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index d6bf017..47ee470 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -52,3 +52,26 @@ describe('populatePkgStoreFromPaths()', () => { }); }); }); + + +describe('getPkgInfo()', () => { + describe('getPkgInfo()', function () { + before(function () { + mockfs(tHelpers.mockedDirsForSearchPaths.structure); + const pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); + this.store = utils.populatePkgStoreFromPaths(pkgPaths); + }); + + it('returns data from package.json', function () { + const pkg = utils.getPkgInfo('sp1dir1', this.store); + chai.equal(pkg.hasError, false); + chai.equal(pkg.pkg.version, '1.0.0'); + chai.equal(pkg.pkg.name, 'sp1dir1pkg'); + chai.equal(pkg.pkg.path, '/tmp/searchPath1/sp1dir1'); + }); + + after(function () { + mockfs.restore(); + }); + }); +}); diff --git a/utils/utils.js b/utils/utils.js index cf3e5d6..1faca21 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,5 +1,6 @@ 'use strict'; +var readFileSync = require('fs').readFileSync; var existsSync = require('fs').existsSync; var globby = require('globby'); var path = require('path'); @@ -188,7 +189,7 @@ function findExternalSubgens(prefixes, host, installed) { * @returns {*} */ function loadPkgJsonFromPkgPath(dir) { - return require(path.join(dir, 'package.json')); + return JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8')); } From c70accf88997a35bebf6052027ff0e80fbc065d7 Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 23:15:29 +0200 Subject: [PATCH 14/23] Added more unit tests for getPkgInfo #11 Fixed bug for returning an error along the way --- test/utils/utilsTest.js | 20 +++++++++++++++----- utils/utils.js | 5 +++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 47ee470..0ef9bfe 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -63,11 +63,21 @@ describe('getPkgInfo()', () => { }); it('returns data from package.json', function () { - const pkg = utils.getPkgInfo('sp1dir1', this.store); - chai.equal(pkg.hasError, false); - chai.equal(pkg.pkg.version, '1.0.0'); - chai.equal(pkg.pkg.name, 'sp1dir1pkg'); - chai.equal(pkg.pkg.path, '/tmp/searchPath1/sp1dir1'); + 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.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'); + }); + + it(`returns an error if pkg can't be found`, function () { + const pkgQ = utils.getPkgInfo('xyz', this.store); + chai.equal(pkgQ.hasError, true); }); after(function () { diff --git a/utils/utils.js b/utils/utils.js index 1faca21..03e3eac 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -88,9 +88,10 @@ function getPkgInfo(pkgName, installed, exact=true) { }); return buildSuccess({ pkg: pkg }); - } - return buildError(`${pkgName} not found in installed packages.`); + } else { + return buildError(`${pkgName} not found in installed packages.`); + } } From ebebe9e020ca66c676336b6c040e3f9c483ae5be Mon Sep 17 00:00:00 2001 From: sthzg Date: Thu, 7 Jul 2016 23:30:32 +0200 Subject: [PATCH 15/23] Connected to Coveralls #11 --- .travis.yml | 2 ++ package.json | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 318df40..543d0a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ language: node_js node_js: - "6.2" +after_success: + - coveralls diff --git a/package.json b/package.json index aa695de..9223a75 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,11 @@ "devDependencies": { "chai": "^3.5.0", "contrib-subgen-yoburger-bbq": "0.0.2", + "coveralls": "^2.11.9", "fs-extra": "^0.30.0", "generator-yoburger": "0.0.3", "mocha": "^2.5.3", + "mocha-lcov-reporter": "^1.2.0", "mock-fs": "^3.9.0", "yeoman-assert": "^2.2.1", "yeoman-test": "^1.4.0" From 8b8ad8791e14adefbbee9fb01952c0d4e70a88c6 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 00:19:53 +0200 Subject: [PATCH 16/23] Added istanbul and updated travis.yml #11 --- .travis.yml | 1 + package.json | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 543d0a2..95c916a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: - "6.2" +script: npm run-script test:travis after_success: - coveralls diff --git a/package.json b/package.json index 9223a75..d313db4 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "coveralls": "^2.11.9", "fs-extra": "^0.30.0", "generator-yoburger": "0.0.3", + "istanbul": "^0.4.4", "mocha": "^2.5.3", "mocha-lcov-reporter": "^1.2.0", "mock-fs": "^3.9.0", @@ -42,6 +43,8 @@ "scripts": { "test": "mocha", "test:watch": "mocha -w", + "test:coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly && rm -rf ./coverage", + "test:travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", "release:major": "npm version prerelease && git push --follow-tags && npm publish --tag poc", "release:minor": "npm version prerelease && git push --follow-tags && npm publish --tag poc", "release:patch": "npm version prerelease && git push --follow-tags && npm publish --tag poc" From b04bc4e4e00f2ecb3508bd905ed8b400b780bdf5 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 00:37:11 +0200 Subject: [PATCH 17/23] Removed unnecessary travis config #11 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95c916a..5923031 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,3 @@ language: node_js node_js: - "6.2" script: npm run-script test:travis -after_success: - - coveralls From eb42a495b1d981e05dc30d56f2d97b4f97963fda Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:03:20 +0200 Subject: [PATCH 18/23] Added first unit tests for getSubgenBaseName() #11 --- test/utils/utilsTest.js | 15 ++++++++++++++- utils/utils.js | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 0ef9bfe..8ff2a12 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -43,7 +43,7 @@ describe('populatePkgStoreFromPaths()', () => { 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 ' + 'Expected all items to have a non-empty path prop' ); }); @@ -85,3 +85,16 @@ describe('getPkgInfo()', () => { }); }); }); + + +describe('getSubgenBaseName()', () => { + it('returns expected basename for contrib-subgen-foobar-helloworld', function () { + let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'contrib-subgen-foobar-helloworld'); + chai.equal(bn, 'helloworld'); + }); + + it('returns expected basename for subgen-foobar-helloworld', function () { + let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'subgen-foobar-helloworld'); + chai.equal(bn, 'helloworld'); + }); +}); diff --git a/utils/utils.js b/utils/utils.js index 03e3eac..a8f3e03 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -114,6 +114,7 @@ function buildPrefixRegexps(patterns, host) { * @returns {string|void|XML|*} */ function getSubgenBaseName(host, patterns, pkgName) { + // TODO gh_issue 13, return Success or Error record const sorted = sortCharArrByLength(patterns); const regexps = buildPrefixRegexps(sorted, host); const prefix = regexps.find(regex => regex.exec(pkgName) !== null); @@ -212,6 +213,7 @@ module.exports = { checkPkgExists, getPkgInfo, getInstalledPkgPaths, + getSubgenBaseName, findExternalSubgens, populatePkgStoreFromPaths }; From 5aa139e599870bdfa43ca991f889da4edb72d5c9 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:12:51 +0200 Subject: [PATCH 19/23] Added unit tests for buildPrefixRegexps() #11 --- test/utils/utilsTest.js | 25 +++++++++++++++++++++++++ utils/utils.js | 1 + 2 files changed, 26 insertions(+) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 8ff2a12..1f4d902 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -87,6 +87,21 @@ describe('getPkgInfo()', () => { }); +describe('buildPrefixRegexps()', () => { + it('returns expected regexps', function () { + let regexps = utils.buildPrefixRegexps(['contrib-subgen-', 'subgen-'], 'foobar'); + chai.equal(regexps.length, 2); + chai.equal(regexps[0], '/^contrib-subgen-foobar-/'); + chai.equal(regexps[1], '/^subgen-foobar-/'); + }); + + it('returns expected basename for subgen-foobar-helloworld', function () { + let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'subgen-foobar-helloworld'); + chai.equal(bn, 'helloworld'); + }); +}); + + describe('getSubgenBaseName()', () => { it('returns expected basename for contrib-subgen-foobar-helloworld', function () { let bn = utils.getSubgenBaseName('foobar', ['contrib-subgen-', 'subgen-'], 'contrib-subgen-foobar-helloworld'); @@ -98,3 +113,13 @@ describe('getSubgenBaseName()', () => { chai.equal(bn, 'helloworld'); }); }); + + +// TODO +describe('checkActivationState()', () => { +}); + + +// TODO +describe('findExternalSubgens()', () => { +}); diff --git a/utils/utils.js b/utils/utils.js index a8f3e03..27bc836 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -209,6 +209,7 @@ function sortCharArrByLength(arr, desc=true) { module.exports = { + buildPrefixRegexps, checkActivationState, checkPkgExists, getPkgInfo, From 083b5f5f0ae3afd4987875cde9e1c2a0c72659e0 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:30:28 +0200 Subject: [PATCH 20/23] Added unit tests for checkActivationState() #11 --- test/_helpers/index.js | 5 +++-- test/utils/utilsTest.js | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/test/_helpers/index.js b/test/_helpers/index.js index 092b027..81cfb80 100644 --- a/test/_helpers/index.js +++ b/test/_helpers/index.js @@ -46,8 +46,9 @@ const mockedDirsForSearchPaths = { structure: { '/tmp/searchPath1': { 'sp1dir1': { - 'foo': {}, - 'bar': {}, + 'generators': { + 'hello': {} + }, 'package.json': JSON.stringify({ name: 'sp1dir1pkg', version: '1.0.0' diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index 1f4d902..cee87fa 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -115,8 +115,30 @@ describe('getSubgenBaseName()', () => { }); -// TODO describe('checkActivationState()', () => { + describe('with mocked file system', function () { + before(function () { + mockfs(tHelpers.mockedDirsForSearchPaths.structure); + const pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); + this.store = utils.populatePkgStoreFromPaths(pkgPaths); + }); + + it('reports activated subgen', function () { + const hostPkg = utils.getPkgInfo('sp1dir1', this.store).pkg; + const res = utils.checkActivationState(hostPkg, 'hello'); + chai.ok(res.result); + }); + + it('reports deactiaved', function () { + const hostPkg = utils.getPkgInfo('sp1dir1', this.store).pkg; + const res = utils.checkActivationState(hostPkg, 'nonExistent'); + chai.notOk(res.result); + }); + + after(function () { + mockfs.restore(); + }); + }); }); From c688dca0300bacefac0e16c3655ed3611c304fee Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:43:56 +0200 Subject: [PATCH 21/23] 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(); + }); + }); }); From c190dd0064a7e4bad89b808daf604a01d46776a4 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 11:45:21 +0200 Subject: [PATCH 22/23] Unified outer describe msg on mock-fs-based tests #11 --- test/utils/utilsTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index d98bf78..f8704a3 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -14,7 +14,7 @@ const utils = require('../../utils/utils'); describe('getInstalledPkgPaths()', () => { - describe('getInstalledPkgPaths()', function () { + describe('with mocked file system', function () { before(function() { mockfs(tHelpers.mockedDirsForSearchPaths.structure); }); @@ -32,7 +32,7 @@ describe('getInstalledPkgPaths()', () => { describe('populatePkgStoreFromPaths()', () => { - describe('populatePkgStoreFromPaths()', function () { + describe('with mocked file system', function () { before(function() { mockfs(tHelpers.mockedDirsForSearchPaths.structure); this.pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); @@ -55,7 +55,7 @@ describe('populatePkgStoreFromPaths()', () => { describe('getPkgInfo()', () => { - describe('getPkgInfo()', function () { + describe('with mocked file system', function () { before(function () { mockfs(tHelpers.mockedDirsForSearchPaths.structure); const pkgPaths = utils.getInstalledPkgPaths(tHelpers.mockedDirsForSearchPaths.roots); From 4871fce8808c50dabecff82fd6af6af8ace67648 Mon Sep 17 00:00:00 2001 From: sthzg Date: Fri, 8 Jul 2016 12:50:22 +0200 Subject: [PATCH 23/23] Rebased unit tests to changes in develop branch #11 --- CHANGELOG | 3 +++ test/utils/utilsTest.js | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9c2d9df..3f00409 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ 2016-07-08 +- <@sthzg> added coveralls integration +- <@sthzg> added coverage by running npm run test:covarage +- <@sthzg> added basic set of unit tests for utils.js - <@stylesuxx> added immutable Message and Package records 2016-07-07 diff --git a/test/utils/utilsTest.js b/test/utils/utilsTest.js index f8704a3..0bbc2a1 100644 --- a/test/utils/utilsTest.js +++ b/test/utils/utilsTest.js @@ -65,14 +65,14 @@ describe('getPkgInfo()', () => { it('returns data from package.json', function () { 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, 'sp1dir1'); - chai.equal(pkgQ.pkg.path, '/tmp/searchPath1/sp1dir1'); + chai.equal(pkgQ.data.getIn(['pkg', 'version']), '1.0.0'); + chai.equal(pkgQ.data.getIn(['pkg', 'name']), 'sp1dir1'); + chai.equal(pkgQ.data.getIn(['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, 'sp1dir1'); + chai.equal(pkgQ.data.getIn(['pkg', 'name']), 'sp1dir1'); }); it('returns an error if pkg can\'t be found', function () { @@ -124,15 +124,15 @@ describe('checkActivationState()', () => { }); it('reports activated subgen', function () { - const hostPkg = utils.getPkgInfo('sp1dir1', this.store).pkg; - const res = utils.checkActivationState(hostPkg, 'hello'); - chai.ok(res.result); + const hostPkgQ = utils.getPkgInfo('sp1dir1', this.store); + const resQ = utils.checkActivationState(hostPkgQ.data.get('pkg'), 'hello'); + chai.ok(resQ.data.get('result')); }); - it('reports deactiaved', function () { - const hostPkg = utils.getPkgInfo('sp1dir1', this.store).pkg; - const res = utils.checkActivationState(hostPkg, 'nonExistent'); - chai.notOk(res.result); + it('reports deactivated', function () { + const hostPkgQ = utils.getPkgInfo('sp1dir1', this.store); + const resQ = utils.checkActivationState(hostPkgQ.data.get('pkg'), 'nonExistent'); + chai.notOk(resQ.data.get('result')); }); after(function () { @@ -152,8 +152,8 @@ describe('findExternalSubgens()', () => { }); it('finds packages that qualify as external subgens', function () { - const res = utils.findExternalSubgens(this.prefixes, 'sp1dir', this.store).results; - chai.ok(res.length, 2); + const resQ = utils.findExternalSubgens(this.prefixes, 'sp1dir', this.store); + chai.equal(resQ.data.get('results').size, 2); }); after(function () {