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

Commit c56f4a7

Browse files
committed
Fix JS and CS for use as an actual module.
1 parent d2e2ae5 commit c56f4a7

File tree

8 files changed

+41
-17
lines changed

8 files changed

+41
-17
lines changed

.gitignore

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

lib/handler/CommonCoffeeHandler.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/handler/CommonJsHandler.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/handler/CommonCoffeeHandler.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = class CommonCoffeeHandler
1010
constructor: (@template) ->
1111
@template ?= '''
1212
(function () {
13-
if (!module) { var module = {}; }
13+
if (!module) { module = {}; }
1414
1515
%s
1616
return module.exports;

src/handler/CommonJsHandler.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = class CommonJsHandler
1010
constructor: (@template) ->
1111
@template ?= '''
1212
(function () {
13-
if (!module) { var module = {}; }
13+
if (!module) { module = {}; }
1414
1515
%s
1616
return module.exports;

test/suite/handler/CommonCoffeeHandler.spec.coffee

Lines changed: 17 additions & 5 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

@@ -7,14 +9,14 @@ describe 'CommonCoffeeHandler', ->
79
@subject = new CommonCoffeeHandler()
810

911
@filePath = "#{__dirname}/../../fixture/handler/coffee.coffee"
10-
@tmpPath = "#{__dirname}/../../fixture/tmp"
12+
@tmpPath = "#{__dirname}/../../fixture/tmp.js"
1113

1214
it 'resolves to a compiled module wrapper for CoffeeScript files', ->
1315
expected = [
1416
'coffee'
1517
'''
1618
(function () {
17-
if (!module) { var module = {}; }
19+
if (!module) { module = {}; }
1820
1921
var test;
2022
@@ -33,12 +35,22 @@ describe 'CommonCoffeeHandler', ->
3335
.then (actual) ->
3436
assert.deepEqual actual, expected
3537

36-
it 'produces code that will work with CouchDB', ->
38+
it 'produces code that will work as a CouchDB view function', ->
39+
return @subject.handleFile @filePath
40+
.then (actual) =>
41+
actual = eval actual[1]
42+
43+
assert.isFunction actual
44+
assert.deepEqual actual('a', 'b'), ['It works.', ['a', 'b']]
45+
46+
it 'produces code that will work as a CommonJS module', ->
3747
return @subject.handleFile @filePath
3848
.then (actual) =>
39-
actual = (eval actual[1])('a', 'b');
49+
fs.writeFileSync @tmpPath, actual[1]
50+
actual = require @tmpPath
4051

41-
assert.deepEqual actual, ['It works.', ['a', 'b']]
52+
assert.isFunction actual
53+
assert.deepEqual actual('a', 'b'), ['It works.', ['a', 'b']]
4254

4355
it 'resolves to null for non-CoffeeScript files', ->
4456
path = "#{__dirname}/../../fixture/handler/other.other"

test/suite/handler/CommonJsHandler.spec.coffee

Lines changed: 17 additions & 5 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

@@ -7,14 +9,14 @@ describe 'CommonJsHandler', ->
79
@subject = new CommonJsHandler()
810

911
@filePath = "#{__dirname}/../../fixture/handler/js.js"
10-
@tmpPath = "#{__dirname}/../../fixture/tmp"
12+
@tmpPath = "#{__dirname}/../../fixture/tmp.js"
1113

1214
it 'resolves to a module wrapper for JavaScript files', ->
1315
expected = [
1416
'js'
1517
'''
1618
(function () {
17-
if (!module) { var module = {}; }
19+
if (!module) { module = {}; }
1820
1921
var test = 'It works.';
2022
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };
@@ -28,12 +30,22 @@ describe 'CommonJsHandler', ->
2830
.then (actual) ->
2931
assert.deepEqual actual, expected
3032

31-
it 'produces code that will work with CouchDB', ->
33+
it 'produces code that will work as a CouchDB view function', ->
34+
return @subject.handleFile @filePath
35+
.then (actual) =>
36+
actual = eval actual[1]
37+
38+
assert.isFunction actual
39+
assert.deepEqual actual('a', 'b'), ['It works.', ['a', 'b']]
40+
41+
it 'produces code that will work as a CommonJS module', ->
3242
return @subject.handleFile @filePath
3343
.then (actual) =>
34-
actual = (eval actual[1])('a', 'b');
44+
fs.writeFileSync @tmpPath, actual[1]
45+
actual = require @tmpPath
3546

36-
assert.deepEqual actual, ['It works.', ['a', 'b']]
47+
assert.isFunction actual
48+
assert.deepEqual actual('a', 'b'), ['It works.', ['a', 'b']]
3749

3850
it 'resolves to null for non-JavaScript files', ->
3951
path = "#{__dirname}/../../fixture/handler/other.other"

test/suite/index.spec.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe 'Module', ->
88
it 'builds a result using the correct handlers', ->
99
expectedCoffee = '''
1010
(function () {
11-
if (!module) { var module = {}; }
11+
if (!module) { module = {}; }
1212
1313
var test;
1414
@@ -23,7 +23,7 @@ describe 'Module', ->
2323
'''
2424
expectedJs = '''
2525
(function () {
26-
if (!module) { var module = {}; }
26+
if (!module) { module = {}; }
2727
2828
var test = 'It works.';
2929
module.exports = function () { return [test, Array.prototype.slice.call(arguments)] };

0 commit comments

Comments
 (0)