• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var path = require('path')
3var fs = require('fs')
4var test = require('tap').test
5var mkdirp = require('mkdirp')
6var common = require('../common-tap.js')
7
8var base = common.pkg
9var installFrom = path.join(base, 'from')
10var installIn = path.join(base, 'in')
11
12var json = {
13  name: 'check-os-reqs',
14  version: '0.0.1',
15  description: 'fixture',
16  os: ['fake-os']
17}
18
19test('setup', function (t) {
20  setup()
21  t.end()
22})
23
24var INSTALL_OPTS = ['--loglevel', 'silly']
25var EXEC_OPTS = {cwd: installIn}
26
27test('install bad os', function (t) {
28  common.npm(['install', installFrom].concat(INSTALL_OPTS), EXEC_OPTS, function (err, code) {
29    t.ifError(err, 'npm ran without issue')
30    t.is(code, 1, 'npm install refused to install a package in itself')
31    t.end()
32  })
33})
34test('force install bad os', function (t) {
35  common.npm(['install', '--force', installFrom].concat(INSTALL_OPTS), EXEC_OPTS, function (err, code) {
36    t.ifError(err, 'npm ran without issue')
37    t.is(code, 0, 'npm install happily installed a package in itself with --force')
38    t.end()
39  })
40})
41
42function setup () {
43  mkdirp.sync(path.resolve(installFrom, 'node_modules'))
44  fs.writeFileSync(
45    path.join(installFrom, 'package.json'),
46    JSON.stringify(json, null, 2)
47  )
48  mkdirp.sync(path.resolve(installIn, 'node_modules'))
49  process.chdir(base)
50}
51