From ff4f8f2381896d7ead1e598f37380ca40aa1aea2 Mon Sep 17 00:00:00 2001 From: Sam Gentle Date: Mon, 7 Nov 2016 20:55:33 +1100 Subject: [PATCH 1/4] make tests run in temp dir --- tests/find.test.js | 2 ++ tests/geoIndex.test.js | 4 ++-- tests/update.test.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/find.test.js b/tests/find.test.js index 2ca36db4..64987da2 100644 --- a/tests/find.test.js +++ b/tests/find.test.js @@ -4,6 +4,8 @@ var assert = require('chai').assert var geoTz = require('../index.js') +process.chdir('/tmp') + describe('find tests', function () { it('should find the timezone name for a valid coordinate', function () { var tz = geoTz.tz(47.650499, -122.350070) diff --git a/tests/geoIndex.test.js b/tests/geoIndex.test.js index fab03317..1fe90cb8 100644 --- a/tests/geoIndex.test.js +++ b/tests/geoIndex.test.js @@ -9,7 +9,7 @@ var util = require('./util.js') var createGeoIndex = require('../lib/createGeoIndex.js') -var TEST_DATA_DIR = './data-test-geoindex' +var TEST_DATA_DIR = __dirname + '/../data-test-geoindex' var testTzData = require('./data/largeTz.json') var expectedIndexData = require('./data/expectedIndexData.json') @@ -30,7 +30,7 @@ describe('geoindex', function () { function (err) { assert.isNotOk(err) - var generatedIndex = require('.' + TEST_DATA_DIR + '/index.json') + var generatedIndex = require(TEST_DATA_DIR + '/index.json') assert.deepEqual(generatedIndex, expectedIndexData) diff --git a/tests/update.test.js b/tests/update.test.js index 73cdae98..d190fdec 100644 --- a/tests/update.test.js +++ b/tests/update.test.js @@ -10,7 +10,7 @@ var util = require('./util.js') var update = require('../lib/update.js') var TEST_DATA_DIR = './data-test-update' -var LOCAL_FOLDER = './tests/data/' +var LOCAL_FOLDER = __dirname + '/../tests/data/' describe('data update', function () { this.timeout(4000) From 0ce49f5a78bffeed45bbe8d7376b58929a57bccf Mon Sep 17 00:00:00 2001 From: Sam Gentle Date: Mon, 7 Nov 2016 20:56:40 +1100 Subject: [PATCH 2/4] fix wrong directory on subfile lookup --- lib/find.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/find.js b/lib/find.js index aaf06bf1..c7a81cc5 100644 --- a/lib/find.js +++ b/lib/find.js @@ -85,7 +85,7 @@ var getTimezone = function (lat, lon) { // exact boundaries saved in file // parse geojson for exact boundaries var filepath = quadPos.split('').join('/') - var data = new Pbf(fs.readFileSync('./data/' + filepath + '/geo.buf')) + var data = new Pbf(fs.readFileSync(__dirname + '/../data/' + filepath + '/geo.buf')) var geoJson = geobuf.decode(data) for (var i = 0; i < geoJson.features.length; i++) { From 44a2e1aeab8584a8d18476bce2755111d3258a94 Mon Sep 17 00:00:00 2001 From: Sam Gentle Date: Mon, 7 Nov 2016 22:39:15 +1100 Subject: [PATCH 3/4] make update paths relative to dirname --- lib/update.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/update.js b/lib/update.js index a46f1f64..9abc0147 100644 --- a/lib/update.js +++ b/lib/update.js @@ -9,8 +9,8 @@ var yauzl = require('yauzl') var indexGeoJSON = require('./createGeoIndex.js') var TARGET_INDEX_PERCENT = 0.5 -var dlFile = 'downloads/timezones.zip' -var tzFile = 'downloads/timezones.json' +var dlFile = __dirname + '/../downloads/timezones.zip' +var tzFile = __dirname + '/../downloads/timezones.json' var downloadLatest = function (callback) { console.log('Downloading geojson') @@ -69,7 +69,7 @@ module.exports = function (cfg, callback) { } } - var dataDir = cfg.dataDir || './data' + var dataDir = cfg.dataDir || __dirname + '/../data' async.auto({ // download latest geojson data @@ -108,7 +108,7 @@ module.exports = function (cfg, callback) { }) }], createIndex: ['deleteIndexFoldersAndFiles', 'unzipGeoJson', function (results, cb) { - indexGeoJSON(require('../' + tzFile), dataDir, TARGET_INDEX_PERCENT, cb) + indexGeoJSON(require(tzFile), dataDir, TARGET_INDEX_PERCENT, cb) }] }, callback) } From d9cdc110044da790347c319ffb06a5c3063dffa5 Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Mon, 7 Nov 2016 09:08:55 -0800 Subject: [PATCH 4/4] fix(update): Fix update script so it uses absolute directory when creating downloads dir. --- lib/update.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/update.js b/lib/update.js index 9abc0147..4c89752f 100644 --- a/lib/update.js +++ b/lib/update.js @@ -42,7 +42,7 @@ var downloadLatest = function (callback) { rimraf(dlFile, cb) }, mkdir: ['rm', function (results, cb) { - mkdirp('downloads', cb) + mkdirp(__dirname + '/../downloads', cb) }], dl: ['mkdir', 'getLatestUrl', function (results, cb) { https.get({