Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit c28e562

Browse files
committed
Improved tests.
1 parent 398fac1 commit c28e562

File tree

8 files changed

+38
-12
lines changed

8 files changed

+38
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/build/
22
/coverage/
33
/node_modules/
4+
/test/fixture/tmp

test/fixture/handler/coffee.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test = 'It works.'
2-
module.exports = -> [test, arguments]
2+
module.exports = -> [test, Array.prototype.slice.call(arguments)]

test/fixture/handler/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
var test = 'It works.';
2-
module.exports = function () { return [test, arguments] };
2+
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test = 'It works.'
2-
module.exports = -> [test, arguments]
2+
module.exports = -> [test, Array.prototype.slice.call(arguments)]

test/fixture/handler/nested/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
var test = 'It works.';
2-
module.exports = function () { return [test, arguments] };
2+
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };

test/suite/handler/CommonCoffeeHandler.spec.coffee

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fs = require 'fs'
2+
13
CommonCoffeeHandler = require '../../../src/handler/CommonCoffeeHandler'
24
HandlerError = 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+

test/suite/handler/CommonJsHandler.spec.coffee

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
fs = require 'fs'
2+
13
CommonJsHandler = require '../../../src/handler/CommonJsHandler'
24
HandlerError = require '../../../src/handler/error/HandlerError'
35

@@ -6,8 +8,10 @@ describe 'CommonJsHandler', ->
68
beforeEach ->
79
@subject = new CommonJsHandler()
810

11+
@filePath = "#{__dirname}/../../fixture/handler/js.js"
12+
@tmpPath = "#{__dirname}/../../fixture/tmp"
13+
914
it 'resolves to a module wrapper for JavaScript files', ->
10-
path = "#{__dirname}/../../fixture/handler/js.js"
1115
expected = [
1216
'js'
1317
'''
@@ -16,18 +20,26 @@ describe 'CommonJsHandler', ->
1620
(function () {
1721
1822
var test = 'It works.';
19-
module.exports = function () { return [test, arguments] };
23+
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };
2024
2125
}).call(this);
2226
return module.exports.apply(this, arguments);
2327
}
2428
'''
2529
]
2630

27-
return @subject.handleFile path
31+
return @subject.handleFile @filePath
2832
.then (actual) ->
2933
assert.deepEqual actual, expected
3034

35+
it 'produces code that will work with CouchDB', ->
36+
return @subject.handleFile @filePath
37+
.then (actual) =>
38+
fs.writeFileSync @tmpPath, "module.exports = #{actual[1]};"
39+
actual = (require @tmpPath) 'a', 'b'
40+
41+
assert.deepEqual actual, ['It works.', ['a', 'b']]
42+
3143
it 'resolves to null for non-JavaScript files', ->
3244
path = "#{__dirname}/../../fixture/handler/other.other"
3345

test/suite/index.spec.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe 'Module', ->
1616
test = 'It works.';
1717
1818
module.exports = function() {
19-
return [test, arguments];
19+
return [test, Array.prototype.slice.call(arguments)];
2020
};
2121
2222
}).call(this);
@@ -30,7 +30,7 @@ describe 'Module', ->
3030
(function () {
3131
3232
var test = 'It works.';
33-
module.exports = function () { return [test, arguments] };
33+
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };
3434
3535
}).call(this);
3636
return module.exports.apply(this, arguments);

0 commit comments

Comments
 (0)