From 945771ed2a31ab808672a3138b0a01930bc747e1 Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Mon, 25 Mar 2019 12:26:03 +0000 Subject: [PATCH 1/3] Refresh should refresh file hashes by clearing the memoized hashes --- index.js | 1 + 1 file changed, 1 insertion(+) 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); }; From 80d747e6bc9ac26398abd1bea9d6b566445feecf Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Mon, 25 Mar 2019 14:47:32 +0000 Subject: [PATCH 2/3] Add a test for refresh() --- .gitignore | 1 + test/index.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) 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/test/index.js b/test/index.js index 0a27839..84724fb 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,27 @@ 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); + }); +}); From 7e28339d38efeb9931a756ac446059d33eb8a396 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 2 Apr 2019 21:52:33 +0300 Subject: [PATCH 3/3] Update index.js --- test/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index 84724fb..0f3fdce 100644 --- a/test/index.js +++ b/test/index.js @@ -279,10 +279,9 @@ describe('.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');