/
render-test.coffee
106 lines (99 loc) · 3.1 KB
/
render-test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# RequirestestServer
balUtil = require('bal-util')
safefs = require('safefs')
safeps = require('safeps')
chai = require('chai')
expect = chai.expect
joe = require('joe')
pathUtil = require('path')
# -------------------------------------
# Configuration
# Paths
docpadPath = pathUtil.join(__dirname, '..', '..')
rootPath = pathUtil.join(docpadPath, 'test')
renderPath = pathUtil.join(rootPath, 'render')
outPath = pathUtil.join(rootPath, 'render-out')
expectPath = pathUtil.join(rootPath, 'render-expected')
cliPath = pathUtil.join(docpadPath, 'bin', 'docpad')
nodePath = null
# -------------------------------------
# Tests
joe.suite 'docpad-render', (suite,test) ->
suite 'files', (suite,test) ->
# Check render physical files
inputs = [
{
filename: 'markdown-with-extension.md'
stdout: '*awesome*'
}
{
filename: 'markdown-with-extensions.html.md'
stdout: '<p><em>awesome</em></p>'
}
]
inputs.forEach (input) ->
test input.filename, (done) ->
# IMPORTANT THAT ANY OPTIONS GO AFTER THE RENDER CALL, SERIOUSLY
# OTHERWISE the sky falls down on scoping, seriously, it is wierd
command = [cliPath, 'render', pathUtil.join(renderPath,input.filename)]
safeps.spawnCommand 'node', command, {cwd:rootPath}, (err,stdout,stderr,code,signal) ->
return done(err) if err
expect(stdout.trim()).to.equal(input.stdout)
return done()
suite 'stdin', (suite,test) ->
# Check rendering stdin inputs
inputs = [
{
testname: 'markdown without extension'
filename: ''
stdin: '*awesome*'
stdout: '*awesome*'
}
{
testname: 'markdown with extension as filename'
filename: 'markdown'
stdin: '*awesome*'
stdout: '<p><em>awesome</em></p>'
}
{
testname: 'markdown with extension'
filename: 'example.md'
stdin: '*awesome*'
stdout: '*awesome*'
}
{
testname: 'markdown with extensions'
filename: '.html.md'
stdin: '*awesome*'
stdout: '<p><em>awesome</em></p>'
}
{
testname: 'markdown with filename'
filename: 'example.html.md'
stdin: '*awesome*'
stdout: '<p><em>awesome</em></p>'
}
]
inputs.forEach (input) ->
test input.testname, (done) ->
command = [cliPath, 'render']
command.push(input.filename) if input.filename
safeps.spawnCommand 'node', command, {stdin:input.stdin,cwd:rootPath}, (err,stdout,stderr,code,signal) ->
return done(err) if err
expect(stdout.trim()).to.equal(input.stdout)
done()
# Works with out path
test 'outPath', (done) ->
input = {
in: '*awesome*'
out: '<p><em>awesome</em></p>'
outPath: pathUtil.join(outPath,'outpath-render.html')
}
safeps.spawnCommand 'node', [cliPath, 'render', 'markdown', '-o', input.outPath], {stdin:input.in, cwd:rootPath}, (err,stdout,stderr,code,signal) ->
return done(err) if err
expect(stdout).to.equal('')
safefs.readFile input.outPath, (err,data) ->
return done(err) if err
result = data.toString()
expect(result.trim()).to.equal(input.out)
done()