Skip to content

Commit

Permalink
test: use module.exports consistently
Browse files Browse the repository at this point in the history
PR-URL: #22557
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
jasnell authored and targos committed Sep 2, 2018
1 parent 280070f commit 5c6d041
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
44 changes: 24 additions & 20 deletions test/common/shared-lib-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,52 @@
const common = require('../common');
const path = require('path');

const kNodeShared = Boolean(process.config.variables.node_shared);
const kShlibSuffix = process.config.variables.shlib_suffix;
const kExecPath = path.dirname(process.execPath);

// If node executable is linked to shared lib, need to take care about the
// shared lib path.
exports.addLibraryPath = function(env) {
if (!process.config.variables.node_shared) {
function addLibraryPath(env) {
if (!kNodeShared) {
return;
}

env = env || process.env;

env.LD_LIBRARY_PATH =
(env.LD_LIBRARY_PATH ? env.LD_LIBRARY_PATH + path.delimiter : '') +
path.join(path.dirname(process.execPath), 'lib.target');
path.join(kExecPath, 'lib.target');
// For AIX.
env.LIBPATH =
(env.LIBPATH ? env.LIBPATH + path.delimiter : '') +
path.join(path.dirname(process.execPath), 'lib.target');
path.join(kExecPath, 'lib.target');
// For Mac OSX.
env.DYLD_LIBRARY_PATH =
(env.DYLD_LIBRARY_PATH ? env.DYLD_LIBRARY_PATH + path.delimiter : '') +
path.dirname(process.execPath);
kExecPath;
// For Windows.
env.PATH =
(env.PATH ? env.PATH + path.delimiter : '') +
path.dirname(process.execPath);
};
env.PATH = (env.PATH ? env.PATH + path.delimiter : '') + kExecPath;
}

// Get the full path of shared lib.
exports.getSharedLibPath = function() {
function getSharedLibPath() {
if (common.isWindows) {
return path.join(path.dirname(process.execPath), 'node.dll');
return path.join(kExecPath, 'node.dll');
} else if (common.isOSX) {
return path.join(path.dirname(process.execPath),
`libnode.${process.config.variables.shlib_suffix}`);
return path.join(kExecPath, `libnode.${kShlibSuffix}`);
} else {
return path.join(path.dirname(process.execPath),
'lib.target',
`libnode.${process.config.variables.shlib_suffix}`);
return path.join(kExecPath, 'lib.target', `libnode.${kShlibSuffix}`);
}
};
}

// Get the binary path of stack frames.
exports.getBinaryPath = function() {
return process.config.variables.node_shared ?
exports.getSharedLibPath() : process.execPath;
function getBinaryPath() {
return kNodeShared ? getSharedLibPath() : process.execPath;
}

module.exports = {
addLibraryPath,
getBinaryPath,
getSharedLibPath
};
14 changes: 10 additions & 4 deletions test/common/tmpdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ let tmpdirName = '.tmp';
if (process.env.TEST_THREAD_ID) {
tmpdirName += `.${process.env.TEST_THREAD_ID}`;
}
exports.path = path.join(testRoot, tmpdirName);

exports.refresh = () => {
rimrafSync(exports.path);
fs.mkdirSync(exports.path);
const tmpPath = path.join(testRoot, tmpdirName);

function refresh() {
rimrafSync(this.path);
fs.mkdirSync(this.path);
}

module.exports = {
path: tmpPath,
refresh
};

0 comments on commit 5c6d041

Please sign in to comment.