1'use strict' 2const path = require('path') 3const test = require('tap').test 4const mr = require('npm-registry-mock') 5const Tacks = require('tacks') 6const fs = require('fs') 7const File = Tacks.File 8const Dir = Tacks.Dir 9const common = require('../common-tap.js') 10 11const basedir = common.pkg 12const testdir = path.join(basedir, 'testdir') 13const cachedir = common.cache 14const globaldir = path.join(basedir, 'global') 15const tmpdir = path.join(basedir, 'tmp') 16 17const conf = { 18 cwd: testdir, 19 stdio: [0, 1, 2], 20 env: Object.assign({}, process.env, { 21 npm_config_cache: cachedir, 22 npm_config_tmp: tmpdir, 23 npm_config_prefix: globaldir, 24 npm_config_registry: common.registry, 25 npm_config_loglevel: 'silly' 26 }) 27} 28 29let server 30const fixture = new Tacks(Dir({ 31 cache: Dir(), 32 global: Dir(), 33 tmp: Dir(), 34 testdir: Dir({ 35 example: Dir({ 36 'package.json': File({ 37 name: 'example', 38 version: '1.0.0' 39 }) 40 }), 41 'package.json': File({ 42 name: 'save-optional', 43 version: '1.0.0' 44 }) 45 }) 46})) 47 48function setup () { 49 cleanup() 50 fixture.create(basedir) 51} 52 53function cleanup () { 54 fixture.remove(basedir) 55} 56 57test('setup', function (t) { 58 setup() 59 mr({port: common.port, throwOnUnmatched: true}, function (err, s) { 60 if (err) throw err 61 server = s 62 t.done() 63 }) 64}) 65 66test('example', function (t) { 67 common.npm(['install', '-O', '--package-lock-only', 'file:example'], conf, function (err, code) { 68 if (err) throw err 69 t.is(code, 0, 'command ran ok') 70 const plock = JSON.parse(fs.readFileSync(`${testdir}/package-lock.json`)) 71 t.like(plock, { dependencies: { example: { optional: true } } }, 'optional status saved') 72 // your assertions here 73 t.done() 74 }) 75}) 76 77test('cleanup', function (t) { 78 server.close() 79 cleanup() 80 t.done() 81}) 82