Skip to content

Commit 78d854c

Browse files
Trottjasnell
authored andcommitted
test: remove util from common
util is loaded just for one use of util.format(). Replace it with a string template. While we're at it, delete nearby lengthy comment justifying use of fs.readFileSync(). PR-URL: #3324 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed By: Evan Lucas <evanlucas@me.com>
1 parent c566c8b commit 78d854c

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

test/common.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var fs = require('fs');
55
var assert = require('assert');
66
var os = require('os');
77
var child_process = require('child_process');
8-
var util = require('util');
98

109

1110
exports.testDir = path.dirname(__filename);
@@ -410,15 +409,9 @@ exports.getServiceName = function getServiceName(port, protocol) {
410409
var serviceName = port.toString();
411410

412411
try {
413-
/*
414-
* I'm not a big fan of readFileSync, but reading /etc/services
415-
* asynchronously here would require implementing a simple line parser,
416-
* which seems overkill for a simple utility function that is not running
417-
* concurrently with any other one.
418-
*/
419412
var servicesContent = fs.readFileSync(etcServicesFileName,
420413
{ encoding: 'utf8'});
421-
var regexp = util.format('^(\\w+)\\s+\\s%d/%s\\s', port, protocol);
414+
var regexp = `^(\\w+)\\s+\\s${port}/${protocol}\\s`;
422415
var re = new RegExp(regexp, 'm');
423416

424417
var matches = re.exec(servicesContent);

0 commit comments

Comments
 (0)