11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ciconst { load: loadMockNpm } = require('../../fixtures/mock-npm')
31cb0ef41Sopenharmony_ciconst { cleanZlib } = require('../../fixtures/clean-snapshot')
41cb0ef41Sopenharmony_ciconst MockRegistry = require('@npmcli/mock-registry')
51cb0ef41Sopenharmony_ciconst pacote = require('pacote')
61cb0ef41Sopenharmony_ciconst Arborist = require('@npmcli/arborist')
71cb0ef41Sopenharmony_ciconst path = require('path')
81cb0ef41Sopenharmony_ciconst fs = require('fs')
91cb0ef41Sopenharmony_ciconst npa = require('npm-package-arg')
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst pkg = 'test-package'
121cb0ef41Sopenharmony_ciconst token = 'test-auth-token'
131cb0ef41Sopenharmony_ciconst auth = { '//registry.npmjs.org/:_authToken': token }
141cb0ef41Sopenharmony_ciconst alternateRegistry = 'https://other.registry.npmjs.org'
151cb0ef41Sopenharmony_ciconst basic = Buffer.from('test-user:test-password').toString('base64')
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciconst pkgJson = {
181cb0ef41Sopenharmony_ci  name: pkg,
191cb0ef41Sopenharmony_ci  description: 'npm test package',
201cb0ef41Sopenharmony_ci  version: '1.0.0',
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cit.cleanSnapshot = data => cleanZlib(data)
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cit.test('respects publishConfig.registry, runs appropriate scripts', async t => {
261cb0ef41Sopenharmony_ci  const { npm, joinedOutput, prefix } = await loadMockNpm(t, {
271cb0ef41Sopenharmony_ci    config: {
281cb0ef41Sopenharmony_ci      loglevel: 'silent',
291cb0ef41Sopenharmony_ci      [`${alternateRegistry.slice(6)}/:_authToken`]: 'test-other-token',
301cb0ef41Sopenharmony_ci    },
311cb0ef41Sopenharmony_ci    prefixDir: {
321cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
331cb0ef41Sopenharmony_ci        ...pkgJson,
341cb0ef41Sopenharmony_ci        scripts: {
351cb0ef41Sopenharmony_ci          prepublishOnly: 'touch scripts-prepublishonly',
361cb0ef41Sopenharmony_ci          prepublish: 'touch scripts-prepublish', // should NOT run this one
371cb0ef41Sopenharmony_ci          publish: 'touch scripts-publish',
381cb0ef41Sopenharmony_ci          postpublish: 'touch scripts-postpublish',
391cb0ef41Sopenharmony_ci        },
401cb0ef41Sopenharmony_ci        publishConfig: { registry: alternateRegistry },
411cb0ef41Sopenharmony_ci      }, null, 2),
421cb0ef41Sopenharmony_ci    },
431cb0ef41Sopenharmony_ci  })
441cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
451cb0ef41Sopenharmony_ci    tap: t,
461cb0ef41Sopenharmony_ci    registry: alternateRegistry,
471cb0ef41Sopenharmony_ci    authorization: 'test-other-token',
481cb0ef41Sopenharmony_ci  })
491cb0ef41Sopenharmony_ci  registry.nock.put(`/${pkg}`, body => {
501cb0ef41Sopenharmony_ci    return t.match(body, {
511cb0ef41Sopenharmony_ci      _id: pkg,
521cb0ef41Sopenharmony_ci      name: pkg,
531cb0ef41Sopenharmony_ci      'dist-tags': { latest: '1.0.0' },
541cb0ef41Sopenharmony_ci      access: null,
551cb0ef41Sopenharmony_ci      versions: {
561cb0ef41Sopenharmony_ci        '1.0.0': {
571cb0ef41Sopenharmony_ci          name: pkg,
581cb0ef41Sopenharmony_ci          version: '1.0.0',
591cb0ef41Sopenharmony_ci          _id: `${pkg}@1.0.0`,
601cb0ef41Sopenharmony_ci          dist: {
611cb0ef41Sopenharmony_ci            shasum: /\.*/,
621cb0ef41Sopenharmony_ci            tarball: `http:${alternateRegistry.slice(6)}/test-package/-/test-package-1.0.0.tgz`,
631cb0ef41Sopenharmony_ci          },
641cb0ef41Sopenharmony_ci          publishConfig: {
651cb0ef41Sopenharmony_ci            registry: alternateRegistry,
661cb0ef41Sopenharmony_ci          },
671cb0ef41Sopenharmony_ci        },
681cb0ef41Sopenharmony_ci      },
691cb0ef41Sopenharmony_ci      _attachments: {
701cb0ef41Sopenharmony_ci        [`${pkg}-1.0.0.tgz`]: {},
711cb0ef41Sopenharmony_ci      },
721cb0ef41Sopenharmony_ci    })
731cb0ef41Sopenharmony_ci  }).reply(200, {})
741cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
751cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
761cb0ef41Sopenharmony_ci  t.equal(fs.existsSync(path.join(prefix, 'scripts-prepublishonly')), true, 'ran prepublishOnly')
771cb0ef41Sopenharmony_ci  t.equal(fs.existsSync(path.join(prefix, 'scripts-prepublish')), false, 'did not run prepublish')
781cb0ef41Sopenharmony_ci  t.equal(fs.existsSync(path.join(prefix, 'scripts-publish')), true, 'ran publish')
791cb0ef41Sopenharmony_ci  t.equal(fs.existsSync(path.join(prefix, 'scripts-postpublish')), true, 'ran postpublish')
801cb0ef41Sopenharmony_ci})
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_cit.test('re-loads publishConfig.registry if added during script process', async t => {
831cb0ef41Sopenharmony_ci  const { joinedOutput, npm } = await loadMockNpm(t, {
841cb0ef41Sopenharmony_ci    config: {
851cb0ef41Sopenharmony_ci      [`${alternateRegistry.slice(6)}/:_authToken`]: 'test-other-token',
861cb0ef41Sopenharmony_ci    },
871cb0ef41Sopenharmony_ci    prefixDir: {
881cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
891cb0ef41Sopenharmony_ci        ...pkgJson,
901cb0ef41Sopenharmony_ci        scripts: {
911cb0ef41Sopenharmony_ci          prepare: 'cp new.json package.json',
921cb0ef41Sopenharmony_ci        },
931cb0ef41Sopenharmony_ci      }, null, 2),
941cb0ef41Sopenharmony_ci      'new.json': JSON.stringify({
951cb0ef41Sopenharmony_ci        ...pkgJson,
961cb0ef41Sopenharmony_ci        publishConfig: { registry: alternateRegistry },
971cb0ef41Sopenharmony_ci      }),
981cb0ef41Sopenharmony_ci    },
991cb0ef41Sopenharmony_ci  })
1001cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
1011cb0ef41Sopenharmony_ci    tap: t,
1021cb0ef41Sopenharmony_ci    registry: alternateRegistry,
1031cb0ef41Sopenharmony_ci    authorization: 'test-other-token',
1041cb0ef41Sopenharmony_ci  })
1051cb0ef41Sopenharmony_ci  registry.nock.put(`/${pkg}`, body => {
1061cb0ef41Sopenharmony_ci    return t.match(body, {
1071cb0ef41Sopenharmony_ci      _id: pkg,
1081cb0ef41Sopenharmony_ci      name: pkg,
1091cb0ef41Sopenharmony_ci      'dist-tags': { latest: '1.0.0' },
1101cb0ef41Sopenharmony_ci      access: null,
1111cb0ef41Sopenharmony_ci      versions: {
1121cb0ef41Sopenharmony_ci        '1.0.0': {
1131cb0ef41Sopenharmony_ci          name: pkg,
1141cb0ef41Sopenharmony_ci          version: '1.0.0',
1151cb0ef41Sopenharmony_ci          _id: `${pkg}@1.0.0`,
1161cb0ef41Sopenharmony_ci          dist: {
1171cb0ef41Sopenharmony_ci            shasum: /\.*/,
1181cb0ef41Sopenharmony_ci            tarball: `http:${alternateRegistry.slice(6)}/test-package/-/test-package-1.0.0.tgz`,
1191cb0ef41Sopenharmony_ci          },
1201cb0ef41Sopenharmony_ci          publishConfig: {
1211cb0ef41Sopenharmony_ci            registry: alternateRegistry,
1221cb0ef41Sopenharmony_ci          },
1231cb0ef41Sopenharmony_ci        },
1241cb0ef41Sopenharmony_ci      },
1251cb0ef41Sopenharmony_ci      _attachments: {
1261cb0ef41Sopenharmony_ci        [`${pkg}-1.0.0.tgz`]: {},
1271cb0ef41Sopenharmony_ci      },
1281cb0ef41Sopenharmony_ci    })
1291cb0ef41Sopenharmony_ci  }).reply(200, {})
1301cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
1311cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
1321cb0ef41Sopenharmony_ci})
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_cit.test('json', async t => {
1351cb0ef41Sopenharmony_ci  const { joinedOutput, npm, logs } = await loadMockNpm(t, {
1361cb0ef41Sopenharmony_ci    config: {
1371cb0ef41Sopenharmony_ci      json: true,
1381cb0ef41Sopenharmony_ci      ...auth,
1391cb0ef41Sopenharmony_ci    },
1401cb0ef41Sopenharmony_ci    prefixDir: {
1411cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(pkgJson, null, 2),
1421cb0ef41Sopenharmony_ci    },
1431cb0ef41Sopenharmony_ci  })
1441cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
1451cb0ef41Sopenharmony_ci    tap: t,
1461cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
1471cb0ef41Sopenharmony_ci    authorization: token,
1481cb0ef41Sopenharmony_ci  })
1491cb0ef41Sopenharmony_ci  registry.nock.put(`/${pkg}`).reply(200, {})
1501cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
1511cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.notice)
1521cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package json')
1531cb0ef41Sopenharmony_ci})
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_cit.test('dry-run', async t => {
1561cb0ef41Sopenharmony_ci  const { joinedOutput, npm, logs } = await loadMockNpm(t, {
1571cb0ef41Sopenharmony_ci    config: {
1581cb0ef41Sopenharmony_ci      'dry-run': true,
1591cb0ef41Sopenharmony_ci      ...auth,
1601cb0ef41Sopenharmony_ci    },
1611cb0ef41Sopenharmony_ci    prefixDir: {
1621cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(pkgJson, null, 2),
1631cb0ef41Sopenharmony_ci    },
1641cb0ef41Sopenharmony_ci  })
1651cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
1661cb0ef41Sopenharmony_ci  t.equal(joinedOutput(), `+ ${pkg}@1.0.0`)
1671cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.notice)
1681cb0ef41Sopenharmony_ci})
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_cit.test('foreground-scripts defaults to true', async t => {
1711cb0ef41Sopenharmony_ci  const { joinedOutput, npm, logs } = await loadMockNpm(t, {
1721cb0ef41Sopenharmony_ci    config: {
1731cb0ef41Sopenharmony_ci      'dry-run': true,
1741cb0ef41Sopenharmony_ci      ...auth,
1751cb0ef41Sopenharmony_ci    },
1761cb0ef41Sopenharmony_ci    prefixDir: {
1771cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
1781cb0ef41Sopenharmony_ci        name: 'test-fg-scripts',
1791cb0ef41Sopenharmony_ci        version: '0.0.0',
1801cb0ef41Sopenharmony_ci        scripts: {
1811cb0ef41Sopenharmony_ci          prepack: 'echo prepack!',
1821cb0ef41Sopenharmony_ci          postpack: 'echo postpack!',
1831cb0ef41Sopenharmony_ci        },
1841cb0ef41Sopenharmony_ci      }
1851cb0ef41Sopenharmony_ci      ),
1861cb0ef41Sopenharmony_ci    },
1871cb0ef41Sopenharmony_ci  })
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ci  /* eslint no-console: 0 */
1901cb0ef41Sopenharmony_ci  // TODO: replace this with `const results = t.intercept(console, 'log')`
1911cb0ef41Sopenharmony_ci  const log = console.log
1921cb0ef41Sopenharmony_ci  t.teardown(() => {
1931cb0ef41Sopenharmony_ci    console.log = log
1941cb0ef41Sopenharmony_ci  })
1951cb0ef41Sopenharmony_ci  const caughtLogs = []
1961cb0ef41Sopenharmony_ci  console.log = (...args) => {
1971cb0ef41Sopenharmony_ci    caughtLogs.push(args)
1981cb0ef41Sopenharmony_ci  }
1991cb0ef41Sopenharmony_ci  // end TODO
2001cb0ef41Sopenharmony_ci
2011cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
2021cb0ef41Sopenharmony_ci  t.equal(joinedOutput(), `+ test-fg-scripts@0.0.0`)
2031cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.notice)
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci  t.same(
2061cb0ef41Sopenharmony_ci    caughtLogs,
2071cb0ef41Sopenharmony_ci    [
2081cb0ef41Sopenharmony_ci      ['\n> test-fg-scripts@0.0.0 prepack\n> echo prepack!\n'],
2091cb0ef41Sopenharmony_ci      ['\n> test-fg-scripts@0.0.0 postpack\n> echo postpack!\n'],
2101cb0ef41Sopenharmony_ci    ],
2111cb0ef41Sopenharmony_ci    'prepack and postpack log to stdout')
2121cb0ef41Sopenharmony_ci})
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_cit.test('foreground-scripts can still be set to false', async t => {
2151cb0ef41Sopenharmony_ci  const { joinedOutput, npm, logs } = await loadMockNpm(t, {
2161cb0ef41Sopenharmony_ci    config: {
2171cb0ef41Sopenharmony_ci      'dry-run': true,
2181cb0ef41Sopenharmony_ci      'foreground-scripts': false,
2191cb0ef41Sopenharmony_ci      ...auth,
2201cb0ef41Sopenharmony_ci    },
2211cb0ef41Sopenharmony_ci    prefixDir: {
2221cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
2231cb0ef41Sopenharmony_ci        name: 'test-fg-scripts',
2241cb0ef41Sopenharmony_ci        version: '0.0.0',
2251cb0ef41Sopenharmony_ci        scripts: {
2261cb0ef41Sopenharmony_ci          prepack: 'echo prepack!',
2271cb0ef41Sopenharmony_ci          postpack: 'echo postpack!',
2281cb0ef41Sopenharmony_ci        },
2291cb0ef41Sopenharmony_ci      }
2301cb0ef41Sopenharmony_ci      ),
2311cb0ef41Sopenharmony_ci    },
2321cb0ef41Sopenharmony_ci  })
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci  /* eslint no-console: 0 */
2351cb0ef41Sopenharmony_ci  // TODO: replace this with `const results = t.intercept(console, 'log')`
2361cb0ef41Sopenharmony_ci  const log = console.log
2371cb0ef41Sopenharmony_ci  t.teardown(() => {
2381cb0ef41Sopenharmony_ci    console.log = log
2391cb0ef41Sopenharmony_ci  })
2401cb0ef41Sopenharmony_ci  const caughtLogs = []
2411cb0ef41Sopenharmony_ci  console.log = (...args) => {
2421cb0ef41Sopenharmony_ci    caughtLogs.push(args)
2431cb0ef41Sopenharmony_ci  }
2441cb0ef41Sopenharmony_ci  // end TODO
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
2471cb0ef41Sopenharmony_ci  t.equal(joinedOutput(), `+ test-fg-scripts@0.0.0`)
2481cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.notice)
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_ci  t.same(
2511cb0ef41Sopenharmony_ci    caughtLogs,
2521cb0ef41Sopenharmony_ci    [],
2531cb0ef41Sopenharmony_ci    'prepack and postpack do not log to stdout')
2541cb0ef41Sopenharmony_ci})
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_cit.test('shows usage with wrong set of arguments', async t => {
2571cb0ef41Sopenharmony_ci  const { publish } = await loadMockNpm(t, { command: 'publish' })
2581cb0ef41Sopenharmony_ci  await t.rejects(publish.exec(['a', 'b', 'c']), publish.usage)
2591cb0ef41Sopenharmony_ci})
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_cit.test('throws when invalid tag', async t => {
2621cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t, {
2631cb0ef41Sopenharmony_ci    config: {
2641cb0ef41Sopenharmony_ci      tag: '0.0.13',
2651cb0ef41Sopenharmony_ci    },
2661cb0ef41Sopenharmony_ci    prefixDir: {
2671cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(pkgJson, null, 2),
2681cb0ef41Sopenharmony_ci    },
2691cb0ef41Sopenharmony_ci  })
2701cb0ef41Sopenharmony_ci  await t.rejects(
2711cb0ef41Sopenharmony_ci    npm.exec('publish', []),
2721cb0ef41Sopenharmony_ci    { message: 'Tag name must not be a valid SemVer range: 0.0.13' }
2731cb0ef41Sopenharmony_ci  )
2741cb0ef41Sopenharmony_ci})
2751cb0ef41Sopenharmony_ci
2761cb0ef41Sopenharmony_cit.test('tarball', async t => {
2771cb0ef41Sopenharmony_ci  const { npm, joinedOutput, logs, home } = await loadMockNpm(t, {
2781cb0ef41Sopenharmony_ci    config: {
2791cb0ef41Sopenharmony_ci      'fetch-retries': 0,
2801cb0ef41Sopenharmony_ci      ...auth,
2811cb0ef41Sopenharmony_ci    },
2821cb0ef41Sopenharmony_ci    homeDir: {
2831cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
2841cb0ef41Sopenharmony_ci        name: 'test-tar-package',
2851cb0ef41Sopenharmony_ci        description: 'this was from a tarball',
2861cb0ef41Sopenharmony_ci        version: '1.0.0',
2871cb0ef41Sopenharmony_ci      }, null, 2),
2881cb0ef41Sopenharmony_ci      'index.js': 'console.log("hello world"}',
2891cb0ef41Sopenharmony_ci    },
2901cb0ef41Sopenharmony_ci  })
2911cb0ef41Sopenharmony_ci  const tarball = await pacote.tarball(home, { Arborist })
2921cb0ef41Sopenharmony_ci  const tarFilename = path.join(home, 'tarball.tgz')
2931cb0ef41Sopenharmony_ci  fs.writeFileSync(tarFilename, tarball)
2941cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
2951cb0ef41Sopenharmony_ci    tap: t,
2961cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
2971cb0ef41Sopenharmony_ci    authorization: token,
2981cb0ef41Sopenharmony_ci  })
2991cb0ef41Sopenharmony_ci  registry.nock.put('/test-tar-package', body => {
3001cb0ef41Sopenharmony_ci    return t.match(body, {
3011cb0ef41Sopenharmony_ci      name: 'test-tar-package',
3021cb0ef41Sopenharmony_ci    })
3031cb0ef41Sopenharmony_ci  }).reply(200, {})
3041cb0ef41Sopenharmony_ci  await npm.exec('publish', [tarFilename])
3051cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.notice)
3061cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package json')
3071cb0ef41Sopenharmony_ci})
3081cb0ef41Sopenharmony_ci
3091cb0ef41Sopenharmony_cit.test('no auth default registry', async t => {
3101cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t, {
3111cb0ef41Sopenharmony_ci    prefixDir: {
3121cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(pkgJson, null, 2),
3131cb0ef41Sopenharmony_ci    },
3141cb0ef41Sopenharmony_ci  })
3151cb0ef41Sopenharmony_ci  await t.rejects(
3161cb0ef41Sopenharmony_ci    npm.exec('publish', []),
3171cb0ef41Sopenharmony_ci    {
3181cb0ef41Sopenharmony_ci      message: 'This command requires you to be logged in to https://registry.npmjs.org/',
3191cb0ef41Sopenharmony_ci      code: 'ENEEDAUTH',
3201cb0ef41Sopenharmony_ci    }
3211cb0ef41Sopenharmony_ci  )
3221cb0ef41Sopenharmony_ci})
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_cit.test('no auth dry-run', async t => {
3251cb0ef41Sopenharmony_ci  const { npm, joinedOutput, logs } = await loadMockNpm(t, {
3261cb0ef41Sopenharmony_ci    config: {
3271cb0ef41Sopenharmony_ci      'dry-run': true,
3281cb0ef41Sopenharmony_ci    },
3291cb0ef41Sopenharmony_ci    prefixDir: {
3301cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(pkgJson, null, 2),
3311cb0ef41Sopenharmony_ci    },
3321cb0ef41Sopenharmony_ci  })
3331cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
3341cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput())
3351cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.warn, 'warns about auth being needed')
3361cb0ef41Sopenharmony_ci})
3371cb0ef41Sopenharmony_ci
3381cb0ef41Sopenharmony_cit.test('no auth for configured registry', async t => {
3391cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t, {
3401cb0ef41Sopenharmony_ci    config: {
3411cb0ef41Sopenharmony_ci      registry: alternateRegistry,
3421cb0ef41Sopenharmony_ci      ...auth,
3431cb0ef41Sopenharmony_ci    },
3441cb0ef41Sopenharmony_ci    prefixDir: {
3451cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(pkgJson, null, 2),
3461cb0ef41Sopenharmony_ci    },
3471cb0ef41Sopenharmony_ci  })
3481cb0ef41Sopenharmony_ci  await t.rejects(
3491cb0ef41Sopenharmony_ci    npm.exec('publish', []),
3501cb0ef41Sopenharmony_ci    {
3511cb0ef41Sopenharmony_ci      message: `This command requires you to be logged in to ${alternateRegistry}`,
3521cb0ef41Sopenharmony_ci      code: 'ENEEDAUTH',
3531cb0ef41Sopenharmony_ci    }
3541cb0ef41Sopenharmony_ci  )
3551cb0ef41Sopenharmony_ci})
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_cit.test('no auth for scope configured registry', async t => {
3581cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t, {
3591cb0ef41Sopenharmony_ci    config: {
3601cb0ef41Sopenharmony_ci      scope: '@npm',
3611cb0ef41Sopenharmony_ci      registry: alternateRegistry,
3621cb0ef41Sopenharmony_ci      ...auth,
3631cb0ef41Sopenharmony_ci    },
3641cb0ef41Sopenharmony_ci    prefixDir: {
3651cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
3661cb0ef41Sopenharmony_ci        name: '@npm/test-package',
3671cb0ef41Sopenharmony_ci        version: '1.0.0',
3681cb0ef41Sopenharmony_ci      }, null, 2),
3691cb0ef41Sopenharmony_ci    },
3701cb0ef41Sopenharmony_ci  })
3711cb0ef41Sopenharmony_ci  await t.rejects(
3721cb0ef41Sopenharmony_ci    npm.exec('publish', []),
3731cb0ef41Sopenharmony_ci    {
3741cb0ef41Sopenharmony_ci      message: `This command requires you to be logged in to ${alternateRegistry}`,
3751cb0ef41Sopenharmony_ci      code: 'ENEEDAUTH',
3761cb0ef41Sopenharmony_ci    }
3771cb0ef41Sopenharmony_ci  )
3781cb0ef41Sopenharmony_ci})
3791cb0ef41Sopenharmony_ci
3801cb0ef41Sopenharmony_cit.test('has token auth for scope configured registry', async t => {
3811cb0ef41Sopenharmony_ci  const spec = npa('@npm/test-package')
3821cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await loadMockNpm(t, {
3831cb0ef41Sopenharmony_ci    config: {
3841cb0ef41Sopenharmony_ci      scope: '@npm',
3851cb0ef41Sopenharmony_ci      registry: alternateRegistry,
3861cb0ef41Sopenharmony_ci      [`${alternateRegistry.slice(6)}/:_authToken`]: 'test-scope-token',
3871cb0ef41Sopenharmony_ci    },
3881cb0ef41Sopenharmony_ci    prefixDir: {
3891cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
3901cb0ef41Sopenharmony_ci        name: '@npm/test-package',
3911cb0ef41Sopenharmony_ci        version: '1.0.0',
3921cb0ef41Sopenharmony_ci      }, null, 2),
3931cb0ef41Sopenharmony_ci    },
3941cb0ef41Sopenharmony_ci  })
3951cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
3961cb0ef41Sopenharmony_ci    tap: t,
3971cb0ef41Sopenharmony_ci    registry: alternateRegistry,
3981cb0ef41Sopenharmony_ci    authorization: 'test-scope-token',
3991cb0ef41Sopenharmony_ci  })
4001cb0ef41Sopenharmony_ci  registry.nock.put(`/${spec.escapedName}`, body => {
4011cb0ef41Sopenharmony_ci    return t.match(body, { name: '@npm/test-package' })
4021cb0ef41Sopenharmony_ci  }).reply(200, {})
4031cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
4041cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
4051cb0ef41Sopenharmony_ci})
4061cb0ef41Sopenharmony_ci
4071cb0ef41Sopenharmony_cit.test('has mTLS auth for scope configured registry', async t => {
4081cb0ef41Sopenharmony_ci  const spec = npa('@npm/test-package')
4091cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await loadMockNpm(t, {
4101cb0ef41Sopenharmony_ci    config: {
4111cb0ef41Sopenharmony_ci      scope: '@npm',
4121cb0ef41Sopenharmony_ci      registry: alternateRegistry,
4131cb0ef41Sopenharmony_ci      [`${alternateRegistry.slice(6)}/:certfile`]: '/some.cert',
4141cb0ef41Sopenharmony_ci      [`${alternateRegistry.slice(6)}/:keyfile`]: '/some.key',
4151cb0ef41Sopenharmony_ci    },
4161cb0ef41Sopenharmony_ci    prefixDir: {
4171cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
4181cb0ef41Sopenharmony_ci        name: '@npm/test-package',
4191cb0ef41Sopenharmony_ci        version: '1.0.0',
4201cb0ef41Sopenharmony_ci      }, null, 2),
4211cb0ef41Sopenharmony_ci    },
4221cb0ef41Sopenharmony_ci  })
4231cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
4241cb0ef41Sopenharmony_ci    tap: t,
4251cb0ef41Sopenharmony_ci    registry: alternateRegistry,
4261cb0ef41Sopenharmony_ci  })
4271cb0ef41Sopenharmony_ci  registry.nock.put(`/${spec.escapedName}`, body => {
4281cb0ef41Sopenharmony_ci    return t.match(body, { name: '@npm/test-package' })
4291cb0ef41Sopenharmony_ci  }).reply(200, {})
4301cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
4311cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
4321cb0ef41Sopenharmony_ci})
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_cit.test('workspaces', t => {
4351cb0ef41Sopenharmony_ci  const dir = {
4361cb0ef41Sopenharmony_ci    'package.json': JSON.stringify(
4371cb0ef41Sopenharmony_ci      {
4381cb0ef41Sopenharmony_ci        ...pkgJson,
4391cb0ef41Sopenharmony_ci        workspaces: ['workspace-a', 'workspace-b', 'workspace-c', 'workspace-p'],
4401cb0ef41Sopenharmony_ci      }, null, 2),
4411cb0ef41Sopenharmony_ci    'workspace-a': {
4421cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
4431cb0ef41Sopenharmony_ci        name: 'workspace-a',
4441cb0ef41Sopenharmony_ci        version: '1.2.3-a',
4451cb0ef41Sopenharmony_ci        repository: 'http://repo.workspace-a/',
4461cb0ef41Sopenharmony_ci      }),
4471cb0ef41Sopenharmony_ci    },
4481cb0ef41Sopenharmony_ci    'workspace-b': {
4491cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
4501cb0ef41Sopenharmony_ci        name: 'workspace-b',
4511cb0ef41Sopenharmony_ci        version: '1.2.3-n',
4521cb0ef41Sopenharmony_ci        repository: 'https://github.com/npm/workspace-b',
4531cb0ef41Sopenharmony_ci      }),
4541cb0ef41Sopenharmony_ci    },
4551cb0ef41Sopenharmony_ci    'workspace-c': {
4561cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
4571cb0ef41Sopenharmony_ci        name: 'workspace-n',
4581cb0ef41Sopenharmony_ci        version: '1.2.3-n',
4591cb0ef41Sopenharmony_ci      }),
4601cb0ef41Sopenharmony_ci    },
4611cb0ef41Sopenharmony_ci    'workspace-p': {
4621cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
4631cb0ef41Sopenharmony_ci        name: 'workspace-p',
4641cb0ef41Sopenharmony_ci        version: '1.2.3-p',
4651cb0ef41Sopenharmony_ci        private: true,
4661cb0ef41Sopenharmony_ci      }),
4671cb0ef41Sopenharmony_ci    },
4681cb0ef41Sopenharmony_ci  }
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_ci  t.test('all workspaces - no color', async t => {
4711cb0ef41Sopenharmony_ci    const { npm, joinedOutput, logs } = await loadMockNpm(t, {
4721cb0ef41Sopenharmony_ci      config: {
4731cb0ef41Sopenharmony_ci        color: false,
4741cb0ef41Sopenharmony_ci        ...auth,
4751cb0ef41Sopenharmony_ci        workspaces: true,
4761cb0ef41Sopenharmony_ci      },
4771cb0ef41Sopenharmony_ci      prefixDir: dir,
4781cb0ef41Sopenharmony_ci    })
4791cb0ef41Sopenharmony_ci    const registry = new MockRegistry({
4801cb0ef41Sopenharmony_ci      tap: t,
4811cb0ef41Sopenharmony_ci      registry: npm.config.get('registry'),
4821cb0ef41Sopenharmony_ci      authorization: token,
4831cb0ef41Sopenharmony_ci    })
4841cb0ef41Sopenharmony_ci    registry.nock
4851cb0ef41Sopenharmony_ci      .put('/workspace-a', body => {
4861cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-a' })
4871cb0ef41Sopenharmony_ci      }).reply(200, {})
4881cb0ef41Sopenharmony_ci      .put('/workspace-b', body => {
4891cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-b' })
4901cb0ef41Sopenharmony_ci      }).reply(200, {})
4911cb0ef41Sopenharmony_ci      .put('/workspace-n', body => {
4921cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-n' })
4931cb0ef41Sopenharmony_ci      }).reply(200, {})
4941cb0ef41Sopenharmony_ci    await npm.exec('publish', [])
4951cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'all public workspaces')
4961cb0ef41Sopenharmony_ci    t.matchSnapshot(logs.warn, 'warns about skipped private workspace')
4971cb0ef41Sopenharmony_ci  })
4981cb0ef41Sopenharmony_ci
4991cb0ef41Sopenharmony_ci  t.test('all workspaces - color', async t => {
5001cb0ef41Sopenharmony_ci    const { npm, joinedOutput, logs } = await loadMockNpm(t, {
5011cb0ef41Sopenharmony_ci      config: {
5021cb0ef41Sopenharmony_ci        ...auth,
5031cb0ef41Sopenharmony_ci        color: 'always',
5041cb0ef41Sopenharmony_ci        workspaces: true,
5051cb0ef41Sopenharmony_ci      },
5061cb0ef41Sopenharmony_ci      prefixDir: dir,
5071cb0ef41Sopenharmony_ci    })
5081cb0ef41Sopenharmony_ci    const registry = new MockRegistry({
5091cb0ef41Sopenharmony_ci      tap: t,
5101cb0ef41Sopenharmony_ci      registry: npm.config.get('registry'),
5111cb0ef41Sopenharmony_ci      authorization: token,
5121cb0ef41Sopenharmony_ci    })
5131cb0ef41Sopenharmony_ci    registry.nock
5141cb0ef41Sopenharmony_ci      .put('/workspace-a', body => {
5151cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-a' })
5161cb0ef41Sopenharmony_ci      }).reply(200, {})
5171cb0ef41Sopenharmony_ci      .put('/workspace-b', body => {
5181cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-b' })
5191cb0ef41Sopenharmony_ci      }).reply(200, {})
5201cb0ef41Sopenharmony_ci      .put('/workspace-n', body => {
5211cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-n' })
5221cb0ef41Sopenharmony_ci      }).reply(200, {})
5231cb0ef41Sopenharmony_ci    await npm.exec('publish', [])
5241cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'all public workspaces')
5251cb0ef41Sopenharmony_ci    t.matchSnapshot(logs.warn, 'warns about skipped private workspace in color')
5261cb0ef41Sopenharmony_ci  })
5271cb0ef41Sopenharmony_ci
5281cb0ef41Sopenharmony_ci  t.test('one workspace - success', async t => {
5291cb0ef41Sopenharmony_ci    const { npm, joinedOutput } = await loadMockNpm(t, {
5301cb0ef41Sopenharmony_ci      config: {
5311cb0ef41Sopenharmony_ci        ...auth,
5321cb0ef41Sopenharmony_ci        workspace: ['workspace-a'],
5331cb0ef41Sopenharmony_ci      },
5341cb0ef41Sopenharmony_ci      prefixDir: dir,
5351cb0ef41Sopenharmony_ci    })
5361cb0ef41Sopenharmony_ci    const registry = new MockRegistry({
5371cb0ef41Sopenharmony_ci      tap: t,
5381cb0ef41Sopenharmony_ci      registry: npm.config.get('registry'),
5391cb0ef41Sopenharmony_ci      authorization: token,
5401cb0ef41Sopenharmony_ci    })
5411cb0ef41Sopenharmony_ci    registry.nock
5421cb0ef41Sopenharmony_ci      .put('/workspace-a', body => {
5431cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-a' })
5441cb0ef41Sopenharmony_ci      }).reply(200, {})
5451cb0ef41Sopenharmony_ci    await npm.exec('publish', [])
5461cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'single workspace')
5471cb0ef41Sopenharmony_ci  })
5481cb0ef41Sopenharmony_ci
5491cb0ef41Sopenharmony_ci  t.test('one workspace - failure', async t => {
5501cb0ef41Sopenharmony_ci    const { npm } = await loadMockNpm(t, {
5511cb0ef41Sopenharmony_ci      config: {
5521cb0ef41Sopenharmony_ci        ...auth,
5531cb0ef41Sopenharmony_ci        workspace: ['workspace-a'],
5541cb0ef41Sopenharmony_ci      },
5551cb0ef41Sopenharmony_ci      prefixDir: dir,
5561cb0ef41Sopenharmony_ci    })
5571cb0ef41Sopenharmony_ci    const registry = new MockRegistry({
5581cb0ef41Sopenharmony_ci      tap: t,
5591cb0ef41Sopenharmony_ci      registry: npm.config.get('registry'),
5601cb0ef41Sopenharmony_ci      authorization: token,
5611cb0ef41Sopenharmony_ci    })
5621cb0ef41Sopenharmony_ci    registry.nock
5631cb0ef41Sopenharmony_ci      .put('/workspace-a', body => {
5641cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-a' })
5651cb0ef41Sopenharmony_ci      }).reply(404, {})
5661cb0ef41Sopenharmony_ci    await t.rejects(npm.exec('publish', []), { code: 'E404' })
5671cb0ef41Sopenharmony_ci  })
5681cb0ef41Sopenharmony_ci
5691cb0ef41Sopenharmony_ci  t.test('invalid workspace', async t => {
5701cb0ef41Sopenharmony_ci    const { npm } = await loadMockNpm(t, {
5711cb0ef41Sopenharmony_ci      config: {
5721cb0ef41Sopenharmony_ci        ...auth,
5731cb0ef41Sopenharmony_ci        workspace: ['workspace-x'],
5741cb0ef41Sopenharmony_ci      },
5751cb0ef41Sopenharmony_ci      prefixDir: dir,
5761cb0ef41Sopenharmony_ci    })
5771cb0ef41Sopenharmony_ci    await t.rejects(
5781cb0ef41Sopenharmony_ci      npm.exec('publish', []),
5791cb0ef41Sopenharmony_ci      { message: 'No workspaces found:\n  --workspace=workspace-x' }
5801cb0ef41Sopenharmony_ci    )
5811cb0ef41Sopenharmony_ci  })
5821cb0ef41Sopenharmony_ci
5831cb0ef41Sopenharmony_ci  t.test('json', async t => {
5841cb0ef41Sopenharmony_ci    const { npm, joinedOutput } = await loadMockNpm(t, {
5851cb0ef41Sopenharmony_ci      config: {
5861cb0ef41Sopenharmony_ci        ...auth,
5871cb0ef41Sopenharmony_ci        workspaces: true,
5881cb0ef41Sopenharmony_ci        json: true,
5891cb0ef41Sopenharmony_ci      },
5901cb0ef41Sopenharmony_ci      prefixDir: dir,
5911cb0ef41Sopenharmony_ci    })
5921cb0ef41Sopenharmony_ci    const registry = new MockRegistry({
5931cb0ef41Sopenharmony_ci      tap: t,
5941cb0ef41Sopenharmony_ci      registry: npm.config.get('registry'),
5951cb0ef41Sopenharmony_ci      authorization: token,
5961cb0ef41Sopenharmony_ci    })
5971cb0ef41Sopenharmony_ci    registry.nock
5981cb0ef41Sopenharmony_ci      .put('/workspace-a', body => {
5991cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-a' })
6001cb0ef41Sopenharmony_ci      }).reply(200, {})
6011cb0ef41Sopenharmony_ci      .put('/workspace-b', body => {
6021cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-b' })
6031cb0ef41Sopenharmony_ci      }).reply(200, {})
6041cb0ef41Sopenharmony_ci      .put('/workspace-n', body => {
6051cb0ef41Sopenharmony_ci        return t.match(body, { name: 'workspace-n' })
6061cb0ef41Sopenharmony_ci      }).reply(200, {})
6071cb0ef41Sopenharmony_ci    await npm.exec('publish', [])
6081cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'all workspaces in json')
6091cb0ef41Sopenharmony_ci  })
6101cb0ef41Sopenharmony_ci  t.end()
6111cb0ef41Sopenharmony_ci})
6121cb0ef41Sopenharmony_ci
6131cb0ef41Sopenharmony_cit.test('ignore-scripts', async t => {
6141cb0ef41Sopenharmony_ci  const { npm, joinedOutput, prefix } = await loadMockNpm(t, {
6151cb0ef41Sopenharmony_ci    config: {
6161cb0ef41Sopenharmony_ci      ...auth,
6171cb0ef41Sopenharmony_ci      'ignore-scripts': true,
6181cb0ef41Sopenharmony_ci    },
6191cb0ef41Sopenharmony_ci    prefixDir: {
6201cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
6211cb0ef41Sopenharmony_ci        ...pkgJson,
6221cb0ef41Sopenharmony_ci        scripts: {
6231cb0ef41Sopenharmony_ci          prepublishOnly: 'touch scripts-prepublishonly',
6241cb0ef41Sopenharmony_ci          prepublish: 'touch scripts-prepublish', // should NOT run this one
6251cb0ef41Sopenharmony_ci          publish: 'touch scripts-publish',
6261cb0ef41Sopenharmony_ci          postpublish: 'touch scripts-postpublish',
6271cb0ef41Sopenharmony_ci        },
6281cb0ef41Sopenharmony_ci      }, null, 2),
6291cb0ef41Sopenharmony_ci    },
6301cb0ef41Sopenharmony_ci  })
6311cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
6321cb0ef41Sopenharmony_ci    tap: t,
6331cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
6341cb0ef41Sopenharmony_ci    authorization: token,
6351cb0ef41Sopenharmony_ci  })
6361cb0ef41Sopenharmony_ci  registry.nock.put(`/${pkg}`).reply(200, {})
6371cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
6381cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
6391cb0ef41Sopenharmony_ci  t.equal(
6401cb0ef41Sopenharmony_ci    fs.existsSync(path.join(prefix, 'scripts-prepublishonly')),
6411cb0ef41Sopenharmony_ci    false,
6421cb0ef41Sopenharmony_ci    'did not run prepublishOnly'
6431cb0ef41Sopenharmony_ci  )
6441cb0ef41Sopenharmony_ci  t.equal(
6451cb0ef41Sopenharmony_ci    fs.existsSync(path.join(prefix, 'scripts-prepublish')),
6461cb0ef41Sopenharmony_ci    false,
6471cb0ef41Sopenharmony_ci    'did not run prepublish'
6481cb0ef41Sopenharmony_ci  )
6491cb0ef41Sopenharmony_ci  t.equal(
6501cb0ef41Sopenharmony_ci    fs.existsSync(path.join(prefix, 'scripts-publish')),
6511cb0ef41Sopenharmony_ci    false,
6521cb0ef41Sopenharmony_ci    'did not run publish'
6531cb0ef41Sopenharmony_ci  )
6541cb0ef41Sopenharmony_ci  t.equal(
6551cb0ef41Sopenharmony_ci    fs.existsSync(path.join(prefix, 'scripts-postpublish')),
6561cb0ef41Sopenharmony_ci    false,
6571cb0ef41Sopenharmony_ci    'did not run postpublish'
6581cb0ef41Sopenharmony_ci  )
6591cb0ef41Sopenharmony_ci})
6601cb0ef41Sopenharmony_ci
6611cb0ef41Sopenharmony_cit.test('_auth config default registry', async t => {
6621cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await loadMockNpm(t, {
6631cb0ef41Sopenharmony_ci    config: {
6641cb0ef41Sopenharmony_ci      '//registry.npmjs.org/:_auth': basic,
6651cb0ef41Sopenharmony_ci    },
6661cb0ef41Sopenharmony_ci    prefixDir: {
6671cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(pkgJson),
6681cb0ef41Sopenharmony_ci    },
6691cb0ef41Sopenharmony_ci  })
6701cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
6711cb0ef41Sopenharmony_ci    tap: t,
6721cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
6731cb0ef41Sopenharmony_ci    basic,
6741cb0ef41Sopenharmony_ci  })
6751cb0ef41Sopenharmony_ci  registry.nock.put(`/${pkg}`).reply(200, {})
6761cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
6771cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
6781cb0ef41Sopenharmony_ci})
6791cb0ef41Sopenharmony_ci
6801cb0ef41Sopenharmony_cit.test('bare _auth and registry config', async t => {
6811cb0ef41Sopenharmony_ci  const spec = npa('@npm/test-package')
6821cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await loadMockNpm(t, {
6831cb0ef41Sopenharmony_ci    config: {
6841cb0ef41Sopenharmony_ci      registry: alternateRegistry,
6851cb0ef41Sopenharmony_ci      '//other.registry.npmjs.org/:_auth': basic,
6861cb0ef41Sopenharmony_ci    },
6871cb0ef41Sopenharmony_ci    prefixDir: {
6881cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
6891cb0ef41Sopenharmony_ci        name: '@npm/test-package',
6901cb0ef41Sopenharmony_ci        version: '1.0.0',
6911cb0ef41Sopenharmony_ci      }, null, 2),
6921cb0ef41Sopenharmony_ci    },
6931cb0ef41Sopenharmony_ci  })
6941cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
6951cb0ef41Sopenharmony_ci    tap: t,
6961cb0ef41Sopenharmony_ci    registry: alternateRegistry,
6971cb0ef41Sopenharmony_ci    basic,
6981cb0ef41Sopenharmony_ci  })
6991cb0ef41Sopenharmony_ci  registry.nock.put(`/${spec.escapedName}`).reply(200, {})
7001cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
7011cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
7021cb0ef41Sopenharmony_ci})
7031cb0ef41Sopenharmony_ci
7041cb0ef41Sopenharmony_cit.test('bare _auth config scoped registry', async t => {
7051cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t, {
7061cb0ef41Sopenharmony_ci    config: {
7071cb0ef41Sopenharmony_ci      scope: '@npm',
7081cb0ef41Sopenharmony_ci      registry: alternateRegistry,
7091cb0ef41Sopenharmony_ci      _auth: basic,
7101cb0ef41Sopenharmony_ci    },
7111cb0ef41Sopenharmony_ci    prefixDir: {
7121cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
7131cb0ef41Sopenharmony_ci        name: '@npm/test-package',
7141cb0ef41Sopenharmony_ci        version: '1.0.0',
7151cb0ef41Sopenharmony_ci      }, null, 2),
7161cb0ef41Sopenharmony_ci    },
7171cb0ef41Sopenharmony_ci  })
7181cb0ef41Sopenharmony_ci  await t.rejects(
7191cb0ef41Sopenharmony_ci    npm.exec('publish', []),
7201cb0ef41Sopenharmony_ci    { message: `This command requires you to be logged in to ${alternateRegistry}` }
7211cb0ef41Sopenharmony_ci  )
7221cb0ef41Sopenharmony_ci})
7231cb0ef41Sopenharmony_ci
7241cb0ef41Sopenharmony_cit.test('scoped _auth config scoped registry', async t => {
7251cb0ef41Sopenharmony_ci  const spec = npa('@npm/test-package')
7261cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await loadMockNpm(t, {
7271cb0ef41Sopenharmony_ci    config: {
7281cb0ef41Sopenharmony_ci      scope: '@npm',
7291cb0ef41Sopenharmony_ci      registry: alternateRegistry,
7301cb0ef41Sopenharmony_ci      [`${alternateRegistry.slice(6)}/:_auth`]: basic,
7311cb0ef41Sopenharmony_ci    },
7321cb0ef41Sopenharmony_ci    prefixDir: {
7331cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
7341cb0ef41Sopenharmony_ci        name: '@npm/test-package',
7351cb0ef41Sopenharmony_ci        version: '1.0.0',
7361cb0ef41Sopenharmony_ci      }, null, 2),
7371cb0ef41Sopenharmony_ci    },
7381cb0ef41Sopenharmony_ci  })
7391cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
7401cb0ef41Sopenharmony_ci    tap: t,
7411cb0ef41Sopenharmony_ci    registry: alternateRegistry,
7421cb0ef41Sopenharmony_ci    basic,
7431cb0ef41Sopenharmony_ci  })
7441cb0ef41Sopenharmony_ci  registry.nock.put(`/${spec.escapedName}`).reply(200, {})
7451cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
7461cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
7471cb0ef41Sopenharmony_ci})
7481cb0ef41Sopenharmony_ci
7491cb0ef41Sopenharmony_cit.test('restricted access', async t => {
7501cb0ef41Sopenharmony_ci  const spec = npa('@npm/test-package')
7511cb0ef41Sopenharmony_ci  const { npm, joinedOutput, logs } = await loadMockNpm(t, {
7521cb0ef41Sopenharmony_ci    config: {
7531cb0ef41Sopenharmony_ci      ...auth,
7541cb0ef41Sopenharmony_ci      access: 'restricted',
7551cb0ef41Sopenharmony_ci    },
7561cb0ef41Sopenharmony_ci    prefixDir: {
7571cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
7581cb0ef41Sopenharmony_ci        name: '@npm/test-package',
7591cb0ef41Sopenharmony_ci        version: '1.0.0',
7601cb0ef41Sopenharmony_ci      }, null, 2),
7611cb0ef41Sopenharmony_ci    },
7621cb0ef41Sopenharmony_ci  })
7631cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
7641cb0ef41Sopenharmony_ci    tap: t,
7651cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
7661cb0ef41Sopenharmony_ci    authorization: token,
7671cb0ef41Sopenharmony_ci  })
7681cb0ef41Sopenharmony_ci  registry.nock.put(`/${spec.escapedName}`, body => {
7691cb0ef41Sopenharmony_ci    t.equal(body.access, 'restricted', 'access is explicitly set to restricted')
7701cb0ef41Sopenharmony_ci    return true
7711cb0ef41Sopenharmony_ci  }).reply(200, {})
7721cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
7731cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
7741cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.notice)
7751cb0ef41Sopenharmony_ci})
7761cb0ef41Sopenharmony_ci
7771cb0ef41Sopenharmony_cit.test('public access', async t => {
7781cb0ef41Sopenharmony_ci  const spec = npa('@npm/test-package')
7791cb0ef41Sopenharmony_ci  const { npm, joinedOutput, logs } = await loadMockNpm(t, {
7801cb0ef41Sopenharmony_ci    config: {
7811cb0ef41Sopenharmony_ci      ...auth,
7821cb0ef41Sopenharmony_ci      access: 'public',
7831cb0ef41Sopenharmony_ci    },
7841cb0ef41Sopenharmony_ci    prefixDir: {
7851cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
7861cb0ef41Sopenharmony_ci        name: '@npm/test-package',
7871cb0ef41Sopenharmony_ci        version: '1.0.0',
7881cb0ef41Sopenharmony_ci      }, null, 2),
7891cb0ef41Sopenharmony_ci    },
7901cb0ef41Sopenharmony_ci  })
7911cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
7921cb0ef41Sopenharmony_ci    tap: t,
7931cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
7941cb0ef41Sopenharmony_ci    authorization: token,
7951cb0ef41Sopenharmony_ci  })
7961cb0ef41Sopenharmony_ci  registry.nock.put(`/${spec.escapedName}`, body => {
7971cb0ef41Sopenharmony_ci    t.equal(body.access, 'public', 'access is explicitly set to public')
7981cb0ef41Sopenharmony_ci    return true
7991cb0ef41Sopenharmony_ci  }).reply(200, {})
8001cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
8011cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'new package version')
8021cb0ef41Sopenharmony_ci  t.matchSnapshot(logs.notice)
8031cb0ef41Sopenharmony_ci})
8041cb0ef41Sopenharmony_ci
8051cb0ef41Sopenharmony_cit.test('manifest', async t => {
8061cb0ef41Sopenharmony_ci  // https://github.com/npm/cli/pull/6470#issuecomment-1571234863
8071cb0ef41Sopenharmony_ci
8081cb0ef41Sopenharmony_ci  // snapshot test that was generated against v9.6.7 originally to ensure our
8091cb0ef41Sopenharmony_ci  // own manifest does not change unexpectedly when publishing. this test
8101cb0ef41Sopenharmony_ci  // asserts a bunch of keys are there that will change often and then snapshots
8111cb0ef41Sopenharmony_ci  // the rest of the manifest.
8121cb0ef41Sopenharmony_ci
8131cb0ef41Sopenharmony_ci  const root = path.resolve(__dirname, '../../..')
8141cb0ef41Sopenharmony_ci  const npmPkg = require(path.join(root, 'package.json'))
8151cb0ef41Sopenharmony_ci
8161cb0ef41Sopenharmony_ci  t.cleanSnapshot = (s) => s.replace(new RegExp(npmPkg.version, 'g'), '{VERSION}')
8171cb0ef41Sopenharmony_ci
8181cb0ef41Sopenharmony_ci  let manifest = null
8191cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t, {
8201cb0ef41Sopenharmony_ci    config: {
8211cb0ef41Sopenharmony_ci      ...auth,
8221cb0ef41Sopenharmony_ci    },
8231cb0ef41Sopenharmony_ci    chdir: () => root,
8241cb0ef41Sopenharmony_ci    mocks: {
8251cb0ef41Sopenharmony_ci      libnpmpublish: {
8261cb0ef41Sopenharmony_ci        publish: (m) => manifest = m,
8271cb0ef41Sopenharmony_ci      },
8281cb0ef41Sopenharmony_ci    },
8291cb0ef41Sopenharmony_ci  })
8301cb0ef41Sopenharmony_ci  await npm.exec('publish', [])
8311cb0ef41Sopenharmony_ci
8321cb0ef41Sopenharmony_ci  const okKeys = [
8331cb0ef41Sopenharmony_ci    'contributors',
8341cb0ef41Sopenharmony_ci    'bundleDependencies',
8351cb0ef41Sopenharmony_ci    'dependencies',
8361cb0ef41Sopenharmony_ci    'devDependencies',
8371cb0ef41Sopenharmony_ci    'templateOSS',
8381cb0ef41Sopenharmony_ci    'scripts',
8391cb0ef41Sopenharmony_ci    'tap',
8401cb0ef41Sopenharmony_ci    'readme',
8411cb0ef41Sopenharmony_ci    'engines',
8421cb0ef41Sopenharmony_ci    'workspaces',
8431cb0ef41Sopenharmony_ci  ]
8441cb0ef41Sopenharmony_ci
8451cb0ef41Sopenharmony_ci  for (const k of okKeys) {
8461cb0ef41Sopenharmony_ci    t.ok(manifest[k], k)
8471cb0ef41Sopenharmony_ci    delete manifest[k]
8481cb0ef41Sopenharmony_ci  }
8491cb0ef41Sopenharmony_ci  delete manifest.gitHead
8501cb0ef41Sopenharmony_ci
8511cb0ef41Sopenharmony_ci  manifest.man.sort()
8521cb0ef41Sopenharmony_ci
8531cb0ef41Sopenharmony_ci  t.matchSnapshot(manifest, 'manifest')
8541cb0ef41Sopenharmony_ci})
855