Skip to content

Commit

Permalink
fix(preprocessor): calculate sha1 on content returned from a preproce…
Browse files Browse the repository at this point in the history
…ssor

Fixes #1204
  • Loading branch information
pkozlowski-opensource committed Oct 13, 2014
1 parent 449b0f5 commit 6cf7955
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/preprocessor.js
Expand Up @@ -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();
}

Expand Down Expand Up @@ -93,7 +94,6 @@ var createPreprocessor = function(config, basePath, injector) {
if (err) {
throw err;
}
file.sha = sha1(buffer);
nextPreprocessor(null, thisFileIsBinary ? buffer : buffer.toString());
});
};
Expand Down
23 changes: 23 additions & 0 deletions test/unit/preprocessor.spec.coffee
Expand Up @@ -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'

Expand Down Expand Up @@ -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) ->
Expand Down

0 comments on commit 6cf7955

Please sign in to comment.