11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst installed = require('../../../../lib/utils/completion/installed-shallow.js') 31cb0ef41Sopenharmony_ciconst mockNpm = require('../../../fixtures/mock-npm') 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst mockShallow = async (t, config) => { 61cb0ef41Sopenharmony_ci const res = await mockNpm(t, { 71cb0ef41Sopenharmony_ci globalPrefixDir: { 81cb0ef41Sopenharmony_ci node_modules: { 91cb0ef41Sopenharmony_ci x: {}, 101cb0ef41Sopenharmony_ci '@scope': { 111cb0ef41Sopenharmony_ci y: {}, 121cb0ef41Sopenharmony_ci }, 131cb0ef41Sopenharmony_ci }, 141cb0ef41Sopenharmony_ci }, 151cb0ef41Sopenharmony_ci prefixDir: { 161cb0ef41Sopenharmony_ci node_modules: { 171cb0ef41Sopenharmony_ci a: {}, 181cb0ef41Sopenharmony_ci '@scope': { 191cb0ef41Sopenharmony_ci b: {}, 201cb0ef41Sopenharmony_ci }, 211cb0ef41Sopenharmony_ci }, 221cb0ef41Sopenharmony_ci }, 231cb0ef41Sopenharmony_ci config: { global: false, ...config }, 241cb0ef41Sopenharmony_ci }) 251cb0ef41Sopenharmony_ci return res 261cb0ef41Sopenharmony_ci} 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_cit.test('global not set, include globals with -g', async t => { 291cb0ef41Sopenharmony_ci const { npm } = await mockShallow(t) 301cb0ef41Sopenharmony_ci const opt = { conf: { argv: { remain: [] } } } 311cb0ef41Sopenharmony_ci const res = await installed(npm, opt) 321cb0ef41Sopenharmony_ci t.strictSame(res.sort(), [ 331cb0ef41Sopenharmony_ci '@scope/y -g', 341cb0ef41Sopenharmony_ci 'x -g', 351cb0ef41Sopenharmony_ci 'a', 361cb0ef41Sopenharmony_ci '@scope/b', 371cb0ef41Sopenharmony_ci ].sort()) 381cb0ef41Sopenharmony_ci}) 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cit.test('global set, include globals and not locals', async t => { 411cb0ef41Sopenharmony_ci const { npm } = await mockShallow(t, { global: true }) 421cb0ef41Sopenharmony_ci const opt = { conf: { argv: { remain: [] } } } 431cb0ef41Sopenharmony_ci const res = await installed(npm, opt) 441cb0ef41Sopenharmony_ci t.strictSame(res.sort(), [ 451cb0ef41Sopenharmony_ci '@scope/y', 461cb0ef41Sopenharmony_ci 'x', 471cb0ef41Sopenharmony_ci ].sort()) 481cb0ef41Sopenharmony_ci}) 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_cit.test('more than 3 items in argv, skip it', async t => { 511cb0ef41Sopenharmony_ci const { npm } = await mockShallow(t) 521cb0ef41Sopenharmony_ci const opt = { conf: { argv: { remain: [1, 2, 3, 4, 5, 6] } } } 531cb0ef41Sopenharmony_ci const res = await installed(npm, opt) 541cb0ef41Sopenharmony_ci t.strictSame(res, null) 551cb0ef41Sopenharmony_ci}) 56