Skip to content

Commit 9dbabd8

Browse files
committed
Added tests for selectFormatter engine function.
1 parent c4dfcc5 commit 9dbabd8

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

test/template_engine.coffee

+31
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ defaultEngine = require('../lib/client_asset_manager/template_engines/default').
66

77
formatters =
88
html: require('./testdata_stubs/formatter_html').init()
9+
const: require('./testdata_stubs/formatter_const').init()
10+
911
root = __dirname
1012
dir = 'testdata_files'
1113

1214
testTmpl = fs.readFileSync("#{root}/#{dir}/template.html")
1315
testTmpl_2 = fs.readFileSync("#{root}/#{dir}/foo/template2.html")
1416
testTmpl_3 = fs.readFileSync("#{root}/#{dir}/template.foo")
17+
testTmpl_4 = fs.readFileSync("#{root}/#{dir}/template.const")
1518

1619

1720
describe 'wrapTemplate', ->
@@ -59,13 +62,41 @@ describe 'wrapTemplate', ->
5962
processWithWrap(engine_2, testTmpl, null, 'template')
6063
output.should.equal expected
6164

65+
lib.generate root, dir, ['foo/template2.html', 'template.const'], formatters, (output) ->
66+
expected = processWithWrap(engine, testTmpl_2, null, 'foo-template2') +
67+
processWithWrap(engine_2, 'CONST', null, 'template')
68+
output.should.equal expected
69+
6270

6371
it 'should not modify template content for unrecognized file extensions', ->
6472
lib = EngineLib.init()
6573
lib.generate root, dir, ['template.foo'], formatters, (output) ->
6674
output.should.equal defaultEngine.process(testTmpl_3, null, 'template')
6775

6876

77+
it 'should allow the use of a formatter specified by the engine', ->
78+
engine = EngineStub.init 'X'
79+
engine.selectFormatter = -> formatters.const
80+
81+
lib = EngineLib.init()
82+
lib.use(init: -> engine)
83+
lib.generate root, dir, ['template.html'], formatters, (output) ->
84+
# The const formatter always outputs 'CONST'
85+
output.should.equal processWithWrap(engine, 'CONST', null, 'template')
86+
87+
88+
it 'should allow the engine to specify no formatting of the template file', ->
89+
engine = EngineStub.init 'X'
90+
engine.selectFormatter = -> false
91+
92+
lib = EngineLib.init()
93+
lib.use(init: -> engine)
94+
lib.generate root, dir, ['template.const'], formatters, (output) ->
95+
# The const formatter always outputs 'CONST' In this case it should
96+
# not equal 'CONST' because it should not be using any formatter.
97+
output.should.equal processWithWrap(engine, testTmpl_4, null, 'template')
98+
99+
69100

70101
processWithWrap = (engine, tmpl, path, id) ->
71102
engine.prefix() +

test/testdata_files/template.const

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Some more random content.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Plain HTML Formatter
2+
3+
fs = require('fs')
4+
5+
exports.init = ->
6+
7+
extensions: ['const']
8+
assetType: 'html'
9+
contentType: 'text/html'
10+
11+
compile: (path, options, cb) -> cb 'CONST'

0 commit comments

Comments
 (0)