1+ fs = require ' fs'
2+
13CommonCoffeeHandler = require ' ../../../src/handler/CommonCoffeeHandler'
24HandlerError = require ' ../../../src/handler/error/HandlerError'
35
@@ -6,8 +8,10 @@ describe 'CommonCoffeeHandler', ->
68 beforeEach ->
79 @subject = new CommonCoffeeHandler ()
810
11+ @filePath = " #{ __dirname } /../../fixture/handler/coffee.coffee"
12+ @tmpPath = " #{ __dirname } /../../fixture/tmp"
13+
914 it ' resolves to a compiled module wrapper for CoffeeScript files' , ->
10- path = " #{ __dirname } /../../fixture/handler/coffee.coffee"
1115 expected = [
1216 ' coffee'
1317 '''
@@ -20,7 +24,7 @@ describe 'CommonCoffeeHandler', ->
2024 test = 'It works.';
2125
2226 module.exports = function() {
23- return [test, arguments];
27+ return [test, Array.prototype.slice.call( arguments) ];
2428 };
2529
2630 }).call(this);
@@ -30,10 +34,18 @@ describe 'CommonCoffeeHandler', ->
3034 '''
3135 ]
3236
33- return @subject .handleFile path
37+ return @subject .handleFile @filePath
3438 .then (actual) ->
3539 assert .deepEqual actual, expected
3640
41+ it ' produces code that will work with CouchDB' , ->
42+ return @subject .handleFile @filePath
43+ .then (actual) =>
44+ fs .writeFileSync @tmpPath , " module.exports = #{ actual[1 ]} ;"
45+ actual = (require @tmpPath ) ' a' , ' b'
46+
47+ assert .deepEqual actual, [' It works.' , [' a' , ' b' ]]
48+
3749 it ' resolves to null for non-CoffeeScript files' , ->
3850 path = " #{ __dirname } /../../fixture/handler/other.other"
3951
@@ -54,3 +66,4 @@ describe 'CommonCoffeeHandler', ->
5466 return @subject .handleFile path
5567 .catch (actual) ->
5668 assert .instanceOf actual, HandlerError
69+
0 commit comments