Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.nyc_output/
/coverage/
/node_modules/
/test/variable_file.txt
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const staticify = (root, options) => {
};

const refresh = () => {
cachedMakeHash.clear();
versions = buildVersionHash(root);
};

Expand Down
24 changes: 24 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const fs = require('fs');
const http = require('http');
const path = require('path');
const should = require('should');
Expand Down Expand Up @@ -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('.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you are splitting this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason expect for the fact that I copied it from the .getVersionedPath test.


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);
});
});