2 /*global describe, it*/
5 var expect = require('chai').expect;
6 var esformatter = require('../lib/esformatter');
9 describe('API', function() {
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');
17 it('shoud expose useful methods to plugin authors', function() {
18 // we don't need to check implementation here since these methods are
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');
31 describe('esformatter.rc', function() {
32 // PS: CLI is already testing this method indirectly, we are only checking
33 // for edge cases for now
35 it('should return custom options if root == true', function() {
37 esformatter.rc(null, {root:true})
38 ).to.be.eql({root:true});
41 it('should return custom options if preset', function() {
43 esformatter.rc(null, {preset:'default'})
44 ).to.be.eql({preset:'default'});
47 it('should merge the custom option', function() {
51 "ArrayExpressionClosing" : 1
54 "ArrayExpressionOpening" : 1
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);
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);
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);