mirror of
https://github.com/CryptKeeperZK/ejs.git
synced 2026-01-09 15:37:57 -05:00
introduced windows compatible tests
This commit is contained in:
21
jakefile.js
21
jakefile.js
@@ -1,4 +1,5 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
var execSync = require('child_process').execSync;
|
var execSync = require('child_process').execSync;
|
||||||
var exec = function (cmd) {
|
var exec = function (cmd) {
|
||||||
execSync(cmd, {stdio: 'inherit'});
|
execSync(cmd, {stdio: 'inherit'});
|
||||||
@@ -19,31 +20,36 @@ task('clean', ['clobber'], function () {
|
|||||||
|
|
||||||
desc('Lints the source code');
|
desc('Lints the source code');
|
||||||
task('lint', ['clean'], function () {
|
task('lint', ['clean'], function () {
|
||||||
exec('./node_modules/.bin/eslint "**/*.js"');
|
var epath = path.join('./node_modules/.bin/eslint');
|
||||||
|
exec(epath+' "**/*.js"');
|
||||||
console.log('Linting completed.');
|
console.log('Linting completed.');
|
||||||
});
|
});
|
||||||
|
|
||||||
task('browserify', function () {
|
task('browserify', function () {
|
||||||
exec('./node_modules/browserify/bin/cmd.js --standalone ejs lib/ejs.js > ejs.js');
|
var epath = path.join('./node_modules/browserify/bin/cmd.js');
|
||||||
|
exec(epath+' --standalone ejs lib/ejs.js > ejs.js');
|
||||||
console.log('Browserification completed.');
|
console.log('Browserification completed.');
|
||||||
});
|
});
|
||||||
|
|
||||||
task('minify', function () {
|
task('minify', function () {
|
||||||
exec('./node_modules/uglify-js/bin/uglifyjs ejs.js > ejs.min.js');
|
var epath = path.join('./node_modules/uglify-js/bin/uglifyjs');
|
||||||
|
exec(epath+' ejs.js > ejs.min.js');
|
||||||
console.log('Minification completed.');
|
console.log('Minification completed.');
|
||||||
});
|
});
|
||||||
|
|
||||||
desc('Generates the EJS API docs for the public API');
|
desc('Generates the EJS API docs for the public API');
|
||||||
task('doc', function () {
|
task('doc', function () {
|
||||||
jake.rmRf('out');
|
jake.rmRf('out');
|
||||||
exec('./node_modules/.bin/jsdoc --verbose -c jsdoc.json lib/* docs/jsdoc/*');
|
var epath = path.join('./node_modules/.bin/jsdoc');
|
||||||
|
exec(epath+' --verbose -c jsdoc.json lib/* docs/jsdoc/*');
|
||||||
console.log('Documentation generated in ./out.');
|
console.log('Documentation generated in ./out.');
|
||||||
});
|
});
|
||||||
|
|
||||||
desc('Generates the EJS API docs for the public and private API');
|
desc('Generates the EJS API docs for the public and private API');
|
||||||
task('devdoc', function () {
|
task('devdoc', function () {
|
||||||
jake.rmRf('out');
|
jake.rmRf('out');
|
||||||
exec('./node_modules/.bin/jsdoc --verbose -p -c jsdoc.json lib/* docs/jsdoc/*');
|
var epath = path.join('./node_modules/.bin/jsdoc');
|
||||||
|
exec(epath+' --verbose -p -c jsdoc.json lib/* docs/jsdoc/*');
|
||||||
console.log('Documentation generated in ./out.');
|
console.log('Documentation generated in ./out.');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,13 +57,14 @@ desc('Publishes the EJS API docs');
|
|||||||
task('docPublish', ['doc'], function () {
|
task('docPublish', ['doc'], function () {
|
||||||
fs.writeFileSync('out/CNAME', 'api.ejs.co');
|
fs.writeFileSync('out/CNAME', 'api.ejs.co');
|
||||||
console.log('Pushing docs to gh-pages...');
|
console.log('Pushing docs to gh-pages...');
|
||||||
exec('./node_modules/.bin/git-directory-deploy --directory out/');
|
var epath = path.join('./node_modules/.bin/git-directory-deploy');
|
||||||
|
exec(epath+' --directory out/');
|
||||||
console.log('Docs published to gh-pages.');
|
console.log('Docs published to gh-pages.');
|
||||||
});
|
});
|
||||||
|
|
||||||
desc('Runs the EJS test suite');
|
desc('Runs the EJS test suite');
|
||||||
task('test', ['lint'], function () {
|
task('test', ['lint'], function () {
|
||||||
exec('./node_modules/.bin/mocha');
|
exec(path.join('./node_modules/.bin/mocha'));
|
||||||
});
|
});
|
||||||
|
|
||||||
publishTask('ejs', ['build'], function () {
|
publishTask('ejs', ['build'], function () {
|
||||||
|
|||||||
43
test/cli.js
43
test/cli.js
@@ -1,6 +1,9 @@
|
|||||||
let exec = require('child_process').execSync;
|
let exec = require('child_process').execSync;
|
||||||
let fs = require('fs');
|
let fs = require('fs');
|
||||||
|
let path = require('path');
|
||||||
let assert = require('assert');
|
let assert = require('assert');
|
||||||
|
let os = process.platform !== 'win32' ? '' : 'node ';
|
||||||
|
let lf = process.platform !== 'win32' ? '\n' : '\r\n';
|
||||||
|
|
||||||
function run(cmd) {
|
function run(cmd) {
|
||||||
return exec(cmd).toString();
|
return exec(cmd).toString();
|
||||||
@@ -8,35 +11,47 @@ function run(cmd) {
|
|||||||
|
|
||||||
suite('cli', function () {
|
suite('cli', function () {
|
||||||
test('rendering, custom delimiter, passed data', function () {
|
test('rendering, custom delimiter, passed data', function () {
|
||||||
let o = run('./bin/cli.js -m $ ./test/fixtures/user.ejs name=foo');
|
let x = path.join('./bin/cli.js');
|
||||||
assert.equal(o, '<h1>foo</h1>\n');
|
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 () {
|
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');
|
let x = path.join('./bin/cli.js');
|
||||||
assert.equal(o, '<h1>zerb</h1>\n');
|
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 () {
|
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');
|
let x = path.join('./bin/cli.js');
|
||||||
assert.equal(o, '<h1>foo</h1>\n');
|
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 () {
|
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');
|
if ( process.platform !== 'win32' ) {
|
||||||
assert.equal(o, '<h1>zerb</h1>\n');
|
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 () {
|
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');
|
let x = path.join('./bin/cli.js');
|
||||||
assert.equal(o, '<h1>frang</h1>\n');
|
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 () {
|
test('rendering, remove whitespace option (hyphen case)', function () {
|
||||||
let o = run('./bin/cli.js --rm-whitespace ./test/fixtures/rmWhitespace.ejs');
|
let x = path.join('./bin/cli.js');
|
||||||
assert.equal(o, fs.readFileSync('test/fixtures/rmWhitespace.html', 'utf-8'));
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
47
test/ejs.js
47
test/ejs.js
@@ -11,6 +11,7 @@ var read = fs.readFileSync;
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var LRU = require('lru-cache');
|
var LRU = require('lru-cache');
|
||||||
|
let lf = process.platform !== 'win32' ? '\n' : '\r\n';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(__dirname + '/tmp');
|
fs.mkdirSync(__dirname + '/tmp');
|
||||||
@@ -383,7 +384,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
assert.equal(html, '<p>hey</p>\n');
|
assert.equal(html, '<p>hey</p>'+lf);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -392,7 +393,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () {
|
|||||||
var AsyncCtor;
|
var AsyncCtor;
|
||||||
var func;
|
var func;
|
||||||
function checkResult(html) {
|
function checkResult(html) {
|
||||||
assert.equal(html, '<p>hey</p>\n');
|
assert.equal(html, '<p>hey</p>'+lf);
|
||||||
}
|
}
|
||||||
// Environments without Promise support -- should throw
|
// Environments without Promise support -- should throw
|
||||||
// when no callback provided
|
// when no callback provided
|
||||||
@@ -440,7 +441,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
assert.equal(html, '<h1>fonebone</h1>\n');
|
assert.equal(html, '<h1>fonebone</h1>'+lf);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -457,7 +458,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () {
|
|||||||
doneCount = 2;
|
doneCount = 2;
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
assert.equal(html, '<h1>fonebone</h1>\n');
|
assert.equal(html, '<h1>fonebone</h1>'+lf);
|
||||||
doneCount++;
|
doneCount++;
|
||||||
if (doneCount === 2) {
|
if (doneCount === 2) {
|
||||||
done();
|
done();
|
||||||
@@ -538,7 +539,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
assert.equal(html, ctxt.foo + '\n');
|
assert.equal(html, ctxt.foo + lf);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -557,7 +558,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () {
|
|||||||
};
|
};
|
||||||
ejs.renderFile(path.join(__dirname, 'fixtures/views.ejs'), data, function(error, data){
|
ejs.renderFile(path.join(__dirname, 'fixtures/views.ejs'), data, function(error, data){
|
||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert.equal('<div><p>global test</p>\n</div>\n', data);
|
assert.equal('<div><p>global test</p>'+lf+'</div>'+lf, data);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -576,7 +577,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () {
|
|||||||
};
|
};
|
||||||
ejs.renderFile(path.join(__dirname, 'fixtures/views.ejs'), data, function(error, data){
|
ejs.renderFile(path.join(__dirname, 'fixtures/views.ejs'), data, function(error, data){
|
||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert.equal('<div><p>custom test</p>\n</div>\n', data);
|
assert.equal('<div><p>custom test</p>'+lf+'</div>'+lf, data);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -849,7 +850,10 @@ suite('exceptions', function () {
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
assert.equal(err.path, 'error.ejs');
|
assert.equal(err.path, 'error.ejs');
|
||||||
assert.equal(err.stack.split('\n').slice(0, 8).join('\n'), fixture('error.out'));
|
var errstck = err.stack.split('\n').slice(0, 8).join('\n');
|
||||||
|
errstck = errstck.replace(/\n/g,lf);
|
||||||
|
errstck = errstck.replace(/\r\r\n/g,lf);
|
||||||
|
assert.equal(errstck, fixture('error.out'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error('no error reported when there should be');
|
throw new Error('no error reported when there should be');
|
||||||
@@ -864,7 +868,10 @@ suite('exceptions', function () {
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
assert.ok(!err.path);
|
assert.ok(!err.path);
|
||||||
assert.notEqual(err.stack.split('\n').slice(0, 8).join('\n'), fixture('error.out'));
|
var errstck = err.stack.split('\n').slice(0, 8).join('\n');
|
||||||
|
errstck = errstck.replace(/\n/g,lf);
|
||||||
|
errstck = errstck.replace(/\r\r\n/g,lf);
|
||||||
|
assert.notEqual(errstck, fixture('error.out'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error('no error reported when there should be');
|
throw new Error('no error reported when there should be');
|
||||||
@@ -915,8 +922,8 @@ suite('exceptions', function () {
|
|||||||
|
|
||||||
suite('rmWhitespace', function () {
|
suite('rmWhitespace', function () {
|
||||||
test('works', function () {
|
test('works', function () {
|
||||||
assert.equal(ejs.render(fixture('rmWhitespace.ejs'), {}, {rmWhitespace: true}),
|
var outp = ejs.render(fixture('rmWhitespace.ejs'), {}, {rmWhitespace: true});
|
||||||
fixture('rmWhitespace.html'));
|
assert.equal(outp.replace(/\n/g,lf), fixture('rmWhitespace.html'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -975,7 +982,7 @@ suite('include()', function () {
|
|||||||
assert.equal(
|
assert.equal(
|
||||||
ejs.render('<%- include("fixtures/includes/bom.ejs") %>',
|
ejs.render('<%- include("fixtures/includes/bom.ejs") %>',
|
||||||
{}, {filename: path.join(__dirname, 'f.ejs')}),
|
{}, {filename: path.join(__dirname, 'f.ejs')}),
|
||||||
'<p>This is a file with BOM.</p>\n');
|
'<p>This is a file with BOM.</p>'+lf);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('include ejs with locals', function () {
|
test('include ejs with locals', function () {
|
||||||
@@ -1003,8 +1010,10 @@ suite('include()', function () {
|
|||||||
var file = 'test/fixtures/include-root.ejs';
|
var file = 'test/fixtures/include-root.ejs';
|
||||||
var inc = function (original, prev) {
|
var inc = function (original, prev) {
|
||||||
if (original.charAt(0) === '/') {
|
if (original.charAt(0) === '/') {
|
||||||
|
// original: '/include' (windows)
|
||||||
|
// prev: 'D:\include.ejs' (windows)
|
||||||
return {
|
return {
|
||||||
filename: path.join(__dirname, 'fixtures', prev)
|
filename: path.join(__dirname, 'fixtures', original+'.ejs')
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return prev;
|
return prev;
|
||||||
@@ -1017,9 +1026,11 @@ suite('include()', function () {
|
|||||||
test('include ejs with includer returning template', function () {
|
test('include ejs with includer returning template', function () {
|
||||||
var file = 'test/fixtures/include-root.ejs';
|
var file = 'test/fixtures/include-root.ejs';
|
||||||
var inc = function (original, prev) {
|
var inc = function (original, prev) {
|
||||||
if (prev === '/include.ejs') {
|
// original: '/include' (windows)
|
||||||
|
// prev: 'D:\include.ejs' (windows)
|
||||||
|
if (original === '/include') {
|
||||||
return {
|
return {
|
||||||
template: '<p>Hello template!</p>\n'
|
template: '<p>Hello template!</p>'+lf
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return prev;
|
return prev;
|
||||||
@@ -1073,10 +1084,10 @@ suite('include()', function () {
|
|||||||
var file = 'test/fixtures/include_cache.ejs';
|
var file = 'test/fixtures/include_cache.ejs';
|
||||||
var options = {filename: file};
|
var options = {filename: file};
|
||||||
var out = ejs.compile(fixture('include_cache.ejs'), options);
|
var out = ejs.compile(fixture('include_cache.ejs'), options);
|
||||||
assert.equal(out(), '<p>Old</p>\n');
|
assert.equal(out(), '<p>Old</p>'+lf);
|
||||||
|
|
||||||
fs.writeFileSync(__dirname + '/tmp/include.ejs', '<p>New</p>');
|
fs.writeFileSync(__dirname + '/tmp/include.ejs', '<p>New</p>');
|
||||||
assert.equal(out(), '<p>New</p>\n');
|
assert.equal(out(), '<p>New</p>'+lf);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('support caching', function () {
|
test('support caching', function () {
|
||||||
@@ -1126,7 +1137,7 @@ suite('test fileloader', function () {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
assert.equal(html, 'myFileLoad: <p>hey</p>\n');
|
assert.equal(html, 'myFileLoad: <p>hey</p>'+lf);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user