diff --git a/jakefile.js b/jakefile.js index 3953160a..7f601051 100644 --- a/jakefile.js +++ b/jakefile.js @@ -1,4 +1,5 @@ var fs = require('fs'); +var path = require('path'); var execSync = require('child_process').execSync; var exec = function (cmd) { execSync(cmd, {stdio: 'inherit'}); @@ -19,31 +20,36 @@ task('clean', ['clobber'], function () { desc('Lints the source code'); 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.'); }); 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.'); }); 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.'); }); desc('Generates the EJS API docs for the public API'); task('doc', function () { 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.'); }); desc('Generates the EJS API docs for the public and private API'); task('devdoc', function () { 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.'); }); @@ -51,13 +57,14 @@ desc('Publishes the EJS API docs'); task('docPublish', ['doc'], function () { fs.writeFileSync('out/CNAME', 'api.ejs.co'); 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.'); }); desc('Runs the EJS test suite'); task('test', ['lint'], function () { - exec('./node_modules/.bin/mocha'); + exec(path.join('./node_modules/.bin/mocha')); }); publishTask('ejs', ['build'], function () { diff --git a/test/cli.js b/test/cli.js index 65c0fafa..81b1d5e9 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,6 +1,9 @@ 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(); @@ -8,35 +11,47 @@ function run(cmd) { 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, '

foo

\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, '

foo

'+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, '

zerb

\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, '

zerb

'+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, '

foo

\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, '

foo

'+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, '

zerb

\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, '

zerb

\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, '

frang

\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, '

frang

'+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); }); }); - - diff --git a/test/ejs.js b/test/ejs.js index 5360499d..1e99d420 100755 --- a/test/ejs.js +++ b/test/ejs.js @@ -11,6 +11,7 @@ var read = fs.readFileSync; var assert = require('assert'); var path = require('path'); var LRU = require('lru-cache'); +let lf = process.platform !== 'win32' ? '\n' : '\r\n'; try { fs.mkdirSync(__dirname + '/tmp'); @@ -383,7 +384,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () { if (err) { return done(err); } - assert.equal(html, '

hey

\n'); + assert.equal(html, '

hey

'+lf); done(); }); }); @@ -392,7 +393,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () { var AsyncCtor; var func; function checkResult(html) { - assert.equal(html, '

hey

\n'); + assert.equal(html, '

hey

'+lf); } // Environments without Promise support -- should throw // when no callback provided @@ -440,7 +441,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () { if (err) { return done(err); } - assert.equal(html, '

fonebone

\n'); + assert.equal(html, '

fonebone

'+lf); done(); }); }); @@ -457,7 +458,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () { doneCount = 2; return done(err); } - assert.equal(html, '

fonebone

\n'); + assert.equal(html, '

fonebone

'+lf); doneCount++; if (doneCount === 2) { done(); @@ -538,7 +539,7 @@ suite('ejs.renderFile(path, [data], [options], [fn])', function () { if (err) { return done(err); } - assert.equal(html, ctxt.foo + '\n'); + assert.equal(html, ctxt.foo + lf); 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){ assert.ifError(error); - assert.equal('

global test

\n
\n', data); + assert.equal('

global test

'+lf+'
'+lf, data); 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){ assert.ifError(error); - assert.equal('

custom test

\n
\n', data); + assert.equal('

custom test

'+lf+'
'+lf, data); done(); }); @@ -849,7 +850,10 @@ suite('exceptions', function () { } catch (err) { 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; } throw new Error('no error reported when there should be'); @@ -864,7 +868,10 @@ suite('exceptions', function () { } catch (err) { 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; } throw new Error('no error reported when there should be'); @@ -915,8 +922,8 @@ suite('exceptions', function () { suite('rmWhitespace', function () { test('works', function () { - assert.equal(ejs.render(fixture('rmWhitespace.ejs'), {}, {rmWhitespace: true}), - fixture('rmWhitespace.html')); + var outp = ejs.render(fixture('rmWhitespace.ejs'), {}, {rmWhitespace: true}); + assert.equal(outp.replace(/\n/g,lf), fixture('rmWhitespace.html')); }); }); @@ -975,7 +982,7 @@ suite('include()', function () { assert.equal( ejs.render('<%- include("fixtures/includes/bom.ejs") %>', {}, {filename: path.join(__dirname, 'f.ejs')}), - '

This is a file with BOM.

\n'); + '

This is a file with BOM.

'+lf); }); test('include ejs with locals', function () { @@ -1003,8 +1010,10 @@ suite('include()', function () { var file = 'test/fixtures/include-root.ejs'; var inc = function (original, prev) { if (original.charAt(0) === '/') { + // original: '/include' (windows) + // prev: 'D:\include.ejs' (windows) return { - filename: path.join(__dirname, 'fixtures', prev) + filename: path.join(__dirname, 'fixtures', original+'.ejs') }; } else { return prev; @@ -1017,9 +1026,11 @@ suite('include()', function () { test('include ejs with includer returning template', function () { var file = 'test/fixtures/include-root.ejs'; var inc = function (original, prev) { - if (prev === '/include.ejs') { + // original: '/include' (windows) + // prev: 'D:\include.ejs' (windows) + if (original === '/include') { return { - template: '

Hello template!

\n' + template: '

Hello template!

'+lf }; } else { return prev; @@ -1073,10 +1084,10 @@ suite('include()', function () { var file = 'test/fixtures/include_cache.ejs'; var options = {filename: file}; var out = ejs.compile(fixture('include_cache.ejs'), options); - assert.equal(out(), '

Old

\n'); + assert.equal(out(), '

Old

'+lf); fs.writeFileSync(__dirname + '/tmp/include.ejs', '

New

'); - assert.equal(out(), '

New

\n'); + assert.equal(out(), '

New

'+lf); }); test('support caching', function () { @@ -1126,7 +1137,7 @@ suite('test fileloader', function () { if (err) { return done(err); } - assert.equal(html, 'myFileLoad:

hey

\n'); + assert.equal(html, 'myFileLoad:

hey

'+lf); done(); });