11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst mockNpm = require('../../fixtures/mock-npm') 31cb0ef41Sopenharmony_ciconst { stripVTControlCharacters } = require('node:util') 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst mockHook = async (t, { hookResponse, ...npmOpts } = {}) => { 61cb0ef41Sopenharmony_ci const now = Date.now() 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci let hookArgs = null 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci const pkgTypes = { 111cb0ef41Sopenharmony_ci semver: 'package', 121cb0ef41Sopenharmony_ci '@npmcli': 'scope', 131cb0ef41Sopenharmony_ci npm: 'owner', 141cb0ef41Sopenharmony_ci } 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci const libnpmhook = { 171cb0ef41Sopenharmony_ci add: async (pkg, uri, secret, opts) => { 181cb0ef41Sopenharmony_ci hookArgs = { pkg, uri, secret, opts } 191cb0ef41Sopenharmony_ci return { id: 1, name: pkg, type: pkgTypes[pkg], endpoint: uri } 201cb0ef41Sopenharmony_ci }, 211cb0ef41Sopenharmony_ci ls: async opts => { 221cb0ef41Sopenharmony_ci hookArgs = opts 231cb0ef41Sopenharmony_ci let id = 0 241cb0ef41Sopenharmony_ci if (hookResponse) { 251cb0ef41Sopenharmony_ci return hookResponse 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci return Object.keys(pkgTypes).map(name => ({ 291cb0ef41Sopenharmony_ci id: ++id, 301cb0ef41Sopenharmony_ci name, 311cb0ef41Sopenharmony_ci type: pkgTypes[name], 321cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 331cb0ef41Sopenharmony_ci last_delivery: id % 2 === 0 ? now : undefined, 341cb0ef41Sopenharmony_ci })) 351cb0ef41Sopenharmony_ci }, 361cb0ef41Sopenharmony_ci rm: async (id, opts) => { 371cb0ef41Sopenharmony_ci hookArgs = { id, opts } 381cb0ef41Sopenharmony_ci const pkg = Object.keys(pkgTypes)[0] 391cb0ef41Sopenharmony_ci return { 401cb0ef41Sopenharmony_ci id: 1, 411cb0ef41Sopenharmony_ci name: pkg, 421cb0ef41Sopenharmony_ci type: pkgTypes[pkg], 431cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci }, 461cb0ef41Sopenharmony_ci update: async (id, uri, secret, opts) => { 471cb0ef41Sopenharmony_ci hookArgs = { id, uri, secret, opts } 481cb0ef41Sopenharmony_ci const pkg = Object.keys(pkgTypes)[0] 491cb0ef41Sopenharmony_ci return { id, name: pkg, type: pkgTypes[pkg], endpoint: uri } 501cb0ef41Sopenharmony_ci }, 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci const mock = await mockNpm(t, { 541cb0ef41Sopenharmony_ci ...npmOpts, 551cb0ef41Sopenharmony_ci command: 'hook', 561cb0ef41Sopenharmony_ci mocks: { 571cb0ef41Sopenharmony_ci libnpmhook, 581cb0ef41Sopenharmony_ci ...npmOpts.mocks, 591cb0ef41Sopenharmony_ci }, 601cb0ef41Sopenharmony_ci }) 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci return { 631cb0ef41Sopenharmony_ci ...mock, 641cb0ef41Sopenharmony_ci now, 651cb0ef41Sopenharmony_ci hookArgs: () => hookArgs, 661cb0ef41Sopenharmony_ci } 671cb0ef41Sopenharmony_ci} 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_cit.test('npm hook no args', async t => { 701cb0ef41Sopenharmony_ci const { hook } = await mockHook(t) 711cb0ef41Sopenharmony_ci await t.rejects(hook.exec([]), hook.usage, 'throws usage with no arguments') 721cb0ef41Sopenharmony_ci}) 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_cit.test('npm hook add', async t => { 751cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t) 761cb0ef41Sopenharmony_ci await hook.exec(['add', 'semver', 'https://google.com', 'some-secret']) 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci t.match( 791cb0ef41Sopenharmony_ci hookArgs(), 801cb0ef41Sopenharmony_ci { 811cb0ef41Sopenharmony_ci pkg: 'semver', 821cb0ef41Sopenharmony_ci uri: 'https://google.com', 831cb0ef41Sopenharmony_ci secret: 'some-secret', 841cb0ef41Sopenharmony_ci opts: npm.flatOptions, 851cb0ef41Sopenharmony_ci }, 861cb0ef41Sopenharmony_ci 'provided the correct arguments to libnpmhook' 871cb0ef41Sopenharmony_ci ) 881cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['+ semver -> https://google.com'], 'prints the correct output') 891cb0ef41Sopenharmony_ci}) 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_cit.test('npm hook add - correct owner hook output', async t => { 921cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t) 931cb0ef41Sopenharmony_ci await hook.exec(['add', '~npm', 'https://google.com', 'some-secret']) 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci t.match( 961cb0ef41Sopenharmony_ci hookArgs(), 971cb0ef41Sopenharmony_ci { 981cb0ef41Sopenharmony_ci pkg: '~npm', 991cb0ef41Sopenharmony_ci uri: 'https://google.com', 1001cb0ef41Sopenharmony_ci secret: 'some-secret', 1011cb0ef41Sopenharmony_ci opts: npm.flatOptions, 1021cb0ef41Sopenharmony_ci }, 1031cb0ef41Sopenharmony_ci 'provided the correct arguments to libnpmhook' 1041cb0ef41Sopenharmony_ci ) 1051cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['+ ~npm -> https://google.com'], 'prints the correct output') 1061cb0ef41Sopenharmony_ci}) 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_cit.test('npm hook add - correct scope hook output', async t => { 1091cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t) 1101cb0ef41Sopenharmony_ci await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret']) 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci t.match( 1131cb0ef41Sopenharmony_ci hookArgs(), 1141cb0ef41Sopenharmony_ci { 1151cb0ef41Sopenharmony_ci pkg: '@npmcli', 1161cb0ef41Sopenharmony_ci uri: 'https://google.com', 1171cb0ef41Sopenharmony_ci secret: 'some-secret', 1181cb0ef41Sopenharmony_ci opts: npm.flatOptions, 1191cb0ef41Sopenharmony_ci }, 1201cb0ef41Sopenharmony_ci 'provided the correct arguments to libnpmhook' 1211cb0ef41Sopenharmony_ci ) 1221cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['+ @npmcli -> https://google.com'], 'prints the correct output') 1231cb0ef41Sopenharmony_ci}) 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_cit.test('npm hook add - unicode output', async t => { 1261cb0ef41Sopenharmony_ci const config = { 1271cb0ef41Sopenharmony_ci unicode: true, 1281cb0ef41Sopenharmony_ci } 1291cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 1301cb0ef41Sopenharmony_ci config, 1311cb0ef41Sopenharmony_ci }) 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci await hook.exec(['add', 'semver', 'https://google.com', 'some-secret']) 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci t.match( 1361cb0ef41Sopenharmony_ci hookArgs(), 1371cb0ef41Sopenharmony_ci { 1381cb0ef41Sopenharmony_ci pkg: 'semver', 1391cb0ef41Sopenharmony_ci uri: 'https://google.com', 1401cb0ef41Sopenharmony_ci secret: 'some-secret', 1411cb0ef41Sopenharmony_ci opts: npm.flatOptions, 1421cb0ef41Sopenharmony_ci }, 1431cb0ef41Sopenharmony_ci 'provided the correct arguments to libnpmhook' 1441cb0ef41Sopenharmony_ci ) 1451cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['+ semver ➜ https://google.com'], 'prints the correct output') 1461cb0ef41Sopenharmony_ci}) 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_cit.test('npm hook add - json output', async t => { 1491cb0ef41Sopenharmony_ci const config = { 1501cb0ef41Sopenharmony_ci json: true, 1511cb0ef41Sopenharmony_ci } 1521cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 1531cb0ef41Sopenharmony_ci config, 1541cb0ef41Sopenharmony_ci }) 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ci await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret']) 1571cb0ef41Sopenharmony_ci 1581cb0ef41Sopenharmony_ci t.match( 1591cb0ef41Sopenharmony_ci hookArgs(), 1601cb0ef41Sopenharmony_ci { 1611cb0ef41Sopenharmony_ci pkg: '@npmcli', 1621cb0ef41Sopenharmony_ci uri: 'https://google.com', 1631cb0ef41Sopenharmony_ci secret: 'some-secret', 1641cb0ef41Sopenharmony_ci opts: npm.flatOptions, 1651cb0ef41Sopenharmony_ci }, 1661cb0ef41Sopenharmony_ci 'provided the correct arguments to libnpmhook' 1671cb0ef41Sopenharmony_ci ) 1681cb0ef41Sopenharmony_ci t.strictSame( 1691cb0ef41Sopenharmony_ci JSON.parse(outputs[0][0]), 1701cb0ef41Sopenharmony_ci { 1711cb0ef41Sopenharmony_ci id: 1, 1721cb0ef41Sopenharmony_ci name: '@npmcli', 1731cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 1741cb0ef41Sopenharmony_ci type: 'scope', 1751cb0ef41Sopenharmony_ci }, 1761cb0ef41Sopenharmony_ci 'prints the correct json output' 1771cb0ef41Sopenharmony_ci ) 1781cb0ef41Sopenharmony_ci}) 1791cb0ef41Sopenharmony_ci 1801cb0ef41Sopenharmony_cit.test('npm hook add - parseable output', async t => { 1811cb0ef41Sopenharmony_ci const config = { 1821cb0ef41Sopenharmony_ci parseable: true, 1831cb0ef41Sopenharmony_ci } 1841cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 1851cb0ef41Sopenharmony_ci config, 1861cb0ef41Sopenharmony_ci }) 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret']) 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_ci t.match( 1911cb0ef41Sopenharmony_ci hookArgs(), 1921cb0ef41Sopenharmony_ci { 1931cb0ef41Sopenharmony_ci pkg: '@npmcli', 1941cb0ef41Sopenharmony_ci uri: 'https://google.com', 1951cb0ef41Sopenharmony_ci secret: 'some-secret', 1961cb0ef41Sopenharmony_ci opts: npm.flatOptions, 1971cb0ef41Sopenharmony_ci }, 1981cb0ef41Sopenharmony_ci 'provided the correct arguments to libnpmhook' 1991cb0ef41Sopenharmony_ci ) 2001cb0ef41Sopenharmony_ci 2011cb0ef41Sopenharmony_ci t.strictSame( 2021cb0ef41Sopenharmony_ci outputs[0][0].split(/\t/), 2031cb0ef41Sopenharmony_ci ['id', 'name', 'type', 'endpoint'], 2041cb0ef41Sopenharmony_ci 'prints the correct parseable output headers' 2051cb0ef41Sopenharmony_ci ) 2061cb0ef41Sopenharmony_ci t.strictSame( 2071cb0ef41Sopenharmony_ci outputs[1][0].split(/\t/), 2081cb0ef41Sopenharmony_ci ['1', '@npmcli', 'scope', 'https://google.com'], 2091cb0ef41Sopenharmony_ci 'prints the correct parseable values' 2101cb0ef41Sopenharmony_ci ) 2111cb0ef41Sopenharmony_ci}) 2121cb0ef41Sopenharmony_ci 2131cb0ef41Sopenharmony_cit.test('npm hook add - silent output', async t => { 2141cb0ef41Sopenharmony_ci const config = { loglevel: 'silent' } 2151cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 2161cb0ef41Sopenharmony_ci config, 2171cb0ef41Sopenharmony_ci }) 2181cb0ef41Sopenharmony_ci 2191cb0ef41Sopenharmony_ci await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret']) 2201cb0ef41Sopenharmony_ci 2211cb0ef41Sopenharmony_ci t.match( 2221cb0ef41Sopenharmony_ci hookArgs(), 2231cb0ef41Sopenharmony_ci { 2241cb0ef41Sopenharmony_ci pkg: '@npmcli', 2251cb0ef41Sopenharmony_ci uri: 'https://google.com', 2261cb0ef41Sopenharmony_ci secret: 'some-secret', 2271cb0ef41Sopenharmony_ci opts: npm.flatOptions, 2281cb0ef41Sopenharmony_ci }, 2291cb0ef41Sopenharmony_ci 'provided the correct arguments to libnpmhook' 2301cb0ef41Sopenharmony_ci ) 2311cb0ef41Sopenharmony_ci t.strictSame(outputs, [], 'printed no output') 2321cb0ef41Sopenharmony_ci}) 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_cit.test('npm hook ls', async t => { 2351cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t) 2361cb0ef41Sopenharmony_ci await hook.exec(['ls']) 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_ci t.match( 2391cb0ef41Sopenharmony_ci hookArgs(), 2401cb0ef41Sopenharmony_ci { 2411cb0ef41Sopenharmony_ci ...npm.flatOptions, 2421cb0ef41Sopenharmony_ci package: undefined, 2431cb0ef41Sopenharmony_ci }, 2441cb0ef41Sopenharmony_ci 'received the correct arguments' 2451cb0ef41Sopenharmony_ci ) 2461cb0ef41Sopenharmony_ci t.equal(outputs[0][0], 'You have 3 hooks configured.', 'prints the correct header') 2471cb0ef41Sopenharmony_ci const out = stripVTControlCharacters(outputs[1][0]) 2481cb0ef41Sopenharmony_ci t.match(out, /semver.*https:\/\/google.com.*\n.*\n.*never triggered/, 'prints package hook') 2491cb0ef41Sopenharmony_ci t.match(out, /@npmcli.*https:\/\/google.com.*\n.*\n.*triggered just now/, 'prints scope hook') 2501cb0ef41Sopenharmony_ci t.match(out, /~npm.*https:\/\/google.com.*\n.*\n.*never triggered/, 'prints owner hook') 2511cb0ef41Sopenharmony_ci}) 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_cit.test('npm hook ls, no results', async t => { 2541cb0ef41Sopenharmony_ci const hookResponse = [] 2551cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 2561cb0ef41Sopenharmony_ci hookResponse, 2571cb0ef41Sopenharmony_ci }) 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ci await hook.exec(['ls']) 2601cb0ef41Sopenharmony_ci 2611cb0ef41Sopenharmony_ci t.match( 2621cb0ef41Sopenharmony_ci hookArgs(), 2631cb0ef41Sopenharmony_ci { 2641cb0ef41Sopenharmony_ci ...npm.flatOptions, 2651cb0ef41Sopenharmony_ci package: undefined, 2661cb0ef41Sopenharmony_ci }, 2671cb0ef41Sopenharmony_ci 'received the correct arguments' 2681cb0ef41Sopenharmony_ci ) 2691cb0ef41Sopenharmony_ci t.equal(outputs[0][0], "You don't have any hooks configured yet.", 'prints the correct result') 2701cb0ef41Sopenharmony_ci}) 2711cb0ef41Sopenharmony_ci 2721cb0ef41Sopenharmony_cit.test('npm hook ls, single result', async t => { 2731cb0ef41Sopenharmony_ci const hookResponse = [ 2741cb0ef41Sopenharmony_ci { 2751cb0ef41Sopenharmony_ci id: 1, 2761cb0ef41Sopenharmony_ci name: 'semver', 2771cb0ef41Sopenharmony_ci type: 'package', 2781cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 2791cb0ef41Sopenharmony_ci }, 2801cb0ef41Sopenharmony_ci ] 2811cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 2821cb0ef41Sopenharmony_ci hookResponse, 2831cb0ef41Sopenharmony_ci }) 2841cb0ef41Sopenharmony_ci 2851cb0ef41Sopenharmony_ci await hook.exec(['ls']) 2861cb0ef41Sopenharmony_ci 2871cb0ef41Sopenharmony_ci t.match( 2881cb0ef41Sopenharmony_ci hookArgs(), 2891cb0ef41Sopenharmony_ci { 2901cb0ef41Sopenharmony_ci ...npm.flatOptions, 2911cb0ef41Sopenharmony_ci package: undefined, 2921cb0ef41Sopenharmony_ci }, 2931cb0ef41Sopenharmony_ci 'received the correct arguments' 2941cb0ef41Sopenharmony_ci ) 2951cb0ef41Sopenharmony_ci t.equal(outputs[0][0], 'You have one hook configured.', 'prints the correct header') 2961cb0ef41Sopenharmony_ci const out = stripVTControlCharacters(outputs[1][0]) 2971cb0ef41Sopenharmony_ci t.match(out, /semver.*https:\/\/google.com.*\n.*\n.*never triggered/, 'prints package hook') 2981cb0ef41Sopenharmony_ci}) 2991cb0ef41Sopenharmony_ci 3001cb0ef41Sopenharmony_cit.test('npm hook ls - json output', async t => { 3011cb0ef41Sopenharmony_ci const config = { 3021cb0ef41Sopenharmony_ci json: true, 3031cb0ef41Sopenharmony_ci } 3041cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 3051cb0ef41Sopenharmony_ci config, 3061cb0ef41Sopenharmony_ci }) 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ci await hook.exec(['ls']) 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ci t.match( 3111cb0ef41Sopenharmony_ci hookArgs(), 3121cb0ef41Sopenharmony_ci { 3131cb0ef41Sopenharmony_ci ...npm.flatOptions, 3141cb0ef41Sopenharmony_ci package: undefined, 3151cb0ef41Sopenharmony_ci }, 3161cb0ef41Sopenharmony_ci 'received the correct arguments' 3171cb0ef41Sopenharmony_ci ) 3181cb0ef41Sopenharmony_ci const out = JSON.parse(outputs[0]) 3191cb0ef41Sopenharmony_ci t.match( 3201cb0ef41Sopenharmony_ci out, 3211cb0ef41Sopenharmony_ci [ 3221cb0ef41Sopenharmony_ci { 3231cb0ef41Sopenharmony_ci id: 1, 3241cb0ef41Sopenharmony_ci name: 'semver', 3251cb0ef41Sopenharmony_ci type: 'package', 3261cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 3271cb0ef41Sopenharmony_ci }, 3281cb0ef41Sopenharmony_ci { 3291cb0ef41Sopenharmony_ci id: 2, 3301cb0ef41Sopenharmony_ci name: 'npmcli', 3311cb0ef41Sopenharmony_ci type: 'scope', 3321cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 3331cb0ef41Sopenharmony_ci }, 3341cb0ef41Sopenharmony_ci { 3351cb0ef41Sopenharmony_ci id: 3, 3361cb0ef41Sopenharmony_ci name: 'npm', 3371cb0ef41Sopenharmony_ci type: 'owner', 3381cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 3391cb0ef41Sopenharmony_ci }, 3401cb0ef41Sopenharmony_ci ], 3411cb0ef41Sopenharmony_ci 'prints the correct output' 3421cb0ef41Sopenharmony_ci ) 3431cb0ef41Sopenharmony_ci}) 3441cb0ef41Sopenharmony_ci 3451cb0ef41Sopenharmony_cit.test('npm hook ls - parseable output', async t => { 3461cb0ef41Sopenharmony_ci const config = { 3471cb0ef41Sopenharmony_ci parseable: true, 3481cb0ef41Sopenharmony_ci } 3491cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs, now } = await mockHook(t, { 3501cb0ef41Sopenharmony_ci config, 3511cb0ef41Sopenharmony_ci }) 3521cb0ef41Sopenharmony_ci 3531cb0ef41Sopenharmony_ci await hook.exec(['ls']) 3541cb0ef41Sopenharmony_ci 3551cb0ef41Sopenharmony_ci t.match( 3561cb0ef41Sopenharmony_ci hookArgs(), 3571cb0ef41Sopenharmony_ci { 3581cb0ef41Sopenharmony_ci ...npm.flatOptions, 3591cb0ef41Sopenharmony_ci package: undefined, 3601cb0ef41Sopenharmony_ci }, 3611cb0ef41Sopenharmony_ci 'received the correct arguments' 3621cb0ef41Sopenharmony_ci ) 3631cb0ef41Sopenharmony_ci t.strictSame( 3641cb0ef41Sopenharmony_ci outputs.map(line => line[0].split(/\t/)), 3651cb0ef41Sopenharmony_ci [ 3661cb0ef41Sopenharmony_ci ['id', 'name', 'type', 'endpoint', 'last_delivery'], 3671cb0ef41Sopenharmony_ci ['1', 'semver', 'package', 'https://google.com', ''], 3681cb0ef41Sopenharmony_ci ['2', '@npmcli', 'scope', 'https://google.com', `${now}`], 3691cb0ef41Sopenharmony_ci ['3', 'npm', 'owner', 'https://google.com', ''], 3701cb0ef41Sopenharmony_ci ], 3711cb0ef41Sopenharmony_ci 'prints the correct result' 3721cb0ef41Sopenharmony_ci ) 3731cb0ef41Sopenharmony_ci}) 3741cb0ef41Sopenharmony_ci 3751cb0ef41Sopenharmony_cit.test('npm hook ls - silent output', async t => { 3761cb0ef41Sopenharmony_ci const config = { loglevel: 'silent' } 3771cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 3781cb0ef41Sopenharmony_ci config, 3791cb0ef41Sopenharmony_ci }) 3801cb0ef41Sopenharmony_ci 3811cb0ef41Sopenharmony_ci await hook.exec(['ls']) 3821cb0ef41Sopenharmony_ci 3831cb0ef41Sopenharmony_ci t.match( 3841cb0ef41Sopenharmony_ci hookArgs(), 3851cb0ef41Sopenharmony_ci { 3861cb0ef41Sopenharmony_ci ...npm.flatOptions, 3871cb0ef41Sopenharmony_ci package: undefined, 3881cb0ef41Sopenharmony_ci }, 3891cb0ef41Sopenharmony_ci 'received the correct arguments' 3901cb0ef41Sopenharmony_ci ) 3911cb0ef41Sopenharmony_ci t.strictSame(outputs, [], 'printed no output') 3921cb0ef41Sopenharmony_ci}) 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_cit.test('npm hook rm', async t => { 3951cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 3961cb0ef41Sopenharmony_ci }) 3971cb0ef41Sopenharmony_ci await hook.exec(['rm', '1']) 3981cb0ef41Sopenharmony_ci 3991cb0ef41Sopenharmony_ci t.match( 4001cb0ef41Sopenharmony_ci hookArgs(), 4011cb0ef41Sopenharmony_ci { 4021cb0ef41Sopenharmony_ci id: '1', 4031cb0ef41Sopenharmony_ci opts: npm.flatOptions, 4041cb0ef41Sopenharmony_ci }, 4051cb0ef41Sopenharmony_ci 'received the correct arguments' 4061cb0ef41Sopenharmony_ci ) 4071cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['- semver X https://google.com'], 'printed the correct output') 4081cb0ef41Sopenharmony_ci}) 4091cb0ef41Sopenharmony_ci 4101cb0ef41Sopenharmony_cit.test('npm hook rm - unicode output', async t => { 4111cb0ef41Sopenharmony_ci const config = { 4121cb0ef41Sopenharmony_ci unicode: true, 4131cb0ef41Sopenharmony_ci } 4141cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 4151cb0ef41Sopenharmony_ci config, 4161cb0ef41Sopenharmony_ci }) 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_ci await hook.exec(['rm', '1']) 4191cb0ef41Sopenharmony_ci 4201cb0ef41Sopenharmony_ci t.match( 4211cb0ef41Sopenharmony_ci hookArgs(), 4221cb0ef41Sopenharmony_ci { 4231cb0ef41Sopenharmony_ci id: '1', 4241cb0ef41Sopenharmony_ci opts: npm.flatOptions, 4251cb0ef41Sopenharmony_ci }, 4261cb0ef41Sopenharmony_ci 'received the correct arguments' 4271cb0ef41Sopenharmony_ci ) 4281cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['- semver ✘ https://google.com'], 'printed the correct output') 4291cb0ef41Sopenharmony_ci}) 4301cb0ef41Sopenharmony_ci 4311cb0ef41Sopenharmony_cit.test('npm hook rm - silent output', async t => { 4321cb0ef41Sopenharmony_ci const config = { loglevel: 'silent' } 4331cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 4341cb0ef41Sopenharmony_ci config, 4351cb0ef41Sopenharmony_ci }) 4361cb0ef41Sopenharmony_ci 4371cb0ef41Sopenharmony_ci await hook.exec(['rm', '1']) 4381cb0ef41Sopenharmony_ci 4391cb0ef41Sopenharmony_ci t.match( 4401cb0ef41Sopenharmony_ci hookArgs(), 4411cb0ef41Sopenharmony_ci { 4421cb0ef41Sopenharmony_ci id: '1', 4431cb0ef41Sopenharmony_ci opts: npm.flatOptions, 4441cb0ef41Sopenharmony_ci }, 4451cb0ef41Sopenharmony_ci 'received the correct arguments' 4461cb0ef41Sopenharmony_ci ) 4471cb0ef41Sopenharmony_ci t.strictSame(outputs, [], 'printed no output') 4481cb0ef41Sopenharmony_ci}) 4491cb0ef41Sopenharmony_ci 4501cb0ef41Sopenharmony_cit.test('npm hook rm - json output', async t => { 4511cb0ef41Sopenharmony_ci const config = { 4521cb0ef41Sopenharmony_ci json: true, 4531cb0ef41Sopenharmony_ci } 4541cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 4551cb0ef41Sopenharmony_ci config, 4561cb0ef41Sopenharmony_ci }) 4571cb0ef41Sopenharmony_ci 4581cb0ef41Sopenharmony_ci await hook.exec(['rm', '1']) 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci t.match( 4611cb0ef41Sopenharmony_ci hookArgs(), 4621cb0ef41Sopenharmony_ci { 4631cb0ef41Sopenharmony_ci id: '1', 4641cb0ef41Sopenharmony_ci opts: npm.flatOptions, 4651cb0ef41Sopenharmony_ci }, 4661cb0ef41Sopenharmony_ci 'received the correct arguments' 4671cb0ef41Sopenharmony_ci ) 4681cb0ef41Sopenharmony_ci t.strictSame( 4691cb0ef41Sopenharmony_ci JSON.parse(outputs[0]), 4701cb0ef41Sopenharmony_ci { 4711cb0ef41Sopenharmony_ci id: 1, 4721cb0ef41Sopenharmony_ci name: 'semver', 4731cb0ef41Sopenharmony_ci type: 'package', 4741cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 4751cb0ef41Sopenharmony_ci }, 4761cb0ef41Sopenharmony_ci 'printed correct output' 4771cb0ef41Sopenharmony_ci ) 4781cb0ef41Sopenharmony_ci}) 4791cb0ef41Sopenharmony_ci 4801cb0ef41Sopenharmony_cit.test('npm hook rm - parseable output', async t => { 4811cb0ef41Sopenharmony_ci const config = { 4821cb0ef41Sopenharmony_ci parseable: true, 4831cb0ef41Sopenharmony_ci } 4841cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 4851cb0ef41Sopenharmony_ci config, 4861cb0ef41Sopenharmony_ci }) 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_ci await hook.exec(['rm', '1']) 4891cb0ef41Sopenharmony_ci 4901cb0ef41Sopenharmony_ci t.match( 4911cb0ef41Sopenharmony_ci hookArgs(), 4921cb0ef41Sopenharmony_ci { 4931cb0ef41Sopenharmony_ci id: '1', 4941cb0ef41Sopenharmony_ci opts: npm.flatOptions, 4951cb0ef41Sopenharmony_ci }, 4961cb0ef41Sopenharmony_ci 'received the correct arguments' 4971cb0ef41Sopenharmony_ci ) 4981cb0ef41Sopenharmony_ci t.strictSame( 4991cb0ef41Sopenharmony_ci outputs.map(line => line[0].split(/\t/)), 5001cb0ef41Sopenharmony_ci [ 5011cb0ef41Sopenharmony_ci ['id', 'name', 'type', 'endpoint'], 5021cb0ef41Sopenharmony_ci ['1', 'semver', 'package', 'https://google.com'], 5031cb0ef41Sopenharmony_ci ], 5041cb0ef41Sopenharmony_ci 'printed correct output' 5051cb0ef41Sopenharmony_ci ) 5061cb0ef41Sopenharmony_ci}) 5071cb0ef41Sopenharmony_ci 5081cb0ef41Sopenharmony_cit.test('npm hook update', async t => { 5091cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 5101cb0ef41Sopenharmony_ci }) 5111cb0ef41Sopenharmony_ci await hook.exec(['update', '1', 'https://google.com', 'some-secret']) 5121cb0ef41Sopenharmony_ci 5131cb0ef41Sopenharmony_ci t.match( 5141cb0ef41Sopenharmony_ci hookArgs(), 5151cb0ef41Sopenharmony_ci { 5161cb0ef41Sopenharmony_ci id: '1', 5171cb0ef41Sopenharmony_ci uri: 'https://google.com', 5181cb0ef41Sopenharmony_ci secret: 'some-secret', 5191cb0ef41Sopenharmony_ci opts: npm.flatOptions, 5201cb0ef41Sopenharmony_ci }, 5211cb0ef41Sopenharmony_ci 'received the correct arguments' 5221cb0ef41Sopenharmony_ci ) 5231cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['+ semver -> https://google.com'], 'printed the correct output') 5241cb0ef41Sopenharmony_ci}) 5251cb0ef41Sopenharmony_ci 5261cb0ef41Sopenharmony_cit.test('npm hook update - unicode', async t => { 5271cb0ef41Sopenharmony_ci const config = { 5281cb0ef41Sopenharmony_ci unicode: true, 5291cb0ef41Sopenharmony_ci } 5301cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 5311cb0ef41Sopenharmony_ci config, 5321cb0ef41Sopenharmony_ci }) 5331cb0ef41Sopenharmony_ci 5341cb0ef41Sopenharmony_ci await hook.exec(['update', '1', 'https://google.com', 'some-secret']) 5351cb0ef41Sopenharmony_ci 5361cb0ef41Sopenharmony_ci t.match( 5371cb0ef41Sopenharmony_ci hookArgs(), 5381cb0ef41Sopenharmony_ci { 5391cb0ef41Sopenharmony_ci id: '1', 5401cb0ef41Sopenharmony_ci uri: 'https://google.com', 5411cb0ef41Sopenharmony_ci secret: 'some-secret', 5421cb0ef41Sopenharmony_ci opts: npm.flatOptions, 5431cb0ef41Sopenharmony_ci }, 5441cb0ef41Sopenharmony_ci 'received the correct arguments' 5451cb0ef41Sopenharmony_ci ) 5461cb0ef41Sopenharmony_ci t.strictSame(outputs[0], ['+ semver ➜ https://google.com'], 'printed the correct output') 5471cb0ef41Sopenharmony_ci}) 5481cb0ef41Sopenharmony_ci 5491cb0ef41Sopenharmony_cit.test('npm hook update - json output', async t => { 5501cb0ef41Sopenharmony_ci const config = { 5511cb0ef41Sopenharmony_ci json: true, 5521cb0ef41Sopenharmony_ci } 5531cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 5541cb0ef41Sopenharmony_ci config, 5551cb0ef41Sopenharmony_ci }) 5561cb0ef41Sopenharmony_ci 5571cb0ef41Sopenharmony_ci await hook.exec(['update', '1', 'https://google.com', 'some-secret']) 5581cb0ef41Sopenharmony_ci 5591cb0ef41Sopenharmony_ci t.match( 5601cb0ef41Sopenharmony_ci hookArgs(), 5611cb0ef41Sopenharmony_ci { 5621cb0ef41Sopenharmony_ci id: '1', 5631cb0ef41Sopenharmony_ci uri: 'https://google.com', 5641cb0ef41Sopenharmony_ci secret: 'some-secret', 5651cb0ef41Sopenharmony_ci opts: npm.flatOptions, 5661cb0ef41Sopenharmony_ci }, 5671cb0ef41Sopenharmony_ci 'received the correct arguments' 5681cb0ef41Sopenharmony_ci ) 5691cb0ef41Sopenharmony_ci t.strictSame( 5701cb0ef41Sopenharmony_ci JSON.parse(outputs[0]), 5711cb0ef41Sopenharmony_ci { 5721cb0ef41Sopenharmony_ci id: '1', 5731cb0ef41Sopenharmony_ci name: 'semver', 5741cb0ef41Sopenharmony_ci type: 'package', 5751cb0ef41Sopenharmony_ci endpoint: 'https://google.com', 5761cb0ef41Sopenharmony_ci }, 5771cb0ef41Sopenharmony_ci 'printed the correct output' 5781cb0ef41Sopenharmony_ci ) 5791cb0ef41Sopenharmony_ci}) 5801cb0ef41Sopenharmony_ci 5811cb0ef41Sopenharmony_cit.test('npm hook update - parseable output', async t => { 5821cb0ef41Sopenharmony_ci const config = { 5831cb0ef41Sopenharmony_ci parseable: true, 5841cb0ef41Sopenharmony_ci } 5851cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 5861cb0ef41Sopenharmony_ci config, 5871cb0ef41Sopenharmony_ci }) 5881cb0ef41Sopenharmony_ci 5891cb0ef41Sopenharmony_ci await hook.exec(['update', '1', 'https://google.com', 'some-secret']) 5901cb0ef41Sopenharmony_ci 5911cb0ef41Sopenharmony_ci t.match( 5921cb0ef41Sopenharmony_ci hookArgs(), 5931cb0ef41Sopenharmony_ci { 5941cb0ef41Sopenharmony_ci id: '1', 5951cb0ef41Sopenharmony_ci uri: 'https://google.com', 5961cb0ef41Sopenharmony_ci secret: 'some-secret', 5971cb0ef41Sopenharmony_ci opts: npm.flatOptions, 5981cb0ef41Sopenharmony_ci }, 5991cb0ef41Sopenharmony_ci 'received the correct arguments' 6001cb0ef41Sopenharmony_ci ) 6011cb0ef41Sopenharmony_ci t.strictSame( 6021cb0ef41Sopenharmony_ci outputs.map(line => line[0].split(/\t/)), 6031cb0ef41Sopenharmony_ci [ 6041cb0ef41Sopenharmony_ci ['id', 'name', 'type', 'endpoint'], 6051cb0ef41Sopenharmony_ci ['1', 'semver', 'package', 'https://google.com'], 6061cb0ef41Sopenharmony_ci ], 6071cb0ef41Sopenharmony_ci 'printed the correct output' 6081cb0ef41Sopenharmony_ci ) 6091cb0ef41Sopenharmony_ci}) 6101cb0ef41Sopenharmony_ci 6111cb0ef41Sopenharmony_cit.test('npm hook update - silent output', async t => { 6121cb0ef41Sopenharmony_ci const config = { loglevel: 'silent' } 6131cb0ef41Sopenharmony_ci const { npm, hook, outputs, hookArgs } = await mockHook(t, { 6141cb0ef41Sopenharmony_ci config, 6151cb0ef41Sopenharmony_ci }) 6161cb0ef41Sopenharmony_ci 6171cb0ef41Sopenharmony_ci await hook.exec(['update', '1', 'https://google.com', 'some-secret']) 6181cb0ef41Sopenharmony_ci 6191cb0ef41Sopenharmony_ci t.match( 6201cb0ef41Sopenharmony_ci hookArgs(), 6211cb0ef41Sopenharmony_ci { 6221cb0ef41Sopenharmony_ci id: '1', 6231cb0ef41Sopenharmony_ci uri: 'https://google.com', 6241cb0ef41Sopenharmony_ci secret: 'some-secret', 6251cb0ef41Sopenharmony_ci opts: npm.flatOptions, 6261cb0ef41Sopenharmony_ci }, 6271cb0ef41Sopenharmony_ci 'received the correct arguments' 6281cb0ef41Sopenharmony_ci ) 6291cb0ef41Sopenharmony_ci t.strictSame(outputs, [], 'printed no output') 6301cb0ef41Sopenharmony_ci}) 631