diff --git a/lib/preprocessor.js b/lib/preprocessor.js index 4e147187c..3d7db2a5d 100644 --- a/lib/preprocessor.js +++ b/lib/preprocessor.js @@ -52,6 +52,7 @@ var createPreprocessor = function(config, basePath, injector) { if (!preprocessors.length) { file.contentPath = null; file.content = content; + file.sha = sha1(content); return done(); } @@ -93,7 +94,6 @@ var createPreprocessor = function(config, basePath, injector) { if (err) { throw err; } - file.sha = sha1(buffer); nextPreprocessor(null, thisFileIsBinary ? buffer : buffer.toString()); }); }; diff --git a/test/unit/preprocessor.spec.coffee b/test/unit/preprocessor.spec.coffee index 61dd224bc..ae8cedc94 100644 --- a/test/unit/preprocessor.spec.coffee +++ b/test/unit/preprocessor.spec.coffee @@ -11,6 +11,7 @@ describe 'preprocessor', -> mockFs = mocks.fs.create some: 'a.js': mocks.fs.file 0, 'content' + 'b.js': mocks.fs.file 0, 'content' 'a.txt': mocks.fs.file 0, 'some-text' 'photo.png': mocks.fs.file 0, 'binary' @@ -96,6 +97,28 @@ describe 'preprocessor', -> expect(file.sha).not.to.equal previousSHA done() + it 'should compute SHA from content returned by a processor', (done) -> + fakePreprocessor = sinon.spy (content, file, done) -> + done null, content + '-processed' + + injector = new di.Injector [{ + 'preprocessor:fake': ['factory', -> fakePreprocessor] + }] + + pp = m.createPreprocessor {'**/a.js': ['fake']}, null, injector + + fileProcess = {originalPath: '/some/a.js', path: 'path'} + fileSkip = {originalPath: '/some/b.js', path: 'path'} + + pp fileProcess, -> + pp fileSkip, -> + expect(fileProcess.sha).to.exist + expect(fileProcess.sha.length).to.equal 40 + expect(fileSkip.sha).to.exist + expect(fileSkip.sha.length).to.equal 40 + expect(fileProcess.sha).not.to.equal fileSkip.sha + done() + it 'should return error if any preprocessor fails', (done) -> failingPreprocessor = sinon.spy (content, file, done) ->