Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/fixtures/npm-install/example/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.value = 42;
5 changes: 5 additions & 0 deletions test/fixtures/npm-install/example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "example",
"version": "1.0.0",
"main": "example.js"
}
Empty file.
5 changes: 5 additions & 0 deletions test/fixtures/npm-install/install-dir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"example": "../example"
}
}
Empty file.
Empty file.
73 changes: 23 additions & 50 deletions test/parallel/test-npm-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,37 @@ if (common.isInsideDirWithUnusualChars)
common.skip('npm does not support this install path');

const path = require('path');
const exec = require('child_process').exec;
const assert = require('assert');
const fs = require('fs');
const fixtures = require('../common/fixtures');
const { spawnSyncAndAssert } = require('../common/child_process');

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const npmSandbox = tmpdir.resolve('npm-sandbox');
fs.mkdirSync(npmSandbox);
const homeDir = tmpdir.resolve('home');
fs.mkdirSync(homeDir);
const installDir = tmpdir.resolve('install-dir');
fs.mkdirSync(installDir);

const npmPath = path.join(
__dirname,
'..',
'..',
'deps',
'npm',
'bin',
'npm-cli.js'
);

const pkgContent = JSON.stringify({
dependencies: {
'package-name': fixtures.path('packages/main')
}
});

const pkgPath = path.join(installDir, 'package.json');
// Copy fixtures/npm-install to the tmpdir for testing
fs.cpSync(fixtures.path('npm-install'), tmpdir.path, { recursive: true });

fs.writeFileSync(pkgPath, pkgContent);
const npmPath = path.join(__dirname, '..', '..', 'deps', 'npm', 'bin', 'npm-cli.js');

const env = { ...process.env,
PATH: path.dirname(process.execPath),
NODE: process.execPath,
NPM: npmPath,
NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'),
NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'),
NPM_CONFIG_AUDIT: false,
NPM_CONFIG_UPDATE_NOTIFIER: false,
HOME: homeDir };
const env = {
...process.env,
PATH: path.dirname(process.execPath),
NODE: process.execPath,
NPM: npmPath,
NPM_CONFIG_PREFIX: tmpdir.resolve('npm-prefix'),
NPM_CONFIG_TMP: tmpdir.resolve('npm-tmp'),
NPM_CONFIG_AUDIT: false,
NPM_CONFIG_UPDATE_NOTIFIER: false,
HOME: tmpdir.resolve('home'),
};

exec(`"${common.isWindows ? process.execPath : '$NODE'}" "${common.isWindows ? npmPath : '$NPM'}" install`, {
cwd: installDir,
env: env
}, common.mustCall(handleExit));

function handleExit(error, stdout, stderr) {
const code = error ? error.code : 0;
const signalCode = error ? error.signal : null;

if (code !== 0) {
process.stderr.write(stderr);
}
const installDir = tmpdir.resolve('install-dir');
spawnSyncAndAssert(
process.execPath,
[npmPath, 'install'],
{ cwd: installDir, env },
{}
);

assert.strictEqual(code, 0, `npm install got error code ${code}`);
assert.strictEqual(signalCode, null, `unexpected signal: ${signalCode}`);
assert(fs.existsSync(`${installDir}/node_modules/package-name`));
}
assert(fs.existsSync(path.join(installDir, 'node_modules', 'example')));
Loading