1'use strict' 2var path = require('path') 3var test = require('tap').test 4var Tacks = require('tacks') 5var File = Tacks.File 6var Dir = Tacks.Dir 7var common = require('../common-tap.js') 8 9var basedir = common.pkg 10var testdir = path.join(basedir, 'testdir') 11var cachedir = common.cache 12var globaldir = path.join(basedir, 'global') 13var tmpdir = path.join(basedir, 'tmp') 14 15var conf = { 16 cwd: testdir, 17 env: Object.assign({}, process.env, { 18 npm_config_cache: cachedir, 19 npm_config_tmp: tmpdir, 20 npm_config_prefix: globaldir, 21 npm_config_registry: common.registry, 22 npm_config_loglevel: 'warn' 23 }) 24} 25 26var fixture = new Tacks(Dir({ 27 cache: Dir(), 28 global: Dir(), 29 tmp: Dir(), 30 testdir: Dir({ 31 mod1: Dir({ 32 'package.json': File({ 33 name: 'mod1', 34 version: '1.0.0', 35 scripts: {}, 36 'optionalDependencies': { 37 'mod2': 'file:../mod2' 38 }, 39 os: ['nosuchos'] 40 }) 41 }), 42 mod2: Dir({ 43 'package.json': File({ 44 name: 'mod2', 45 version: '1.0.0', 46 scripts: {}, 47 os: ['nosuchos'] 48 }) 49 }), 50 'npm-shrinkwrap.json': File({ 51 name: 'shrinkwrap-optional-platform', 52 version: '1.0.0', 53 dependencies: { 54 mod1: { 55 version: '1.0.0', 56 resolved: 'file:mod1', 57 optional: true 58 }, 59 mod2: { 60 version: '1.0.0', 61 resolved: 'file:mod2', 62 optional: true 63 } 64 } 65 }), 66 'package.json': File({ 67 name: 'shrinkwrap-optional-platform', 68 version: '1.0.0', 69 optionalDependencies: { 70 mod1: 'file:mod1' 71 }, 72 description: 'x', 73 repository: 'x', 74 license: 'Artistic-2.0' 75 }) 76 }) 77})) 78 79function setup () { 80 cleanup() 81 fixture.create(basedir) 82} 83 84function cleanup () { 85 fixture.remove(basedir) 86} 87 88test('setup', function (t) { 89 setup() 90 t.done() 91}) 92 93test('example', function (t) { 94 common.npm(['install'], conf, function (err, code, stdout, stderr) { 95 if (err) throw err 96 t.is(code, 0, 'install ran ok') 97 t.comment(stdout.trim()) 98 t.comment(stderr.trim()) 99 t.notMatch(stderr, /Exit status 1/, 'did not try to install opt dep') 100 t.done() 101 }) 102}) 103 104test('cleanup', function (t) { 105 cleanup() 106 t.done() 107}) 108