1const t = require('tap') 2const _mockNpm = require('../../fixtures/mock-npm') 3 4// XXX: this test has been refactored to use the new mockNpm 5// but it still only asserts the options passed to arborist. 6// TODO: make this really test npm update scenarios 7const mockUpdate = async (t, { exec = [], ...opts } = {}) => { 8 let ctor = null 9 let reify = null 10 let finish = null 11 12 const res = await _mockNpm(t, { 13 ...opts, 14 mocks: { 15 '@npmcli/arborist': class Arborist { 16 constructor (o) { 17 ctor = o 18 } 19 20 reify (o) { 21 reify = o 22 } 23 }, 24 '{LIB}/utils/reify-finish.js': (_, o) => { 25 finish = o 26 }, 27 }, 28 }) 29 30 await res.npm.exec('update', exec) 31 32 return { 33 ...res, 34 ctor, 35 reify, 36 finish, 37 } 38} 39 40t.test('no args', async t => { 41 const { ctor, reify, finish, prefix } = await mockUpdate(t) 42 43 t.equal(ctor.path, prefix, 'path') 44 t.equal(ctor.save, false, 'should default to save=false') 45 t.equal(ctor.workspaces, undefined, 'workspaces') 46 47 t.equal(reify.update, true, 'should update all deps') 48 49 t.equal(finish.constructor.name, 'Arborist') 50}) 51 52t.test('with args', async t => { 53 const { ctor, reify } = await mockUpdate(t, { 54 config: { save: true }, 55 exec: ['ipt'], 56 }) 57 58 t.equal(ctor.save, true, 'save') 59 t.strictSame(reify.update, ['ipt'], 'ipt') 60}) 61 62t.test('update --depth=<number>', async t => { 63 const { logs } = await mockUpdate(t, { 64 config: { depth: 1 }, 65 }) 66 67 const [title, msg] = logs.warn[0] 68 t.equal(title, 'update', 'should print expected title') 69 t.match( 70 msg, 71 /The --depth option no longer has any effect/, 72 'should print expected warning message' 73 ) 74}) 75 76t.test('update --global', async t => { 77 const { ctor, globalPrefix } = await mockUpdate(t, { 78 config: { global: true }, 79 }) 80 81 t.match(ctor.path, globalPrefix) 82 t.ok(ctor.path.startsWith(globalPrefix)) 83}) 84