080d5e58c3eafa6ade8f9da1676d1bd026a46091
[platform/framework/web/crosswalk-tizen.git] /
1 //jshint node:true
2 /*global describe, it*/
3 "use strict";
4
5 var expect = require('chai').expect;
6 var esformatter = require('../lib/esformatter');
7
8
9 describe('API', function() {
10
11   describe('exposed API', function() {
12     // plugins might need to access some internal methods from esformatter
13     // so we check if these methods are really available
14     var limit = require('../lib/limit');
15     var options = require('../lib/options');
16
17     it('shoud expose useful methods to plugin authors', function() {
18       // we don't need to check implementation here since these methods are
19       // used internally
20       expect(limit.before).to.be.a('function');
21       expect(limit.after).to.be.a('function');
22       expect(limit.around).to.be.a('function');
23       expect(options.set).to.be.a('function');
24       expect(options.get).to.be.a('function');
25       expect(options.getRc).to.be.a('function');
26       expect(options.loadAndParseConfig).to.be.a('function');
27       expect(esformatter.rc).to.be.a('function');
28     });
29   });
30
31   describe('esformatter.rc', function() {
32     // PS: CLI is already testing this method indirectly, we are only checking
33     // for edge cases for now
34
35     it('should return custom options if root == true', function() {
36       expect(
37         esformatter.rc(null, {root:true})
38       ).to.be.eql({root:true});
39     });
40
41     it('should return custom options if preset', function() {
42       expect(
43         esformatter.rc(null, {preset:'default'})
44       ).to.be.eql({preset:'default'});
45     });
46
47     it('should merge the custom option', function() {
48       var customOpts = {
49         whiteSpace: {
50           before: {
51             "ArrayExpressionClosing" : 1
52           },
53           after: {
54             "ArrayExpressionOpening" : 1
55           }
56         }
57       };
58       var result = esformatter.rc('test/compare/rc/top-in.js', customOpts);
59       expect(result.whiteSpace.before.FunctionDeclarationOpeningBrace).to.be.eql(0);
60       expect(result.whiteSpace.before.ArrayExpressionClosing).to.be.eql(1);
61       expect(result.whiteSpace.after.ArrayExpressionOpening).to.be.eql(1);
62     });
63
64     it('should merge rcs from parent folder', function() {
65       var result = esformatter.rc('test/compare/rc/nested/nested-in.js');
66       expect(result.indent.value).to.be.eql('\t');
67       expect(result.whiteSpace.before.FunctionDeclarationOpeningBrace).to.be.eql(0);
68     });
69
70     it('should merge .esformatter and package.json files', function() {
71       var result = esformatter.rc('test/compare/rc/package/nested/pkg_nested-in.js');
72       expect(result.indent.value).to.be.eql('\t');
73       expect(result.lineBreak.before.FunctionDeclarationOpeningBrace).to.be.eql(1);
74       expect(result.lineBreak.before.FunctionDeclarationClosingBrace).to.be.eql(0);
75     });
76   });
77 });