MCPcopy Index your code
hub / github.com/nodejs/node / runNPMPackageTests

Function runNPMPackageTests

tools/test-npm-package.js:39–107  ·  view source on GitHub ↗
({ srcDir, install, rebuild, testArgs, logfile })

Source from the content-addressed store, hash-verified

37}
38
39function runNPMPackageTests({ srcDir, install, rebuild, testArgs, logfile }) {
40 // Make sure we don't conflict with concurrent test runs
41 const srcHash = createHash('md5').update(srcDir).digest('hex');
42 tmpDir.path = `${tmpDir.path}.npm.${srcHash}`;
43 tmpDir.refresh();
44
45 const npmCache = path.join(tmpDir.path, 'npm-cache');
46 const npmPrefix = path.join(tmpDir.path, 'npm-prefix');
47 const npmTmp = path.join(tmpDir.path, 'npm-tmp');
48 const npmUserconfig = path.join(tmpDir.path, 'npm-userconfig');
49 const pkgDir = path.join(tmpDir.path, 'pkg');
50
51 spawnCopyDeepSync(srcDir, pkgDir);
52
53 const npmOptions = {
54 cwd: pkgDir,
55 env: Object.assign({}, process.env, {
56 'npm_config_cache': npmCache,
57 'npm_config_prefix': npmPrefix,
58 'npm_config_tmp': npmTmp,
59 'npm_config_userconfig': npmUserconfig,
60 }),
61 stdio: 'inherit',
62 };
63
64 if (common.isWindows) {
65 npmOptions.env.home = tmpDir.path;
66 npmOptions.env.Path = `${nodePath};${process.env.Path}`;
67 } else {
68 npmOptions.env.HOME = tmpDir.path;
69 npmOptions.env.PATH = `${nodePath}:${process.env.PATH}`;
70 }
71
72 if (rebuild) {
73 spawnSync(process.execPath, [
74 npmBin,
75 'rebuild',
76 ], npmOptions);
77 }
78
79 if (install) {
80 spawnSync(process.execPath, [
81 npmBin,
82 'install',
83 '--ignore-scripts',
84 '--no-save',
85 ], npmOptions);
86 }
87
88 const testChild = spawn(process.execPath, [
89 npmBin,
90 '--silent',
91 'run',
92 ...testArgs,
93 ], Object.assign({}, npmOptions, { stdio: 'pipe' }));
94
95 testChild.stdout.pipe(process.stdout);
96 testChild.stderr.pipe(process.stderr);

Callers 1

Calls 11

createHashFunction · 0.85
spawnCopyDeepSyncFunction · 0.85
rmdirSyncFunction · 0.85
assignMethod · 0.80
updateMethod · 0.65
spawnSyncFunction · 0.50
spawnFunction · 0.50
createWriteStreamFunction · 0.50
refreshMethod · 0.45
joinMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…