• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5
6const path = require('path');
7const exec = require('child_process').exec;
8const assert = require('assert');
9const fs = require('fs');
10const fixtures = require('../common/fixtures');
11
12const tmpdir = require('../common/tmpdir');
13tmpdir.refresh();
14const npmSandbox = path.join(tmpdir.path, 'npm-sandbox');
15fs.mkdirSync(npmSandbox);
16const homeDir = path.join(tmpdir.path, 'home');
17fs.mkdirSync(homeDir);
18const installDir = path.join(tmpdir.path, 'install-dir');
19fs.mkdirSync(installDir);
20
21const npmPath = path.join(
22  __dirname,
23  '..',
24  '..',
25  'deps',
26  'npm',
27  'bin',
28  'npm-cli.js'
29);
30
31const pkgContent = JSON.stringify({
32  dependencies: {
33    'package-name': fixtures.path('packages/main')
34  }
35});
36
37const pkgPath = path.join(installDir, 'package.json');
38
39fs.writeFileSync(pkgPath, pkgContent);
40
41const env = { ...process.env,
42              PATH: path.dirname(process.execPath),
43              NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'),
44              NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'),
45              NPM_CONFIG_AUDIT: false,
46              NPM_CONFIG_UPDATE_NOTIFIER: false,
47              HOME: homeDir };
48
49exec(`${process.execPath} ${npmPath} install`, {
50  cwd: installDir,
51  env: env
52}, common.mustCall(handleExit));
53
54function handleExit(error, stdout, stderr) {
55  const code = error ? error.code : 0;
56  const signalCode = error ? error.signal : null;
57
58  if (code !== 0) {
59    process.stderr.write(stderr);
60  }
61
62  assert.strictEqual(code, 0, `npm install got error code ${code}`);
63  assert.strictEqual(signalCode, null, `unexpected signal: ${signalCode}`);
64  assert(fs.existsSync(`${installDir}/node_modules/package-name`));
65}
66