• 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-engine-reqs',
14  version: '0.0.1',
15  description: 'fixture',
16  engines: {
17    node: '1.0.0-not-a-real-version'
18  }
19}
20
21test('setup', function (t) {
22  setup()
23  t.end()
24})
25
26var INSTALL_OPTS = ['--loglevel', 'silly']
27var EXEC_OPTS = {cwd: installIn}
28test('install bad engine', function (t) {
29  common.npm(['install', '--engine-strict', installFrom].concat(INSTALL_OPTS), EXEC_OPTS, function (err, code) {
30    t.ifError(err, 'npm ran without issue')
31    t.is(code, 1, 'npm install refused to install a package in itself')
32    t.end()
33  })
34})
35test('force install bad engine', function (t) {
36  common.npm(['install', '--engine-strict', '--force', installFrom].concat(INSTALL_OPTS), EXEC_OPTS, function (err, code) {
37    t.ifError(err, 'npm ran without issue')
38    t.is(code, 0, 'npm install happily installed a package in itself with --force')
39    t.end()
40  })
41})
42
43test('warns on bad engine not strict', function (t) {
44  common.npm(['install', '--json', installFrom], EXEC_OPTS, function (err, code, stdout, stderr) {
45    t.ifError(err, 'npm ran without issue')
46    t.is(code, 0, 'result code')
47    var result = JSON.parse(stdout)
48    t.match(result.warnings[0], /Unsupported engine/, 'reason for optional failure in JSON')
49    t.match(result.warnings[0], /1.0.0-not-a-real-version/, 'should print mismatch version info')
50    t.match(result.warnings[0], /Not compatible with your version of node/, 'incompatibility message')
51    t.done()
52  })
53})
54
55function setup () {
56  mkdirp.sync(path.resolve(installFrom, 'node_modules'))
57  fs.writeFileSync(
58    path.join(installFrom, 'package.json'),
59    JSON.stringify(json, null, 2)
60  )
61  mkdirp.sync(path.resolve(installIn, 'node_modules'))
62  process.chdir(base)
63}
64