UNPKG

1.96 kBJavaScriptView Raw
1var Config = require('../lib/config');
2
3describe('config', function() {
4 it('should fail if parsing error occurs', function() {
5 (function() {
6 Config.readConfig(__dirname + '/artifacts/invalid.json');
7 }).should.throw(/Failed to load config .*invalid.json: Line: 3 Column: 4 - Unexpected token ;/);
8 });
9
10 it('should fail if no modules are defined', function() {
11 (function() {
12 Config.create({});
13 }).should.throw(/No modules object defined/);
14 });
15
16 it('should serialize config', function() {
17 var config = Config.create({
18 application: {
19 module: 'foo',
20 name: 'Name!'
21 },
22 modules: {
23 foo: {
24 scripts: [
25 "foo",
26 {template: "bar"}
27 ]
28 }
29 }
30 });
31
32 config.serialize().should.eql({
33 application: {
34 module: 'foo',
35 name: 'Name!'
36 },
37 modules: {
38 foo: {
39 scripts: [
40 "foo",
41 {template: "bar"}
42 ]
43 }
44 },
45 packages: {
46 web: {
47 name: ''
48 }
49 }
50 });
51 });
52
53 describe('application module', function() {
54 var config = Config.create({
55 application: {
56 module: 'foo',
57 name: 'Name!'
58 },
59 modules: {}
60 });
61
62 it('should identify the app module', function() {
63 config.isAppModule('foo').should.be.true;
64 config.isAppModule({name: 'foo'}).should.be.true;
65
66 config.isAppModule('bar').should.be.false;
67 config.isAppModule({name: 'bar'}).should.be.false;
68 });
69 it('should provide the scoped module name', function() {
70 config.scopedAppModuleName('foo').should.equal('module.exports');
71 config.scopedAppModuleName({name: 'foo'}).should.equal('module.exports');
72
73 config.scopedAppModuleName('bar').should.equal('Name!');
74 config.scopedAppModuleName({name: 'bar'}).should.equal('Name!');
75 });
76 });
77});