Skip to content

Fix invalid atime being set #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2021
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = {
fs.stat(fullPath, function(err, stats) {
if (err) resolve(); // ignore errors
else {
fs.utimes(outFilePath, Date.now(), stats.mtime, function () {
fs.utimes(outFilePath, new Date(), stats.mtime, function () {
resolve();
});
}
Expand Down
18 changes: 16 additions & 2 deletions tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('gzip plugin', function() {
if (!fs.existsSync(context.distDir)) { fs.mkdirSync(context.distDir); }
if (!fs.existsSync(path.join(context.distDir, 'assets'))) { fs.mkdirSync(path.join(context.distDir, 'assets')); }
fs.writeFileSync(path.join(context.distDir, context.distFiles[0]), 'alert("Hello foo world!");', 'utf8');
fs.utimesSync(path.join(context.distDir, context.distFiles[0]), Date.now(), new Date("2020-01-01T00:01:02Z"));
fs.utimesSync(path.join(context.distDir, context.distFiles[0]), new Date(), new Date("2020-01-01T00:01:02Z"));
fs.writeFileSync(path.join(context.distDir, context.distFiles[1]), 'alert("Hello bar world!");', 'utf8');
fs.writeFileSync(path.join(context.distDir, context.distFiles[2]), 'alert("Hello ignore world!");', 'utf8');
plugin.beforeHook(context);
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('gzip plugin', function() {
});
});

it('has the same timestamp as the original', function(done) {
it('has the same mtime timestamp as the original', function(done) {
assert.isFulfilled(plugin.willUpload(context))
.then(function(result) {
var mtime_gz = fs.statSync(path.join(context.distDir, result.gzippedFiles[0])).mtime.valueOf();
Expand All @@ -201,6 +201,20 @@ describe('gzip plugin', function() {
});
});

it('atime timestamp is slightly newer than the original', function(done) {
assert.isFulfilled(plugin.willUpload(context))
.then(function(result) {
var atime_gz = fs.statSync(path.join(context.distDir, result.gzippedFiles[0])).atime.valueOf();
var atime_orig = fs.statSync(path.join(context.distDir, context.distFiles[0])).atime.valueOf();

assert.ok(atime_gz - atime_orig < 1000);

done();
}).catch(function(reason){
done(reason);
});
});

it('does not use the same object for gzippedFiles and distFiles', function(done) {
assert.isFulfilled(plugin.willUpload(context))
.then(function(result) {
Expand Down