From d03da359f5723d840bdef22eba7f043718f357b6 Mon Sep 17 00:00:00 2001 From: czerwingithub Date: Wed, 20 Aug 2014 11:19:44 -0700 Subject: [PATCH] Fixed bug that caused the path of the generated javascript file to be appended multiple times with '.js', once for each time the file was processed. This resulted in the file's path going from *.js to *.js.js to *.js.js.js, etc. --- lib/html2js.js | 2 +- test/html2js.spec.coffee | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/html2js.js b/lib/html2js.js index 4114294..7c65f63 100644 --- a/lib/html2js.js +++ b/lib/html2js.js @@ -17,7 +17,7 @@ var createHtml2JsPreprocessor = function(logger, basePath) { var htmlPath = file.originalPath.replace(basePath + '/', ''); - file.path = file.path + '.js'; + file.path = file.originalPath + '.js'; done(util.format(TEMPLATE, htmlPath, escapeContent(content))); }; }; diff --git a/test/html2js.spec.coffee b/test/html2js.spec.coffee index 71e2eeb..2acbae9 100644 --- a/test/html2js.spec.coffee +++ b/test/html2js.spec.coffee @@ -27,6 +27,21 @@ describe 'preprocessors html2js', -> expect(file.path).to.equal '/base/path/file.html.js' done() + it 'should change path to *.js only once', (done) -> + # Test case for bug where processing the same file + # twice results in the path changing to *.js.js . + # Multiple processing can occur when you edit the underlying + # .html file multiple times while using karma to proxy the + # files for your dev environment. + file = new File '/base/path/file.html' + + process '', file, (processedContent) -> + expect(file.path).to.equal '/base/path/file.html.js' + + process '', file, (processedContent) -> + expect(file.path).to.equal '/base/path/file.html.js' + done() + it 'should preserve new lines', (done) -> file = new File '/base/path/file.html'