summaryrefslogtreecommitdiff
path: root/test/parallel/test-npm-install.js
blob: 0c2e4df52f986319ba3fab353c529ee037c7bb6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const common = require('../common');

const path = require('path');
const spawn = require('child_process').spawn;
const assert = require('assert');
const fs = require('fs');

common.refreshTmpDir();

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

const args = [
  npmPath,
  'install'
];

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

const pkgPath = path.join(common.tmpDir, 'package.json');

fs.writeFileSync(pkgPath, pkgContent);

const proc = spawn(process.execPath, args, {
  cwd: common.tmpDir
});

function handleExit(code, signalCode) {
  assert.equal(code, 0, 'npm install should run without an error');
  assert.ok(signalCode === null, 'signalCode should be null');
  assert.doesNotThrow(function() {
    fs.accessSync(common.tmpDir + '/node_modules/package-name');
  });
}

proc.on('exit', common.mustCall(handleExit));