Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
ensure compileFile runs callback if cache found. Fixes gh-291
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong committed Aug 21, 2013
1 parent 40f49a3 commit a185ea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/swig.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ exports.Swig = function (opts) {
cached = cacheGet(pathname);

if (cached) {
if (cb) {
cb(null, cached);
return;
}
return cached;
}

Expand Down
10 changes: 7 additions & 3 deletions tests/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,14 @@ describe('swig.compileFile', function () {
});

it('can run asynchronously', function (done) {
expect(swig.compileFile(test, {}, function (err, fn) {
// Run twice to ensure cached result uses the callback [gh-291]
swig.compileFile(test, {}, function (err, fn) {
expect(fn).to.be.a(Function);
done();
}));
expect(swig.compileFile(test, {}, function (err, fn) {
expect(fn).to.be.a(Function);
done();
}));
});
});
});

Expand Down

0 comments on commit a185ea2

Please sign in to comment.