diff --git a/.gitignore b/.gitignore index bd53bbe..5581656 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.nyc_output/ /coverage/ /node_modules/ +/test/variable_file.txt diff --git a/index.js b/index.js index d44af53..baf1549 100644 --- a/index.js +++ b/index.js @@ -141,6 +141,7 @@ const staticify = (root, options) => { }; const refresh = () => { + cachedMakeHash.clear(); versions = buildVersionHash(root); }; diff --git a/test/index.js b/test/index.js index 0a27839..0f3fdce 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,6 @@ 'use strict'; +const fs = require('fs'); const http = require('http'); const path = require('path'); const should = require('should'); @@ -272,3 +273,26 @@ describe('.replacePaths', () => { results.includes('test/font.woff2').should.be.false(); }); }); + +describe('.refresh', () => { + it('should empty the cache of file hashes after a refresh()', () => { + fs.writeFileSync(path.join(__dirname, 'variable_file.txt'), 'File Content 1'); + + const staticifyObj = staticify(ROOT); + const versionedPath = staticifyObj.getVersionedPath('/test/variable_file.txt'); + const versioned = versionedPath.split('.'); + + versioned.should.have.a.lengthOf(3); + versioned[0].should.equal('/test/variable_file'); + versioned[2].should.equal('txt'); + + staticifyObj.refresh(); + + fs.writeFileSync(path.join(__dirname, 'variable_file.txt'), 'File Content 2'); + + const versionedPath2 = staticifyObj.getVersionedPath('/test/variable_file.txt'); + + versionedPath2.should.have.a.lengthOf(31); + versionedPath2.should.not.equal(versionedPath); + }); +});