|
2 | 2 | var assert = require('assert'); |
3 | 3 | var _ = require('lodash'); |
4 | 4 | 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 | +}); |
6 | 24 |
|
7 | 25 | describe('Router', function () { |
8 | 26 | 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); |
10 | 30 | }); |
11 | 31 |
|
12 | 32 | describe('#registerRoute()', function () { |
@@ -37,4 +57,43 @@ describe('Router', function () { |
37 | 57 | assert.throws(this.router.navigate.bind(this.route, 'invalid route name')); |
38 | 58 | }); |
39 | 59 | }); |
| 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 | + }); |
40 | 99 | }); |
0 commit comments