Skip to content

Commit

Permalink
fix: don’t make change if time fields match (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
buffaybu committed Jan 29, 2019
1 parent 23b02c0 commit e62ef8d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class LocalStorage implements IStorage {
}
}

if ('time' in packageInfo) {
if ('time' in packageInfo && !_.isEqual(packageLocalJson.time, packageInfo.time)) {
packageLocalJson.time = packageInfo.time;
change = true;
}
Expand Down
23 changes: 19 additions & 4 deletions test/unit/api/local-storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import rimRaf from 'rimraf';
import path from 'path';
import fs from 'fs';
import LocalStorage from '../../../src/lib/local-storage';
import AppConfig from '../../../src/lib/config';
// $FlowFixMe
Expand Down Expand Up @@ -250,14 +251,16 @@ describe('LocalStorage', () => {
});

describe('LocalStorage::updateVersions', () => {
test('should update versions from external source', async (done) => {
const metadata = JSON.parse(readMetadata('metadata-update-versions-tags'));
const pkgName = 'add-update-versions-test-1';
const version = '1.0.2';
const metadata = JSON.parse(readMetadata('metadata-update-versions-tags'));
const pkgName = 'add-update-versions-test-1';
const version = '1.0.2';
beforeAll(async () => {
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
await addNewVersion(pkgName, '1.0.1');
await addNewVersion(pkgName, version);
})

test('should update versions from external source', async (done) => {
storage.updateVersions(pkgName, metadata, (err, data) => {
expect(err).toBeNull();
expect(data.versions['1.0.1']).toBeDefined();
Expand All @@ -274,6 +277,18 @@ describe('LocalStorage', () => {
done();
});
});

test('should not update if the metadata match', done => {
const metadataPath = path.join(configExample.storage, pkgName, 'package.json')
const prevStat = fs.statSync(metadataPath)
storage.updateVersions(pkgName, metadata, (err, data) => {
expect(err).toBeNull()
const nextStat = fs.statSync(metadataPath)
expect(nextStat).toHaveProperty('ctime', prevStat.ctime)
expect(nextStat).toHaveProperty('mtime', prevStat.mtime)
done()
})
})
});

describe('LocalStorage::changePackage', () => {
Expand Down
8 changes: 7 additions & 1 deletion test/unit/partials/metadata-update-versions-tags
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@
"beta": "1.0.2",
"next": "1.0.4"
},
"time": {},
"time": {
"modified": "2019-01-29T03:20:04.000Z",
"created": "2019-01-29T03:20:00.000Z",
"1.0.1": "2019-01-29T03:20:01.000Z",
"1.0.2": "2019-01-29T03:20:02.000Z",
"1.0.4": "2019-01-29T03:20:04.000Z"
},
"_distfiles": {},
"_attachments": {},
"_uplinks": {},
Expand Down

0 comments on commit e62ef8d

Please sign in to comment.