11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst { load: _loadMockNpm } = require('../../fixtures/mock-npm.js') 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cit.cleanSnapshot = str => str 51cb0ef41Sopenharmony_ci .replace(/(published ).*?( ago)/g, '$1{TIME}$2') 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// run the same as tap does when running directly with node 81cb0ef41Sopenharmony_ciprocess.stdout.columns = undefined 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// 3 days. its never yesterday and never a week ago 111cb0ef41Sopenharmony_ciconst yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24 * 3) 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst packument = (nv, opts) => { 141cb0ef41Sopenharmony_ci if (!opts.fullMetadata) { 151cb0ef41Sopenharmony_ci throw new Error('must fetch fullMetadata') 161cb0ef41Sopenharmony_ci } 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci if (!opts.preferOnline) { 191cb0ef41Sopenharmony_ci throw new Error('must fetch with preferOnline') 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci const mocks = { 231cb0ef41Sopenharmony_ci red: { 241cb0ef41Sopenharmony_ci _id: 'red@1.0.1', 251cb0ef41Sopenharmony_ci name: 'red', 261cb0ef41Sopenharmony_ci 'dist-tags': { 271cb0ef41Sopenharmony_ci '1.0.1': {}, 281cb0ef41Sopenharmony_ci }, 291cb0ef41Sopenharmony_ci time: { 301cb0ef41Sopenharmony_ci unpublished: { 311cb0ef41Sopenharmony_ci time: '2012-12-20T00:00:00.000Z', 321cb0ef41Sopenharmony_ci }, 331cb0ef41Sopenharmony_ci }, 341cb0ef41Sopenharmony_ci }, 351cb0ef41Sopenharmony_ci blue: { 361cb0ef41Sopenharmony_ci _id: 'blue', 371cb0ef41Sopenharmony_ci name: 'blue', 381cb0ef41Sopenharmony_ci 'dist-tags': { 391cb0ef41Sopenharmony_ci latest: '1.0.0', 401cb0ef41Sopenharmony_ci }, 411cb0ef41Sopenharmony_ci time: { 421cb0ef41Sopenharmony_ci '1.0.0': yesterday, 431cb0ef41Sopenharmony_ci }, 441cb0ef41Sopenharmony_ci versions: { 451cb0ef41Sopenharmony_ci '1.0.0': { 461cb0ef41Sopenharmony_ci name: 'blue', 471cb0ef41Sopenharmony_ci version: '1.0.0', 481cb0ef41Sopenharmony_ci dist: { 491cb0ef41Sopenharmony_ci shasum: '123', 501cb0ef41Sopenharmony_ci tarball: 'http://hm.blue.com/1.0.0.tgz', 511cb0ef41Sopenharmony_ci integrity: '---', 521cb0ef41Sopenharmony_ci fileCount: 1, 531cb0ef41Sopenharmony_ci unpackedSize: 1, 541cb0ef41Sopenharmony_ci }, 551cb0ef41Sopenharmony_ci }, 561cb0ef41Sopenharmony_ci '1.0.1': { 571cb0ef41Sopenharmony_ci name: 'blue', 581cb0ef41Sopenharmony_ci version: '1.0.1', 591cb0ef41Sopenharmony_ci dist: { 601cb0ef41Sopenharmony_ci shasum: '124', 611cb0ef41Sopenharmony_ci tarball: 'http://hm.blue.com/1.0.1.tgz', 621cb0ef41Sopenharmony_ci integrity: '---', 631cb0ef41Sopenharmony_ci fileCount: 1, 641cb0ef41Sopenharmony_ci unpackedSize: 1000, 651cb0ef41Sopenharmony_ci }, 661cb0ef41Sopenharmony_ci }, 671cb0ef41Sopenharmony_ci }, 681cb0ef41Sopenharmony_ci }, 691cb0ef41Sopenharmony_ci cyan: { 701cb0ef41Sopenharmony_ci _npmUser: { 711cb0ef41Sopenharmony_ci name: 'claudia', 721cb0ef41Sopenharmony_ci email: 'claudia@cyan.com', 731cb0ef41Sopenharmony_ci }, 741cb0ef41Sopenharmony_ci name: 'cyan', 751cb0ef41Sopenharmony_ci 'dist-tags': { 761cb0ef41Sopenharmony_ci latest: '1.0.0', 771cb0ef41Sopenharmony_ci }, 781cb0ef41Sopenharmony_ci versions: { 791cb0ef41Sopenharmony_ci '1.0.0': { 801cb0ef41Sopenharmony_ci version: '1.0.0', 811cb0ef41Sopenharmony_ci name: 'cyan', 821cb0ef41Sopenharmony_ci dist: { 831cb0ef41Sopenharmony_ci shasum: '123', 841cb0ef41Sopenharmony_ci tarball: 'http://hm.cyan.com/1.0.0.tgz', 851cb0ef41Sopenharmony_ci integrity: '---', 861cb0ef41Sopenharmony_ci fileCount: 1, 871cb0ef41Sopenharmony_ci unpackedSize: 1000000, 881cb0ef41Sopenharmony_ci }, 891cb0ef41Sopenharmony_ci }, 901cb0ef41Sopenharmony_ci '1.0.1': {}, 911cb0ef41Sopenharmony_ci }, 921cb0ef41Sopenharmony_ci }, 931cb0ef41Sopenharmony_ci brown: { 941cb0ef41Sopenharmony_ci name: 'brown', 951cb0ef41Sopenharmony_ci }, 961cb0ef41Sopenharmony_ci yellow: { 971cb0ef41Sopenharmony_ci _id: 'yellow', 981cb0ef41Sopenharmony_ci name: 'yellow', 991cb0ef41Sopenharmony_ci author: { 1001cb0ef41Sopenharmony_ci name: 'foo', 1011cb0ef41Sopenharmony_ci email: 'foo@yellow.com', 1021cb0ef41Sopenharmony_ci twitter: 'foo', 1031cb0ef41Sopenharmony_ci }, 1041cb0ef41Sopenharmony_ci empty: '', 1051cb0ef41Sopenharmony_ci readme: 'a very useful readme', 1061cb0ef41Sopenharmony_ci versions: { 1071cb0ef41Sopenharmony_ci '1.0.0': { 1081cb0ef41Sopenharmony_ci version: '1.0.0', 1091cb0ef41Sopenharmony_ci author: 'claudia', 1101cb0ef41Sopenharmony_ci readme: 'a very useful readme', 1111cb0ef41Sopenharmony_ci maintainers: [ 1121cb0ef41Sopenharmony_ci { name: 'claudia', email: 'c@yellow.com', twitter: 'cyellow' }, 1131cb0ef41Sopenharmony_ci { name: 'isaacs', email: 'i@yellow.com', twitter: 'iyellow' }, 1141cb0ef41Sopenharmony_ci ], 1151cb0ef41Sopenharmony_ci }, 1161cb0ef41Sopenharmony_ci '1.0.1': { 1171cb0ef41Sopenharmony_ci version: '1.0.1', 1181cb0ef41Sopenharmony_ci author: 'claudia', 1191cb0ef41Sopenharmony_ci }, 1201cb0ef41Sopenharmony_ci '1.0.2': { 1211cb0ef41Sopenharmony_ci version: '1.0.2', 1221cb0ef41Sopenharmony_ci author: 'claudia', 1231cb0ef41Sopenharmony_ci }, 1241cb0ef41Sopenharmony_ci }, 1251cb0ef41Sopenharmony_ci }, 1261cb0ef41Sopenharmony_ci purple: { 1271cb0ef41Sopenharmony_ci name: 'purple', 1281cb0ef41Sopenharmony_ci versions: { 1291cb0ef41Sopenharmony_ci '1.0.0': { 1301cb0ef41Sopenharmony_ci foo: 1, 1311cb0ef41Sopenharmony_ci maintainers: [ 1321cb0ef41Sopenharmony_ci { name: 'claudia' }, 1331cb0ef41Sopenharmony_ci ], 1341cb0ef41Sopenharmony_ci }, 1351cb0ef41Sopenharmony_ci '1.0.1': {}, 1361cb0ef41Sopenharmony_ci }, 1371cb0ef41Sopenharmony_ci }, 1381cb0ef41Sopenharmony_ci green: { 1391cb0ef41Sopenharmony_ci _id: 'green', 1401cb0ef41Sopenharmony_ci name: 'green', 1411cb0ef41Sopenharmony_ci 'dist-tags': { 1421cb0ef41Sopenharmony_ci latest: '1.0.0', 1431cb0ef41Sopenharmony_ci }, 1441cb0ef41Sopenharmony_ci maintainers: [ 1451cb0ef41Sopenharmony_ci { name: 'claudia', email: 'c@yellow.com', twitter: 'cyellow' }, 1461cb0ef41Sopenharmony_ci { name: 'isaacs', email: 'i@yellow.com', twitter: 'iyellow' }, 1471cb0ef41Sopenharmony_ci ], 1481cb0ef41Sopenharmony_ci keywords: ['colors', 'green', 'crayola'], 1491cb0ef41Sopenharmony_ci versions: { 1501cb0ef41Sopenharmony_ci '1.0.0': { 1511cb0ef41Sopenharmony_ci _id: 'green', 1521cb0ef41Sopenharmony_ci version: '1.0.0', 1531cb0ef41Sopenharmony_ci description: 'green is a very important color', 1541cb0ef41Sopenharmony_ci bugs: { 1551cb0ef41Sopenharmony_ci url: 'http://bugs.green.com', 1561cb0ef41Sopenharmony_ci }, 1571cb0ef41Sopenharmony_ci deprecated: true, 1581cb0ef41Sopenharmony_ci repository: { 1591cb0ef41Sopenharmony_ci url: 'http://repository.green.com', 1601cb0ef41Sopenharmony_ci }, 1611cb0ef41Sopenharmony_ci license: { type: 'ACME' }, 1621cb0ef41Sopenharmony_ci bin: { 1631cb0ef41Sopenharmony_ci green: 'bin/green.js', 1641cb0ef41Sopenharmony_ci }, 1651cb0ef41Sopenharmony_ci dependencies: { 1661cb0ef41Sopenharmony_ci red: '1.0.0', 1671cb0ef41Sopenharmony_ci yellow: '1.0.0', 1681cb0ef41Sopenharmony_ci }, 1691cb0ef41Sopenharmony_ci dist: { 1701cb0ef41Sopenharmony_ci shasum: '123', 1711cb0ef41Sopenharmony_ci tarball: 'http://hm.green.com/1.0.0.tgz', 1721cb0ef41Sopenharmony_ci integrity: '---', 1731cb0ef41Sopenharmony_ci fileCount: 1, 1741cb0ef41Sopenharmony_ci unpackedSize: 1000000000, 1751cb0ef41Sopenharmony_ci }, 1761cb0ef41Sopenharmony_ci }, 1771cb0ef41Sopenharmony_ci '1.0.1': {}, 1781cb0ef41Sopenharmony_ci }, 1791cb0ef41Sopenharmony_ci }, 1801cb0ef41Sopenharmony_ci black: { 1811cb0ef41Sopenharmony_ci name: 'black', 1821cb0ef41Sopenharmony_ci 'dist-tags': { 1831cb0ef41Sopenharmony_ci latest: '1.0.0', 1841cb0ef41Sopenharmony_ci }, 1851cb0ef41Sopenharmony_ci versions: { 1861cb0ef41Sopenharmony_ci '1.0.0': { 1871cb0ef41Sopenharmony_ci version: '1.0.0', 1881cb0ef41Sopenharmony_ci bugs: 'http://bugs.black.com', 1891cb0ef41Sopenharmony_ci license: {}, 1901cb0ef41Sopenharmony_ci dependencies: (() => { 1911cb0ef41Sopenharmony_ci const deps = {} 1921cb0ef41Sopenharmony_ci for (let i = 0; i < 25; i++) { 1931cb0ef41Sopenharmony_ci deps[i] = '1.0.0' 1941cb0ef41Sopenharmony_ci } 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ci return deps 1971cb0ef41Sopenharmony_ci })(), 1981cb0ef41Sopenharmony_ci dist: { 1991cb0ef41Sopenharmony_ci shasum: '123', 2001cb0ef41Sopenharmony_ci tarball: 'http://hm.black.com/1.0.0.tgz', 2011cb0ef41Sopenharmony_ci integrity: '---', 2021cb0ef41Sopenharmony_ci fileCount: 1, 2031cb0ef41Sopenharmony_ci unpackedSize: 1, 2041cb0ef41Sopenharmony_ci }, 2051cb0ef41Sopenharmony_ci }, 2061cb0ef41Sopenharmony_ci '1.0.1': {}, 2071cb0ef41Sopenharmony_ci }, 2081cb0ef41Sopenharmony_ci }, 2091cb0ef41Sopenharmony_ci pink: { 2101cb0ef41Sopenharmony_ci name: 'pink', 2111cb0ef41Sopenharmony_ci 'dist-tags': { 2121cb0ef41Sopenharmony_ci latest: '1.0.0', 2131cb0ef41Sopenharmony_ci }, 2141cb0ef41Sopenharmony_ci versions: { 2151cb0ef41Sopenharmony_ci '1.0.0': { 2161cb0ef41Sopenharmony_ci version: '1.0.0', 2171cb0ef41Sopenharmony_ci maintainers: [ 2181cb0ef41Sopenharmony_ci { name: 'claudia', url: 'http://c.pink.com' }, 2191cb0ef41Sopenharmony_ci { name: 'isaacs', url: 'http://i.pink.com' }, 2201cb0ef41Sopenharmony_ci ], 2211cb0ef41Sopenharmony_ci repository: 'http://repository.pink.com', 2221cb0ef41Sopenharmony_ci license: {}, 2231cb0ef41Sopenharmony_ci dist: { 2241cb0ef41Sopenharmony_ci shasum: '123', 2251cb0ef41Sopenharmony_ci tarball: 'http://hm.pink.com/1.0.0.tgz', 2261cb0ef41Sopenharmony_ci integrity: '---', 2271cb0ef41Sopenharmony_ci fileCount: 1, 2281cb0ef41Sopenharmony_ci unpackedSize: 1, 2291cb0ef41Sopenharmony_ci }, 2301cb0ef41Sopenharmony_ci }, 2311cb0ef41Sopenharmony_ci '1.0.1': {}, 2321cb0ef41Sopenharmony_ci }, 2331cb0ef41Sopenharmony_ci }, 2341cb0ef41Sopenharmony_ci orange: { 2351cb0ef41Sopenharmony_ci name: 'orange', 2361cb0ef41Sopenharmony_ci 'dist-tags': { 2371cb0ef41Sopenharmony_ci latest: '1.0.0', 2381cb0ef41Sopenharmony_ci }, 2391cb0ef41Sopenharmony_ci versions: { 2401cb0ef41Sopenharmony_ci '1.0.0': { 2411cb0ef41Sopenharmony_ci version: '1.0.0', 2421cb0ef41Sopenharmony_ci homepage: 'http://hm.orange.com', 2431cb0ef41Sopenharmony_ci license: {}, 2441cb0ef41Sopenharmony_ci dist: { 2451cb0ef41Sopenharmony_ci shasum: '123', 2461cb0ef41Sopenharmony_ci tarball: 'http://hm.orange.com/1.0.0.tgz', 2471cb0ef41Sopenharmony_ci integrity: '---', 2481cb0ef41Sopenharmony_ci fileCount: 1, 2491cb0ef41Sopenharmony_ci unpackedSize: 1, 2501cb0ef41Sopenharmony_ci }, 2511cb0ef41Sopenharmony_ci }, 2521cb0ef41Sopenharmony_ci '1.0.1': {}, 2531cb0ef41Sopenharmony_ci '100000000000000000.0.0': { 2541cb0ef41Sopenharmony_ci }, 2551cb0ef41Sopenharmony_ci }, 2561cb0ef41Sopenharmony_ci }, 2571cb0ef41Sopenharmony_ci } 2581cb0ef41Sopenharmony_ci if (nv.type === 'git') { 2591cb0ef41Sopenharmony_ci return mocks[nv.hosted.project] 2601cb0ef41Sopenharmony_ci } 2611cb0ef41Sopenharmony_ci if (nv.raw === './blue') { 2621cb0ef41Sopenharmony_ci return mocks.blue 2631cb0ef41Sopenharmony_ci } 2641cb0ef41Sopenharmony_ci return mocks[nv.name] 2651cb0ef41Sopenharmony_ci} 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ciconst loadMockNpm = async function (t, opts = {}) { 2681cb0ef41Sopenharmony_ci const mockNpm = await _loadMockNpm(t, { 2691cb0ef41Sopenharmony_ci command: 'view', 2701cb0ef41Sopenharmony_ci mocks: { 2711cb0ef41Sopenharmony_ci pacote: { 2721cb0ef41Sopenharmony_ci packument, 2731cb0ef41Sopenharmony_ci }, 2741cb0ef41Sopenharmony_ci }, 2751cb0ef41Sopenharmony_ci ...opts, 2761cb0ef41Sopenharmony_ci config: { 2771cb0ef41Sopenharmony_ci color: 'always', 2781cb0ef41Sopenharmony_ci ...opts.config, 2791cb0ef41Sopenharmony_ci }, 2801cb0ef41Sopenharmony_ci }) 2811cb0ef41Sopenharmony_ci return mockNpm 2821cb0ef41Sopenharmony_ci} 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_cit.test('package from git', async t => { 2851cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 2861cb0ef41Sopenharmony_ci await view.exec(['https://github.com/npm/green']) 2871cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 2881cb0ef41Sopenharmony_ci}) 2891cb0ef41Sopenharmony_ci 2901cb0ef41Sopenharmony_cit.test('deprecated package with license, bugs, repository and other fields', async t => { 2911cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 2921cb0ef41Sopenharmony_ci await view.exec(['green@1.0.0']) 2931cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 2941cb0ef41Sopenharmony_ci}) 2951cb0ef41Sopenharmony_ci 2961cb0ef41Sopenharmony_cit.test('deprecated package with unicode', async t => { 2971cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: true } }) 2981cb0ef41Sopenharmony_ci await view.exec(['green@1.0.0']) 2991cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3001cb0ef41Sopenharmony_ci}) 3011cb0ef41Sopenharmony_ci 3021cb0ef41Sopenharmony_cit.test('package with more than 25 deps', async t => { 3031cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3041cb0ef41Sopenharmony_ci await view.exec(['black@1.0.0']) 3051cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3061cb0ef41Sopenharmony_ci}) 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_cit.test('package with maintainers info as object', async t => { 3091cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3101cb0ef41Sopenharmony_ci await view.exec(['pink@1.0.0']) 3111cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3121cb0ef41Sopenharmony_ci}) 3131cb0ef41Sopenharmony_ci 3141cb0ef41Sopenharmony_cit.test('package with homepage', async t => { 3151cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3161cb0ef41Sopenharmony_ci await view.exec(['orange@1.0.0']) 3171cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3181cb0ef41Sopenharmony_ci}) 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_cit.test('package with invalid version', async t => { 3211cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3221cb0ef41Sopenharmony_ci await view.exec(['orange', 'versions']) 3231cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3241cb0ef41Sopenharmony_ci}) 3251cb0ef41Sopenharmony_ci 3261cb0ef41Sopenharmony_cit.test('package with no versions', async t => { 3271cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3281cb0ef41Sopenharmony_ci await view.exec(['brown']) 3291cb0ef41Sopenharmony_ci t.equal(outputs.join('\n'), '', 'no info to display') 3301cb0ef41Sopenharmony_ci}) 3311cb0ef41Sopenharmony_ci 3321cb0ef41Sopenharmony_cit.test('package with no repo or homepage', async t => { 3331cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3341cb0ef41Sopenharmony_ci await view.exec(['blue@1.0.0']) 3351cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3361cb0ef41Sopenharmony_ci}) 3371cb0ef41Sopenharmony_ci 3381cb0ef41Sopenharmony_cit.test('package with semver range', async t => { 3391cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3401cb0ef41Sopenharmony_ci await view.exec(['blue@^1.0.0']) 3411cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3421cb0ef41Sopenharmony_ci}) 3431cb0ef41Sopenharmony_ci 3441cb0ef41Sopenharmony_cit.test('package with no modified time', async t => { 3451cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } }) 3461cb0ef41Sopenharmony_ci await view.exec(['cyan@1.0.0']) 3471cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3481cb0ef41Sopenharmony_ci}) 3491cb0ef41Sopenharmony_ci 3501cb0ef41Sopenharmony_cit.test('package with --json and semver range', async t => { 3511cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { json: true } }) 3521cb0ef41Sopenharmony_ci await view.exec(['cyan@^1.0.0']) 3531cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3541cb0ef41Sopenharmony_ci}) 3551cb0ef41Sopenharmony_ci 3561cb0ef41Sopenharmony_cit.test('package with --json and no versions', async t => { 3571cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { json: true } }) 3581cb0ef41Sopenharmony_ci await view.exec(['brown']) 3591cb0ef41Sopenharmony_ci t.equal(outputs.join('\n'), '', 'no info to display') 3601cb0ef41Sopenharmony_ci}) 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_cit.test('package in cwd', async t => { 3631cb0ef41Sopenharmony_ci const prefixDir = { 3641cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 3651cb0ef41Sopenharmony_ci name: 'blue', 3661cb0ef41Sopenharmony_ci version: '1.0.0', 3671cb0ef41Sopenharmony_ci }, null, 2), 3681cb0ef41Sopenharmony_ci } 3691cb0ef41Sopenharmony_ci 3701cb0ef41Sopenharmony_ci t.test('specific version', async t => { 3711cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { prefixDir }) 3721cb0ef41Sopenharmony_ci await view.exec(['.@1.0.0']) 3731cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3741cb0ef41Sopenharmony_ci }) 3751cb0ef41Sopenharmony_ci 3761cb0ef41Sopenharmony_ci t.test('non-specific version', async t => { 3771cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { prefixDir }) 3781cb0ef41Sopenharmony_ci await view.exec(['.']) 3791cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3801cb0ef41Sopenharmony_ci }) 3811cb0ef41Sopenharmony_ci 3821cb0ef41Sopenharmony_ci t.test('directory', async t => { 3831cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { prefixDir }) 3841cb0ef41Sopenharmony_ci await view.exec(['./blue']) 3851cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3861cb0ef41Sopenharmony_ci }) 3871cb0ef41Sopenharmony_ci}) 3881cb0ef41Sopenharmony_ci 3891cb0ef41Sopenharmony_cit.test('specific field names', async t => { 3901cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { config: { color: false } }) 3911cb0ef41Sopenharmony_ci t.afterEach(() => outputs.length = 0) 3921cb0ef41Sopenharmony_ci 3931cb0ef41Sopenharmony_ci t.test('readme', async t => { 3941cb0ef41Sopenharmony_ci await view.exec(['yellow@1.0.0', 'readme']) 3951cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 3961cb0ef41Sopenharmony_ci }) 3971cb0ef41Sopenharmony_ci 3981cb0ef41Sopenharmony_ci t.test('several fields', async t => { 3991cb0ef41Sopenharmony_ci await view.exec(['yellow@1.0.0', 'name', 'version', 'foo[bar]']) 4001cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4011cb0ef41Sopenharmony_ci }) 4021cb0ef41Sopenharmony_ci 4031cb0ef41Sopenharmony_ci t.test('several fields with several versions', async t => { 4041cb0ef41Sopenharmony_ci await view.exec(['yellow@1.x.x', 'author']) 4051cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4061cb0ef41Sopenharmony_ci }) 4071cb0ef41Sopenharmony_ci 4081cb0ef41Sopenharmony_ci t.test('nested field with brackets', async t => { 4091cb0ef41Sopenharmony_ci await view.exec(['orange@1.0.0', 'dist[shasum]']) 4101cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4111cb0ef41Sopenharmony_ci }) 4121cb0ef41Sopenharmony_ci 4131cb0ef41Sopenharmony_ci t.test('maintainers with email', async t => { 4141cb0ef41Sopenharmony_ci await view.exec(['yellow@1.0.0', 'maintainers', 'name']) 4151cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4161cb0ef41Sopenharmony_ci }) 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_ci t.test('maintainers with url', async t => { 4191cb0ef41Sopenharmony_ci await view.exec(['pink@1.0.0', 'maintainers']) 4201cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4211cb0ef41Sopenharmony_ci }) 4221cb0ef41Sopenharmony_ci 4231cb0ef41Sopenharmony_ci t.test('unknown nested field ', async t => { 4241cb0ef41Sopenharmony_ci await view.exec(['yellow@1.0.0', 'dist.foobar']) 4251cb0ef41Sopenharmony_ci t.equal(outputs.join('\n'), '', 'no info to display') 4261cb0ef41Sopenharmony_ci }) 4271cb0ef41Sopenharmony_ci 4281cb0ef41Sopenharmony_ci t.test('array field - 1 element', async t => { 4291cb0ef41Sopenharmony_ci await view.exec(['purple@1.0.0', 'maintainers.name']) 4301cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4311cb0ef41Sopenharmony_ci }) 4321cb0ef41Sopenharmony_ci 4331cb0ef41Sopenharmony_ci t.test('array field - 2 elements', async t => { 4341cb0ef41Sopenharmony_ci await view.exec(['yellow@1.x.x', 'maintainers.name']) 4351cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4361cb0ef41Sopenharmony_ci }) 4371cb0ef41Sopenharmony_ci 4381cb0ef41Sopenharmony_ci t.test('fields with empty values', async t => { 4391cb0ef41Sopenharmony_ci await view.exec(['yellow', 'empty']) 4401cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 4411cb0ef41Sopenharmony_ci }) 4421cb0ef41Sopenharmony_ci}) 4431cb0ef41Sopenharmony_ci 4441cb0ef41Sopenharmony_cit.test('throw error if global mode', async t => { 4451cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { config: { global: true } }) 4461cb0ef41Sopenharmony_ci await t.rejects( 4471cb0ef41Sopenharmony_ci npm.exec('view', []), 4481cb0ef41Sopenharmony_ci /Cannot use view command in global mode./ 4491cb0ef41Sopenharmony_ci ) 4501cb0ef41Sopenharmony_ci}) 4511cb0ef41Sopenharmony_ci 4521cb0ef41Sopenharmony_cit.test('throw ENOENT error if package.json missing', async t => { 4531cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t) 4541cb0ef41Sopenharmony_ci await t.rejects( 4551cb0ef41Sopenharmony_ci npm.exec('view', []), 4561cb0ef41Sopenharmony_ci { code: 'ENOENT' } 4571cb0ef41Sopenharmony_ci ) 4581cb0ef41Sopenharmony_ci}) 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_cit.test('throw error if package.json has no name', async t => { 4611cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 4621cb0ef41Sopenharmony_ci prefixDir: { 4631cb0ef41Sopenharmony_ci 'package.json': '{}', 4641cb0ef41Sopenharmony_ci }, 4651cb0ef41Sopenharmony_ci }) 4661cb0ef41Sopenharmony_ci await t.rejects( 4671cb0ef41Sopenharmony_ci npm.exec('view', []), 4681cb0ef41Sopenharmony_ci /Invalid package.json, no "name" field/ 4691cb0ef41Sopenharmony_ci ) 4701cb0ef41Sopenharmony_ci}) 4711cb0ef41Sopenharmony_ci 4721cb0ef41Sopenharmony_cit.test('throws when unpublished', async t => { 4731cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t) 4741cb0ef41Sopenharmony_ci await t.rejects( 4751cb0ef41Sopenharmony_ci npm.exec('view', ['red']), 4761cb0ef41Sopenharmony_ci { code: 'E404', pkgid: 'red@1.0.1', message: 'Unpublished on 2012-12-20T00:00:00.000Z' } 4771cb0ef41Sopenharmony_ci ) 4781cb0ef41Sopenharmony_ci}) 4791cb0ef41Sopenharmony_ci 4801cb0ef41Sopenharmony_cit.test('throws when version not matched', async t => { 4811cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t) 4821cb0ef41Sopenharmony_ci await t.rejects( 4831cb0ef41Sopenharmony_ci npm.exec('view', ['blue@2.0.0']), 4841cb0ef41Sopenharmony_ci { code: 'E404', pkgid: 'blue@2.0.0', message: 'No match found for version 2.0.0' } 4851cb0ef41Sopenharmony_ci ) 4861cb0ef41Sopenharmony_ci}) 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_cit.test('workspaces', async t => { 4891cb0ef41Sopenharmony_ci const prefixDir = { 4901cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 4911cb0ef41Sopenharmony_ci name: 'workspaces-test-package', 4921cb0ef41Sopenharmony_ci version: '1.2.3', 4931cb0ef41Sopenharmony_ci workspaces: ['test-workspace-a', 'test-workspace-b'], 4941cb0ef41Sopenharmony_ci }), 4951cb0ef41Sopenharmony_ci 'test-workspace-a': { 4961cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 4971cb0ef41Sopenharmony_ci name: 'green', 4981cb0ef41Sopenharmony_ci version: '1.2.3', 4991cb0ef41Sopenharmony_ci }), 5001cb0ef41Sopenharmony_ci }, 5011cb0ef41Sopenharmony_ci 'test-workspace-b': { 5021cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5031cb0ef41Sopenharmony_ci name: 'orange', 5041cb0ef41Sopenharmony_ci version: '1.2.3', 5051cb0ef41Sopenharmony_ci }), 5061cb0ef41Sopenharmony_ci }, 5071cb0ef41Sopenharmony_ci } 5081cb0ef41Sopenharmony_ci 5091cb0ef41Sopenharmony_ci t.test('all workspaces', async t => { 5101cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5111cb0ef41Sopenharmony_ci prefixDir, 5121cb0ef41Sopenharmony_ci config: { unicode: false, workspaces: true }, 5131cb0ef41Sopenharmony_ci }) 5141cb0ef41Sopenharmony_ci await view.exec([]) 5151cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5161cb0ef41Sopenharmony_ci }) 5171cb0ef41Sopenharmony_ci 5181cb0ef41Sopenharmony_ci t.test('one specific workspace', async t => { 5191cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5201cb0ef41Sopenharmony_ci prefixDir, 5211cb0ef41Sopenharmony_ci config: { unicode: false, workspace: ['green'] }, 5221cb0ef41Sopenharmony_ci }) 5231cb0ef41Sopenharmony_ci await view.exec([]) 5241cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5251cb0ef41Sopenharmony_ci }) 5261cb0ef41Sopenharmony_ci 5271cb0ef41Sopenharmony_ci t.test('all workspaces --json', async t => { 5281cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5291cb0ef41Sopenharmony_ci prefixDir, 5301cb0ef41Sopenharmony_ci config: { unicode: false, workspaces: true, json: true }, 5311cb0ef41Sopenharmony_ci }) 5321cb0ef41Sopenharmony_ci await view.exec([]) 5331cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5341cb0ef41Sopenharmony_ci }) 5351cb0ef41Sopenharmony_ci 5361cb0ef41Sopenharmony_ci t.test('all workspaces single field', async t => { 5371cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5381cb0ef41Sopenharmony_ci prefixDir, 5391cb0ef41Sopenharmony_ci config: { unicode: false, workspaces: true }, 5401cb0ef41Sopenharmony_ci }) 5411cb0ef41Sopenharmony_ci await view.exec(['.', 'name']) 5421cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5431cb0ef41Sopenharmony_ci }) 5441cb0ef41Sopenharmony_ci 5451cb0ef41Sopenharmony_ci t.test('all workspaces nonexistent field', async t => { 5461cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5471cb0ef41Sopenharmony_ci prefixDir, 5481cb0ef41Sopenharmony_ci config: { unicode: false, workspaces: true }, 5491cb0ef41Sopenharmony_ci }) 5501cb0ef41Sopenharmony_ci await view.exec(['.', 'foo']) 5511cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5521cb0ef41Sopenharmony_ci }) 5531cb0ef41Sopenharmony_ci 5541cb0ef41Sopenharmony_ci t.test('all workspaces nonexistent field --json', async t => { 5551cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5561cb0ef41Sopenharmony_ci prefixDir, 5571cb0ef41Sopenharmony_ci config: { unicode: false, workspaces: true, json: true }, 5581cb0ef41Sopenharmony_ci }) 5591cb0ef41Sopenharmony_ci await view.exec(['.', 'foo']) 5601cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5611cb0ef41Sopenharmony_ci }) 5621cb0ef41Sopenharmony_ci 5631cb0ef41Sopenharmony_ci t.test('all workspaces single field --json', async t => { 5641cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5651cb0ef41Sopenharmony_ci prefixDir, 5661cb0ef41Sopenharmony_ci config: { unicode: false, workspaces: true, json: true }, 5671cb0ef41Sopenharmony_ci }) 5681cb0ef41Sopenharmony_ci await view.exec(['.', 'name']) 5691cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5701cb0ef41Sopenharmony_ci }) 5711cb0ef41Sopenharmony_ci 5721cb0ef41Sopenharmony_ci t.test('single workspace --json', async t => { 5731cb0ef41Sopenharmony_ci const { view, outputs } = await loadMockNpm(t, { 5741cb0ef41Sopenharmony_ci prefixDir, 5751cb0ef41Sopenharmony_ci config: { unicode: false, workspace: ['green'], json: true }, 5761cb0ef41Sopenharmony_ci }) 5771cb0ef41Sopenharmony_ci await view.exec([]) 5781cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5791cb0ef41Sopenharmony_ci }) 5801cb0ef41Sopenharmony_ci 5811cb0ef41Sopenharmony_ci t.test('remote package name', async t => { 5821cb0ef41Sopenharmony_ci const { view, logs, outputs } = await loadMockNpm(t, { 5831cb0ef41Sopenharmony_ci prefixDir, 5841cb0ef41Sopenharmony_ci config: { unicode: false, workspaces: true }, 5851cb0ef41Sopenharmony_ci }) 5861cb0ef41Sopenharmony_ci await view.exec(['pink']) 5871cb0ef41Sopenharmony_ci t.matchSnapshot(outputs.join('\n')) 5881cb0ef41Sopenharmony_ci t.matchSnapshot(logs.warn, 'should have warning of ignoring workspaces') 5891cb0ef41Sopenharmony_ci }) 5901cb0ef41Sopenharmony_ci}) 5911cb0ef41Sopenharmony_ci 5921cb0ef41Sopenharmony_cit.test('completion', async t => { 5931cb0ef41Sopenharmony_ci const { view } = await loadMockNpm(t, { command: 'view' }) 5941cb0ef41Sopenharmony_ci const res = await view.completion({ 5951cb0ef41Sopenharmony_ci conf: { argv: { remain: ['npm', 'view', 'green@1.0.0'] } }, 5961cb0ef41Sopenharmony_ci }) 5971cb0ef41Sopenharmony_ci t.ok(res, 'returns back fields') 5981cb0ef41Sopenharmony_ci}) 5991cb0ef41Sopenharmony_ci 6001cb0ef41Sopenharmony_cit.test('no package completion', async t => { 6011cb0ef41Sopenharmony_ci const { view } = await loadMockNpm(t, { command: 'view' }) 6021cb0ef41Sopenharmony_ci const res = await view.completion({ conf: { argv: { remain: ['npm', 'view'] } } }) 6031cb0ef41Sopenharmony_ci t.notOk(res, 'there is no package completion') 6041cb0ef41Sopenharmony_ci t.end() 6051cb0ef41Sopenharmony_ci}) 606