Skip to content

Commit 82a37a4

Browse files
mlenkeitSBoudrias
authored andcommitted
Fix main generator detection pattern (#447)
* add helper to create fake read-pkg-up module * cover Router#updateAvailableGenerators with tests * ignore sub-generators that contain 'app' * inline fake read-pkg-up module * Revert "add helper to create fake read-pkg-up module" This reverts commit a6f7ff7.
1 parent cc4493a commit 82a37a4

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

lib/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Router.prototype.updateAvailableGenerators = function () {
5757

5858
var resolveGenerators = function (generator) {
5959
// Skip sub generators
60-
if (!/(app|all)$/.test(generator.namespace)) {
60+
if (!/:(app|all)$/.test(generator.namespace)) {
6161
return;
6262
}
6363

test/router.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,31 @@
22
var assert = require('assert');
33
var _ = require('lodash');
44
var sinon = require('sinon');
5-
var Router = require('../lib/router');
5+
var helpers = require('./helpers');
6+
var proxyquire = require('proxyquire');
7+
var path = require('path');
8+
var Router = proxyquire('../lib/router', {
9+
'read-pkg-up': {
10+
sync: function (options) {
11+
// turn /phoenix/app into phoenix-app
12+
var name = options.cwd.split(path.sep).filter(function (chunk) {
13+
return !!chunk;
14+
}).join('-');
15+
return {
16+
pkg: {
17+
name: name,
18+
version: '0.1.0'
19+
}
20+
};
21+
}
22+
}
23+
});
624

725
describe('Router', function () {
826
beforeEach(function () {
9-
this.router = new Router(sinon.stub());
27+
this.env = helpers.fakeEnv();
28+
this.env.getGeneratorsMeta = sinon.stub();
29+
this.router = new Router(this.env);
1030
});
1131

1232
describe('#registerRoute()', function () {
@@ -37,4 +57,43 @@ describe('Router', function () {
3757
assert.throws(this.router.navigate.bind(this.route, 'invalid route name'));
3858
});
3959
});
60+
61+
describe('#updateAvailableGenerators()', function () {
62+
beforeEach(function () {
63+
this.env.getGeneratorsMeta.returns([
64+
{
65+
namespace: 'xanadu:all',
66+
resolved: '/xanadu/all/index.js'
67+
},
68+
{
69+
namespace: 'phoenix:app',
70+
resolved: '/phoenix/app/index.js'
71+
},
72+
{
73+
namespace: 'phoenix:misc',
74+
resolved: '/phoenix/misc/index.js'
75+
},
76+
{
77+
namespace: 'phoenix:sub-app',
78+
resolved: '/phoenix/sub-app/index.js'
79+
}
80+
]);
81+
});
82+
83+
it('finds generators where an `all` generator is implemented', function () {
84+
this.router.updateAvailableGenerators();
85+
assert.ok(this.router.generators['xanadu-all'], 'xanadu:all found');
86+
});
87+
88+
it('finds generators where an `app` generator is implemented', function () {
89+
this.router.updateAvailableGenerators();
90+
assert.ok(this.router.generators['phoenix-app'], 'phoenix:app found');
91+
});
92+
93+
it('ignores sub-generators', function () {
94+
this.router.updateAvailableGenerators();
95+
assert.ok(!this.router.generators['phoenix-misc'], 'phoenix:misc ignored');
96+
assert.ok(!this.router.generators['phoenix-sub-app'], 'phoenix:sub-app ignored');
97+
});
98+
});
4099
});

0 commit comments

Comments
 (0)