Permalink
Browse files

added sinonjs for stubs, completed tests

  • Loading branch information...
1 parent 713c0cc commit bdb962c01975511cb1906fecc9057bf91c6b6db7 @GulinSS committed Aug 5, 2013
Showing with 98 additions and 29 deletions.
  1. +17 −18 lib/index.js
  2. +4 −2 package.json
  3. +1 −1 setup.js
  4. +6 −5 src/index.coffee
  5. +63 −1 test/JadeAngularJsCompiler.coffee
  6. +6 −2 test/common.js
  7. +1 −0 test/folder/assets/index.jade
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -23,10 +23,12 @@
"coffee-script": "1.3.3",
"jade": "~0.31.0",
"mkdirp": "*",
- "lodash": "~0.9.0"
+ "lodash": "~0.9.0"
},
"devDependencies": {
"mocha": "*",
- "chai": "*"
+ "chai": "*",
+ "sinon": "~1.7.3",
+ "sinon-chai": "~2.4.0"
}
}
View
@@ -25,5 +25,5 @@ if (mode === 'postinstall') {
} else if (mode === 'test') {
execute(['node_modules', 'coffee-script', 'bin', 'coffee'], '-o lib/ src/');
execute(['node_modules', 'mocha', 'bin', 'mocha'],
- '--require test/common.js --require coffee-script --compilers coffee:coffee-script --colors -R \'spec\'');
+ '--require test/common.js --require coffee-script --compilers coffee:coffee-script --colors -R \'spec\' --ui \'bdd\'');
}
View
@@ -105,11 +105,11 @@ module.exports = class JadeAngularJsCompiler
writer null, content
prepareResult: (compiled) ->
- pathes = (result.sourceFiles for result in compiled when result.path is @compileTrigger)[0]
+ pathes = _.find compiled, (v) => v.path is @compileTrigger
return [] if pathes is undefined
- pathes.map (e, i) =>
+ pathes.sourceFiles.map (e, i) =>
data = fs.readFileSync e.path, 'utf8'
content = jade.compile data,
compileDebug: no,
@@ -125,14 +125,15 @@ module.exports = class JadeAngularJsCompiler
onCompile: (compiled) ->
preResult = @prepareResult compiled
- assets = _.filter preResult, (v) -> v.path.indexOf('assets') is -1
+ assets = _.filter preResult, (v) -> v.path.indexOf('assets') > 0
@writeStatic assets
@writeModules _.chain(preResult)
.difference(assets)
- .each(@attachModuleNameToTemplate)
+ .each((v) => @attachModuleNameToTemplate v)
+ .each((v) -> v.path = v.path.join('/')) # concat items to virtual url
.groupBy((v) -> v.module)
.map((v, k) -> name: k, templates: v)
- .each(@generateModuleFileName)
+ .each((v) => @generateModuleFileName v)
.value()
@@ -174,6 +174,8 @@ describe "JadeAngularJsCompiler", ->
describe "Post-compile hook", ->
data = [
sourceFiles: [
+ path: "test/folder/assets/index.jade"
+ ,
path: "test/folder/index.jade"
,
path: "test/folder/partial1.jade"
@@ -187,4 +189,64 @@ describe "JadeAngularJsCompiler", ->
path: "test/folder/folder/partial2.jade"
]
path: compileTrigger
- ]
+ ]
+
+ beforeEach ->
+ sinon.stub(plugin, "writeModules")
+ sinon.stub(plugin, "writeStatic")
+
+ afterEach ->
+ plugin.writeModules.restore()
+ plugin.writeStatic.restore()
+
+ it "Anyway on test data it should call write methods for modules and assets", ->
+ plugin.onCompile data
+ plugin.writeStatic.should.have.been.calledOnce
+ plugin.writeModules.should.have.been.calledOnce
+
+ it "For assets (any paths contains \'assets\' folder) it should write them \'as is\'", ->
+ plugin.onCompile data
+
+ plugin.writeStatic.args[0].should.length 1
+ plugin.writeStatic.args[0][0].should.length 1
+ plugin.writeStatic.args[0][0][0].path.should.deep.equal ['test', 'folder', 'assets', 'index.jade']
+
+ it "For modules it should filtered and grouped them correct", ->
+ expect = [
+ name: 'test'
+ templates: [
+ path: 'test/folder/index.jade'
+ result: '<!DOCTYPE html>'
+ module: 'test'
+ ,
+ path: 'test/folder/partial1.jade'
+ result: '<!DOCTYPE html>'
+ module: 'test'
+ ,
+ path: 'test/folder/partial2.jade'
+ result: '<!DOCTYPE html>'
+ module: 'test'
+ ]
+ filename: '_public/js/test.js'
+ ,
+ name: 'test.folder',
+ templates: [
+ path: 'test/folder/folder/index.jade'
+ result: '<!DOCTYPE html>'
+ module: 'test.folder'
+ ,
+ path: 'test/folder/folder/partial1.jade'
+ result: '<!DOCTYPE html>'
+ module: 'test.folder'
+ ,
+ path: 'test/folder/folder/partial2.jade'
+ result: '<!DOCTYPE html>'
+ module: 'test.folder'
+ ],
+ filename: '_public/js/test.folder.js'
+ ]
+
+ plugin.onCompile data
+
+ plugin.writeModules.args[0].should.length 1
+ plugin.writeModules.args[0][0].should.deep.equal expect
View
@@ -1,6 +1,10 @@
+global.Plugin = require('../lib');
+global.fs = require('fs');
+global.sinon = require('sinon');
+
chai = require('chai');
+chai.use(require('sinon-chai'));
chai.should();
global.expect = chai.expect;
-global.Plugin = require('../lib');
-global.fs = require('fs');
+
@@ -0,0 +1 @@
+!!!

0 comments on commit bdb962c

Please sign in to comment.