1 | path = require 'path'
|
2 | should = require 'should'
|
3 | _ = require 'lodash'
|
4 | logger = require 'torch'
|
5 |
|
6 | core = require '../lib/core'
|
7 |
|
8 | proj1Dir = path.join __dirname, '../sample/project1'
|
9 |
|
10 | describe 'core.init', ->
|
11 | before ->
|
12 | @retriever =
|
13 | projectRoot: proj1Dir
|
14 |
|
15 | afterEach ->
|
16 | core.reset()
|
17 |
|
18 | it 'should load axiom-base', (done) ->
|
19 | core.init {}, @retriever
|
20 |
|
21 | core.request 'base.runtime', {}, (err, result) ->
|
22 | should.not.exist err
|
23 | should.exist result
|
24 | result.should.eql {message: 'axiom-base'}
|
25 | done()
|
26 |
|
27 | it 'should dynamically load a module based on name', (done) ->
|
28 | data = {greeting: 'hello!'}
|
29 | config =
|
30 | modules: ['sample']
|
31 | core.init config, @retriever
|
32 |
|
33 | core.request 'sample.echo', data, (err, result) ->
|
34 | should.not.exist err
|
35 | should.exist result
|
36 | result.should.eql data
|
37 | done()
|
38 |
|
39 | it 'should not init a module that is blacklisted', (done) ->
|
40 | config =
|
41 | blacklist: ['sample']
|
42 | modules: ['sample']
|
43 | core.init config, @retriever
|
44 |
|
45 | core.request 'sample.echo', {greeting: 'hello!'}, (err, result) ->
|
46 | should.exist err
|
47 | err.message.should.eql "No responders for request: 'sample.echo'"
|
48 |
|
49 | should.not.exist result
|
50 |
|
51 | done()
|
52 |
|
53 | it "should load a global 'axiom' file from the project root", (done) ->
|
54 | internal = require '../lib/core/internal'
|
55 | axiomFile = require path.join(proj1Dir, 'axiom')
|
56 | should.exist axiomFile
|
57 | core.init {}, @retriever
|
58 | internal.config.should.include axiomFile
|
59 | done()
|
60 |
|
61 | it "should assume an 'axiom_configs' folder containing config overrides", (done) ->
|
62 | core.init {modules: ['sample']}, @retriever
|
63 |
|
64 | sampleExtension = require path.join(proj1Dir, 'node_modules/axiom-sample')
|
65 |
|
66 |
|
67 | defaultSampleConfig = sampleExtension.config.whatsMyContext
|
68 | should.exist defaultSampleConfig
|
69 |
|
70 |
|
71 | overrideConfigPath = path.join proj1Dir, 'axiom_configs/sample'
|
72 | overrideConfig = require(overrideConfigPath).whatsMyContext
|
73 | should.exist overrideConfig
|
74 |
|
75 | expectedConfig = _.merge {}, defaultSampleConfig, overrideConfig
|
76 |
|
77 |
|
78 | core.request 'sample.whatsMyContext', {}, (err, config) ->
|
79 | should.not.exist err
|
80 |
|
81 |
|
82 | should.exist config
|
83 | config.should.eql expectedConfig
|
84 |
|
85 | done()
|
86 |
|
87 | it "should expose an injected 'retriever' in 'util'", (done) ->
|
88 | defaultRetriever = @retriever
|
89 |
|
90 |
|
91 | mockRetriever =
|
92 | retrieve: (name...) -> {}
|
93 | retrieveExtension: (name...) -> {}
|
94 |
|
95 |
|
96 | server =
|
97 | services:
|
98 | "run/prepare": (args, fin) ->
|
99 | should.exist @util
|
100 |
|
101 |
|
102 | @util.should.include mockRetriever
|
103 |
|
104 |
|
105 | @util.should.not.include defaultRetriever
|
106 |
|
107 | fin()
|
108 |
|
109 |
|
110 | core.init {}, mockRetriever
|
111 |
|
112 |
|
113 | core.load "server", server
|
114 |
|
115 |
|
116 | core.request "server.run/prepare", {}, (err, result) ->
|
117 |
|
118 |
|
119 | should.not.exist err
|
120 | done()
|
121 |
|
122 | it "should load an appExtension", (done) ->
|
123 | config =
|
124 | appExtensions:
|
125 | doStuff: 'appExtensions/doStuff'
|
126 |
|
127 | core.init config, @retriever
|
128 | core.request 'doStuff.doStuff', {}, (err, result) ->
|
129 | result.should.eql {status: 'stuff is done'}
|
130 | done()
|