From dda4e8459499b777fac405c80f917e868ecb5d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 19:20:22 +0100 Subject: [PATCH 01/10] Fix escape for windows path --- src/compiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.js b/src/compiler.js index 82618d31..e04a5b9d 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -124,7 +124,7 @@ var Compiler = Object.extend({ }, _templateName: function() { - return this.templateName == null? 'undefined' : '"'+this.templateName.replace(/"/g, '\\"')+'"'; + return this.templateName == null? 'undefined' : JSON.stringify(this.templateName); }, _bufferAppend: function(func) { From f08182c4cae5c271c316d65b4f60e11e0d9cffc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 19:57:13 +0100 Subject: [PATCH 02/10] Add method to normalize EOL in tests --- tests/api.js | 6 ++++-- tests/util.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/api.js b/tests/api.js index b2b0a829..7f9bcb4f 100644 --- a/tests/api.js +++ b/tests/api.js @@ -1,11 +1,13 @@ (function() { 'use strict'; - var expect, Environment, Loader, templatesPath; + var expect, util, Environment, Loader, templatesPath; var path = require('path'); + var os = require('os'); if(typeof require !== 'undefined') { expect = require('expect.js'); + util = require('./util'); Environment = require('../src/environment').Environment; Loader = require('../src/node-loaders').FileSystemLoader; templatesPath = 'tests/templates'; @@ -41,7 +43,7 @@ var test = env.getTemplate('relative/test-cache.html'); - expect(test.render()).to.be('Test1\nTest2'); + expect(util.normEOL(test.render())).to.be('Test1\nTest2'); }); it('should handle correctly relative paths in renderString', function() { diff --git a/tests/util.js b/tests/util.js index 01d34b08..c5df9d7e 100644 --- a/tests/util.js +++ b/tests/util.js @@ -52,6 +52,11 @@ } } + function normEOL(str) { + if (!str) return str; + return str.replace("\r\n", "\n"); + } + function render(str, ctx, opts, cb) { if(!opts) { cb = ctx; @@ -95,7 +100,7 @@ throw err; } - cb(err, res); + cb(err, normEOL(res)); doneAsyncs++; @@ -110,12 +115,14 @@ module.exports.render = render; module.exports.equal = equal; module.exports.finish = finish; + module.exports.normEOL = normEOL; } else { window.util = { render: render, equal: equal, - finish: finish + finish: finish, + normEOL: normEOL }; } })(); From 5b48f29a9e62e65079452b67fedb13b9fffe896c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 21:01:53 +0100 Subject: [PATCH 03/10] Improve EOL normalization for tests --- tests/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/util.js b/tests/util.js index c5df9d7e..9913987a 100644 --- a/tests/util.js +++ b/tests/util.js @@ -54,7 +54,7 @@ function normEOL(str) { if (!str) return str; - return str.replace("\r\n", "\n"); + return str.replace(/\r\n|\r|\n/g, "\n"); } function render(str, ctx, opts, cb) { From f58fd6479b7119c4ea79fb6c6089fa467271136e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 21:03:33 +0100 Subject: [PATCH 04/10] Add appveyor.yml for windows testing --- appveyor.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..680b86ca --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,28 @@ +# Fix line endings in Windows. (runs before repo cloning) +init: + - git config --global core.autocrlf input + +# Test against these versions of Node.js. +environment: + matrix: + - nodejs_version: "0.11" + - nodejs_version: "0.10" + - nodejs_version: "0.8" + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js or io.js + - ps: Install-Product node $env:nodejs_version + # install modules + - npm install + +# Post-install test scripts. +test_script: + # Output useful info for debugging. + - node --version + - npm --version + # run tests + - npm test + +# Don't actually build. +build: off From 3b2f4ea5aa2da0ad03736f79d1f68f367acf47be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 21:17:15 +0100 Subject: [PATCH 05/10] Remove make as testing dependency --- Makefile | 8 -------- package.json | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 76fba283..00000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ - -test: - node_modules/.bin/istanbul cover node_modules/.bin/_mocha \ - -- -b -R tap tests - -browserfiles: - ./bin/bundle browser/nunjucks - SLIM=1 ./bin/bundle browser/nunjucks-slim diff --git a/package.json b/package.json index 5643e164..0e758924 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "node": "*" }, "scripts": { - "test": "make test" + "test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -b -R tap tests", + "browserfiles": "./bin/bundle browser/nunjucks; SLIM=1 ./bin/bundle browser/nunjucks-slim" }, "bin": { "nunjucks-precompile": "./bin/precompile" From 7ff10e306a4bb9a3d668bce09fcc4dc01893a670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 21:49:28 +0100 Subject: [PATCH 06/10] Use explicit path to mocha bin in test script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e758924..7119c150 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "node": "*" }, "scripts": { - "test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -b -R tap tests", + "test": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- -b -R tap tests", "browserfiles": "./bin/bundle browser/nunjucks; SLIM=1 ./bin/bundle browser/nunjucks-slim" }, "bin": { From ff075af89dace93044b6f2dde33ee3b3eb68b03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 22:10:57 +0100 Subject: [PATCH 07/10] Fix #392: fix precompile.js for strict mode --- src/precompile.js | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/precompile.js b/src/precompile.js index b197f782..319b91a6 100644 --- a/src/precompile.js +++ b/src/precompile.js @@ -37,6 +37,27 @@ function precompile(input, opts) { var pathStats = fs.existsSync(input) && fs.statSync(input); var output = ''; + var templates = []; + + function addTemplates(dir) { + var files = fs.readdirSync(dir); + + for(var i=0; i Date: Tue, 10 Mar 2015 22:20:21 +0100 Subject: [PATCH 08/10] Add very simple test for precompile Related to #392 --- tests/precompile.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/precompile.js diff --git a/tests/precompile.js b/tests/precompile.js new file mode 100644 index 00000000..1e5cec5a --- /dev/null +++ b/tests/precompile.js @@ -0,0 +1,22 @@ +(function() { + 'use strict'; + + var expect, precompile, precompileString; + + if(typeof require !== 'undefined') { + expect = require('expect.js'); + precompile = require('../src/precompile').precompile; + precompileString = require('../src/precompile').precompileString; + } + else { + expect = window.expect; + precompile = nunjucks.precompile; + precompileString = nunjucks.precompileString + } + + describe('precompile', function() { + it('should return a string', function() { + expect(precompileString("{{ test }}", { name: "test.html" })).to.be.an('string'); + }); + }); +})(); From 41dd01cf61ae4aa09d96df55f2674fa6ddaa0f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 10 Mar 2015 22:22:24 +0100 Subject: [PATCH 09/10] Disable windows tests for node 0.8 --- appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 680b86ca..643fd4ba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,6 @@ environment: matrix: - nodejs_version: "0.11" - nodejs_version: "0.10" - - nodejs_version: "0.8" # Install scripts. (runs after repo cloning) install: From 0f8b21b8df7e8e852b2e1889388653b7075f0d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 11 Mar 2015 09:27:52 +0100 Subject: [PATCH 10/10] Simplify EOL norm regex in tests --- tests/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/util.js b/tests/util.js index 9913987a..39c8dd48 100644 --- a/tests/util.js +++ b/tests/util.js @@ -54,7 +54,7 @@ function normEOL(str) { if (!str) return str; - return str.replace(/\r\n|\r|\n/g, "\n"); + return str.replace(/\r\n|\r/g, "\n"); } function render(str, ctx, opts, cb) {