Skip to content

Commit a49d64f

Browse files
authored
Update first batch of npm dependencies (#7169)
* Update dependencies in cucumber-js test framework * Clear package-lock.json * Fix tape test * Replace rimraf with node-interal fs.rm * Update Babel * Update xmlbuilder * Delete files in a sync way
1 parent f5e9241 commit a49d64f

File tree

17 files changed

+21184
-27900
lines changed

17 files changed

+21184
-27900
lines changed

features/lib/osrm_loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const fs = require('fs');
44
const util = require('util');
5-
const Timeout = require('node-timeout');
5+
const { Timeout } = require('./utils');
66
const tryConnect = require('../lib/try_connect');
77
const errorReason = require('./utils').errorReason;
88

features/lib/try_connect.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const net = require('net');
4-
const Timeout = require('node-timeout');
54

65
module.exports = function tryConnect(host, port, callback) {
76
net.connect({ port: port, host: host })

features/lib/utils.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
'use strict';
22

33
const util = require('util');
4+
const { mkdir } = require('fs/promises');
5+
6+
function Timeout(ms, options) {
7+
return function (cb) {
8+
let called = false;
9+
const timer = setTimeout(() => {
10+
if (!called) {
11+
called = true;
12+
cb(options.err || new Error(`Operation timed out after ${ms}ms`));
13+
}
14+
}, ms);
15+
16+
return function (...args) {
17+
if (!called) {
18+
called = true;
19+
clearTimeout(timer);
20+
cb(...args);
21+
}
22+
};
23+
};
24+
}
25+
26+
function createDir(dir, callback) {
27+
mkdir(dir, { recursive: true })
28+
.then(() => callback(null))
29+
.catch(err => callback(err));
30+
}
431

532
module.exports = {
633

34+
createDir,
735
ensureDecimal: (i) => {
836
if (parseInt(i) === i) return i.toFixed(1);
937
else return i;
@@ -13,5 +41,6 @@ module.exports = {
1341
return err.signal ?
1442
'killed by signal ' + err.signal :
1543
'exited with code ' + err.code;
16-
}
44+
},
45+
Timeout
1746
};

features/step_definitions/distance_matrix.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function tableCodeOnlyParse(table, annotation, format, callback) {
4040
this.reprocessAndLoadData((e) => {
4141
if (e) return callback(e);
4242
var testRow = (row, ri, cb) => {
43-
var afterRequest = (err, res) => {
43+
var afterRequest = (err, res, body) => {
4444
if (err) return cb(err);
4545

4646
for (var k in row) {
@@ -57,8 +57,8 @@ function tableCodeOnlyParse(table, annotation, format, callback) {
5757

5858
var json;
5959
got.code = 'unknown';
60-
if (res.body.length) {
61-
json = JSON.parse(res.body);
60+
if (body.length) {
61+
json = JSON.parse(body);
6262
got.code = json.code;
6363
}
6464

@@ -126,13 +126,13 @@ function tableParse(table, noRoute, annotation, format, callback) {
126126
if (e) return callback(e);
127127
// compute matrix
128128

129-
this.requestTable(waypoints, params, (err, response) => {
129+
this.requestTable(waypoints, params, (err, response, body) => {
130130
if (err) return callback(err);
131-
if (!response.body.length) return callback(new Error('Invalid response body'));
131+
if (!body.length) return callback(new Error('Invalid response body'));
132132

133133
var result = [];
134134
if (format === 'json') {
135-
var json = JSON.parse(response.body);
135+
var json = JSON.parse(body);
136136

137137
if (annotation === 'fallback_speed_cells') {
138138
result = table.raw().map(row => row.map(() => ''));
@@ -154,7 +154,6 @@ function tableParse(table, noRoute, annotation, format, callback) {
154154
});
155155
}
156156
} else { //flatbuffers
157-
var body = response.body;
158157
var bytes = new Uint8Array(body.length);
159158
for (var indx = 0; indx < body.length; ++indx) {
160159
bytes[indx] = body.charCodeAt(indx);

features/step_definitions/matching.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var util = require('util');
4-
var polyline = require('polyline');
4+
var polyline = require('@mapbox/polyline');
55

66
module.exports = function () {
77
this.When(/^I match I should get$/, (table, callback) => {
@@ -10,15 +10,15 @@ module.exports = function () {
1010
this.reprocessAndLoadData((e) => {
1111
if (e) return callback(e);
1212
var testRow = (row, ri, cb) => {
13-
var afterRequest = (err, res) => {
13+
var afterRequest = (err, res, body) => {
1414
if (err) return cb(err);
1515
var json;
1616

1717
var headers = new Set(table.raw()[0]);
1818

1919
got.code = 'unknown';
20-
if (res.body.length) {
21-
json = JSON.parse(res.body);
20+
if (body.length) {
21+
json = JSON.parse(body);
2222
got.code = json.code;
2323
}
2424

features/step_definitions/nearest.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ module.exports = function () {
1212
var inNode = this.findNodeByName(row.in);
1313
if (!inNode) throw new Error(util.format('*** unknown in-node "%s"', row.in));
1414

15-
this.requestNearest(inNode, this.queryParams, (err, response) => {
15+
this.requestNearest(inNode, this.queryParams, (err, response, body) => {
1616
if (err) return cb(err);
1717
var coord;
1818
var headers = new Set(table.raw()[0]);
1919

20-
var got = { in: row.in};
20+
var got = { in: row.in };
2121

22-
if (response.body.length) {
23-
var json = JSON.parse(response.body);
22+
if (body.length) {
23+
var json = JSON.parse(body);
2424
got.code = json.code;
2525

2626
if (response.statusCode === 200) {
@@ -72,12 +72,11 @@ module.exports = function () {
7272
if (!outNode) throw new Error(util.format('*** unknown out-node "%s"', row.out));
7373

7474
this.queryParams.output = 'flatbuffers';
75-
this.requestNearest(inNode, this.queryParams, (err, response) => {
75+
this.requestNearest(inNode, this.queryParams, (err, response, body) => {
7676
if (err) return cb(err);
7777
var coord;
7878

79-
if (response.statusCode === 200 && response.body.length) {
80-
var body = response.body;
79+
if (response.statusCode === 200 && body.length) {
8180
var bytes = new Uint8Array(body.length);
8281
for (var indx = 0; indx < body.length; ++indx) {
8382
bytes[indx] = body.charCodeAt(indx);

features/step_definitions/requests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = function () {
66
if (e) return callback(e);
77
this.requestUrl(path, (err, res, body) => {
88
this.response = res;
9+
this.body = body;
910
callback(err, res, body);
1011
});
1112
});
@@ -25,7 +26,7 @@ module.exports = function () {
2526

2627
this.Then(/^status code should be (.+)$/, (code, callback) => {
2728
try {
28-
this.json = JSON.parse(this.response.body);
29+
this.json = JSON.parse(this.body);
2930
} catch(e) {
3031
return callback(e);
3132
}
@@ -35,7 +36,7 @@ module.exports = function () {
3536

3637
this.Then(/^status message should be "(.*?)"$/, (message, callback) => {
3738
try {
38-
this.json = JSON.parse(this.response.body);
39+
this.json = JSON.parse(this.body);
3940
} catch(e) {
4041
return callback(e);
4142
}

features/step_definitions/trip.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var util = require('util');
2-
var polyline = require('polyline');
2+
var polyline = require('@mapbox/polyline');
33

44
module.exports = function () {
55
function add(a, b) {
@@ -12,7 +12,7 @@ module.exports = function () {
1212
this.reprocessAndLoadData((e) => {
1313
if (e) return callback(e);
1414
var testRow = (row, ri, cb) => {
15-
var afterRequest = (err, res) => {
15+
var afterRequest = (err, res, body) => {
1616
if (err) return cb(err);
1717
var headers = new Set(table.raw()[0]);
1818

@@ -30,8 +30,8 @@ module.exports = function () {
3030

3131
var json;
3232
got.code = 'unknown';
33-
if (res.body.length) {
34-
json = JSON.parse(res.body);
33+
if (body.length) {
34+
json = JSON.parse(body);
3535
got.code = json.code;
3636
}
3737

features/support/cache.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const d3 = require('d3-queue');
44
const fs = require('fs');
55
const util = require('util');
66
const path = require('path');
7-
const mkdirp = require('mkdirp');
87
const hash = require('../lib/hash');
9-
const rimraf = require('rimraf');
8+
const { rm } = require('fs/promises');
9+
const { createDir } = require('../lib/utils');
1010

11-
module.exports = function() {
11+
module.exports = function () {
1212
this.initializeCache = (callback) => {
1313
this.getOSRMHash((err, osrmHash) => {
1414
if (err) return callback(err);
@@ -45,7 +45,7 @@ module.exports = function() {
4545
this.featureProcessedCacheDirectories[uri] = featureProcessedCacheDirectory;
4646

4747
d3.queue(1)
48-
.defer(mkdirp, featureProcessedCacheDirectory)
48+
.defer(createDir, featureProcessedCacheDirectory)
4949
.defer(this.cleanupFeatureCache.bind(this), featureCacheDirectory, hash)
5050
.defer(this.cleanupProcessedFeatureCache.bind(this), featureProcessedCacheDirectory, this.osrmHash)
5151
.awaitAll(callback);
@@ -61,33 +61,29 @@ module.exports = function() {
6161
this.cleanupProcessedFeatureCache = (directory, osrmHash, callback) => {
6262
let parentPath = path.resolve(path.join(directory, '..'));
6363
fs.readdir(parentPath, (err, files) => {
64+
if (err) return callback(err);
6465
let q = d3.queue();
65-
function runStats(path, callback) {
66-
fs.stat(path, (err, stat) => {
66+
files.forEach((f) => {
67+
let filePath = path.join(parentPath, f);
68+
fs.stat(filePath, (err, stat) => {
6769
if (err) return callback(err);
68-
callback(null, {file: path, stat: stat});
69-
});
70-
}
71-
files.map(f => { q.defer(runStats, path.join(parentPath, f)); });
72-
q.awaitAll((err, results) => {
73-
if (err) return callback(err);
74-
let q = d3.queue();
75-
results.forEach(r => {
76-
if (r.stat.isDirectory() && r.file.search(osrmHash) < 0) {
77-
q.defer(rimraf, r.file);
70+
if (stat.isDirectory() && filePath.search(osrmHash) < 0) {
71+
rm(filePath, { recursive: true, force: true });
7872
}
7973
});
80-
q.awaitAll(callback);
8174
});
75+
q.awaitAll(callback);
8276
});
8377
};
8478

8579
this.cleanupFeatureCache = (directory, featureHash, callback) => {
8680
let parentPath = path.resolve(path.join(directory, '..'));
8781
fs.readdir(parentPath, (err, files) => {
82+
if (err) return callback(err);
8883
let q = d3.queue();
89-
files.filter(name => { return name !== featureHash;})
90-
.map((f) => { q.defer(rimraf, path.join(parentPath, f)); });
84+
files.filter((name) => name !== featureHash).forEach((f) => {
85+
rm(path.join(parentPath, f), { recursive: true, force: true });
86+
});
9187
q.awaitAll(callback);
9288
});
9389
};

features/support/hooks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
var d3 = require('d3-queue');
44
var path = require('path');
5-
var mkdirp = require('mkdirp');
6-
var rimraf = require('rimraf');
5+
var fs = require('fs');
76
var OSM = require('../lib/osm');
87
var OSRMLoader = require('../lib/osrm_loader');
8+
const { createDir } = require('../lib/utils');
99

1010
module.exports = function () {
11-
this.registerHandler('BeforeFeatures', {timeout: 30000}, (features, callback) => {
11+
this.registerHandler('BeforeFeatures', { timeout: 30000 }, (features, callback) => {
1212
this.osrmLoader = new OSRMLoader(this);
1313
this.OSMDB = new OSM.DB();
1414

@@ -48,8 +48,8 @@ module.exports = function () {
4848
let logDir = path.join(this.LOGS_PATH, this.featureID);
4949
this.scenarioLogFile = path.join(logDir, this.scenarioID) + '.log';
5050
d3.queue(1)
51-
.defer(mkdirp, logDir)
52-
.defer(rimraf, this.scenarioLogFile)
51+
.defer(createDir, logDir)
52+
.defer((callback) => fs.rm(this.scenarioLogFile, { force: true }, callback))
5353
.awaitAll(callback);
5454
// uncomment to get path to logfile
5555
// console.log(' Writing logging output to ' + this.scenarioLogFile);

0 commit comments

Comments
 (0)