-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80bf3d7
commit 9f66025
Showing
3 changed files
with
72 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
let exec = require('child_process').execSync; | ||
let fs = require('fs'); | ||
let path = require('path'); | ||
let assert = require('assert'); | ||
let os = process.platform !== 'win32' ? '' : 'node '; | ||
let lf = process.platform !== 'win32' ? '\n' : '\r\n'; | ||
|
||
function run(cmd) { | ||
return exec(cmd).toString(); | ||
} | ||
|
||
suite('cli', function () { | ||
test('rendering, custom delimiter, passed data', function () { | ||
let o = run('./bin/cli.js -m $ ./test/fixtures/user.ejs name=foo'); | ||
assert.equal(o, '<h1>foo</h1>\n'); | ||
let x = path.join('./bin/cli.js'); | ||
let u = path.join('./test/fixtures/user.ejs'); | ||
let o = run(os+x+' -m $ '+u+' name=foo'); | ||
assert.equal(o, '<h1>foo</h1>'+lf); | ||
}); | ||
|
||
test('rendering, custom delimiter, data from file with -f', function () { | ||
let o = run('./bin/cli.js -m $ -f ./test/fixtures/user_data.json ./test/fixtures/user.ejs'); | ||
assert.equal(o, '<h1>zerb</h1>\n'); | ||
let x = path.join('./bin/cli.js'); | ||
let u = path.join('./test/fixtures/user.ejs'); | ||
let o = run(os+x+' -m $ -f ./test/fixtures/user_data.json '+u); | ||
assert.equal(o, '<h1>zerb</h1>'+lf); | ||
}); | ||
|
||
test('rendering, custom delimiter, data from CLI arg with -i', function () { | ||
let o = run('./bin/cli.js -m $ -i %7B%22name%22%3A%20%22foo%22%7D ./test/fixtures/user.ejs'); | ||
assert.equal(o, '<h1>foo</h1>\n'); | ||
let x = path.join('./bin/cli.js'); | ||
let u = path.join('./test/fixtures/user.ejs'); | ||
let o = run(os+x+' -m $ -i %7B%22name%22%3A%20%22foo%22%7D '+u); | ||
assert.equal(o, '<h1>foo</h1>'+lf); | ||
}); | ||
|
||
test('rendering, custom delimiter, data from stdin / pipe', function () { | ||
let o = run('cat ./test/fixtures/user_data.json | ./bin/cli.js -m $ ./test/fixtures/user.ejs'); | ||
assert.equal(o, '<h1>zerb</h1>\n'); | ||
if ( process.platform !== 'win32' ) { | ||
let o = run('cat ./test/fixtures/user_data.json | ./bin/cli.js -m $ ./test/fixtures/user.ejs'); | ||
assert.equal(o, '<h1>zerb</h1>\n'); | ||
} // does not work on windows... | ||
}); | ||
|
||
test('rendering, custom delimiter, passed data overrides file', function () { | ||
let o = run('./bin/cli.js -m $ -f ./test/fixtures/user_data.json ./test/fixtures/user.ejs name=frang'); | ||
assert.equal(o, '<h1>frang</h1>\n'); | ||
let x = path.join('./bin/cli.js'); | ||
let f = path.join('./test/fixtures/user_data.json'); | ||
let g = path.join('./test/fixtures/user.ejs'); | ||
let o = run(os+x+' -m $ -f '+f+' '+g+' name=frang'); | ||
assert.equal(o, '<h1>frang</h1>'+lf); | ||
}); | ||
|
||
test('rendering, remove whitespace option (hyphen case)', function () { | ||
let o = run('./bin/cli.js --rm-whitespace ./test/fixtures/rmWhitespace.ejs'); | ||
assert.equal(o, fs.readFileSync('test/fixtures/rmWhitespace.html', 'utf-8')); | ||
let x = path.join('./bin/cli.js'); | ||
let f = path.join('./test/fixtures/rmWhitespace.ejs'); | ||
let o = run(os+x+' --rm-whitespace '+f); | ||
let c = fs.readFileSync('test/fixtures/rmWhitespace.html', 'utf-8'); | ||
assert.equal(o.replace(/\n/g, lf), c); | ||
}); | ||
|
||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters