11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ciconst fs = require('fs')
31cb0ef41Sopenharmony_ciconst path = require('path')
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst { load: loadMockNpm } = require('../../fixtures/mock-npm')
61cb0ef41Sopenharmony_ciconst tnock = require('../../fixtures/tnock.js')
71cb0ef41Sopenharmony_ciconst mockGlobals = require('@npmcli/mock-globals')
81cb0ef41Sopenharmony_ciconst { cleanCwd, cleanDate } = require('../../fixtures/clean-snapshot.js')
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst cleanCacheSha = (str) =>
111cb0ef41Sopenharmony_ci  str.replace(/content-v2\/sha512\/[^"]+/g, 'content-v2/sha512/{sha}')
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cit.cleanSnapshot = p => cleanCacheSha(cleanDate(cleanCwd(p)))
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst npmManifest = (version) => {
161cb0ef41Sopenharmony_ci  return {
171cb0ef41Sopenharmony_ci    name: 'npm',
181cb0ef41Sopenharmony_ci    versions: {
191cb0ef41Sopenharmony_ci      [version]: {
201cb0ef41Sopenharmony_ci        name: 'npm',
211cb0ef41Sopenharmony_ci        version: version,
221cb0ef41Sopenharmony_ci      },
231cb0ef41Sopenharmony_ci    },
241cb0ef41Sopenharmony_ci    time: {
251cb0ef41Sopenharmony_ci      [version]: new Date(),
261cb0ef41Sopenharmony_ci    },
271cb0ef41Sopenharmony_ci    'dist-tags': { latest: version },
281cb0ef41Sopenharmony_ci  }
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciconst nodeVersions = [
321cb0ef41Sopenharmony_ci  { version: 'v2.0.1', lts: false },
331cb0ef41Sopenharmony_ci  { version: 'v2.0.0', lts: false },
341cb0ef41Sopenharmony_ci  { version: 'v1.0.0', lts: 'NpmTestium' },
351cb0ef41Sopenharmony_ci]
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ciconst dirs = {
381cb0ef41Sopenharmony_ci  prefixDir: {
391cb0ef41Sopenharmony_ci    node_modules: {
401cb0ef41Sopenharmony_ci      testLink: t.fixture('symlink', './testDir'),
411cb0ef41Sopenharmony_ci      testDir: {
421cb0ef41Sopenharmony_ci        testFile: 'test contents',
431cb0ef41Sopenharmony_ci      },
441cb0ef41Sopenharmony_ci      '.bin': {},
451cb0ef41Sopenharmony_ci    },
461cb0ef41Sopenharmony_ci  },
471cb0ef41Sopenharmony_ci  globalPrefixDir: {
481cb0ef41Sopenharmony_ci    bin: {},
491cb0ef41Sopenharmony_ci    node_modules: {},
501cb0ef41Sopenharmony_ci  },
511cb0ef41Sopenharmony_ci}
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciconst globals = ({ globalPrefix }) => {
541cb0ef41Sopenharmony_ci  return {
551cb0ef41Sopenharmony_ci    process: {
561cb0ef41Sopenharmony_ci      'env.PATH': `${globalPrefix}:${path.join(globalPrefix, 'bin')}`,
571cb0ef41Sopenharmony_ci      version: 'v1.0.0',
581cb0ef41Sopenharmony_ci    },
591cb0ef41Sopenharmony_ci  }
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_cimockGlobals(t, {
631cb0ef41Sopenharmony_ci  process: {
641cb0ef41Sopenharmony_ci    // set platform to not-windows before any tests because mockNpm
651cb0ef41Sopenharmony_ci    // sets the platform specific location of node_modules based on it
661cb0ef41Sopenharmony_ci    platform: 'test-not-windows',
671cb0ef41Sopenharmony_ci    // getuid and getgid do not exist in windows, so we shim them
681cb0ef41Sopenharmony_ci    // to return 0, as that is the value that lstat will assign the
691cb0ef41Sopenharmony_ci    // gid and uid properties for fs.Stats objects
701cb0ef41Sopenharmony_ci    ...(process.platform === 'win32' ? { getuid: () => 0, getgid: () => 0 } : {}),
711cb0ef41Sopenharmony_ci  },
721cb0ef41Sopenharmony_ci})
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ciconst mocks = {
751cb0ef41Sopenharmony_ci  '{ROOT}/package.json': { version: '1.0.0' },
761cb0ef41Sopenharmony_ci  which: async () => '/path/to/git',
771cb0ef41Sopenharmony_ci  cacache: {
781cb0ef41Sopenharmony_ci    verify: () => {
791cb0ef41Sopenharmony_ci      return { badContentCount: 0, reclaimedCount: 0, missingContent: 0, verifiedContent: 0 }
801cb0ef41Sopenharmony_ci    },
811cb0ef41Sopenharmony_ci  },
821cb0ef41Sopenharmony_ci}
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_cit.test('all clear', async t => {
851cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
861cb0ef41Sopenharmony_ci    mocks,
871cb0ef41Sopenharmony_ci    globals,
881cb0ef41Sopenharmony_ci    ...dirs,
891cb0ef41Sopenharmony_ci  })
901cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
911cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
921cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
931cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
941cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
951cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
961cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'output')
971cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
981cb0ef41Sopenharmony_ci})
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_cit.test('all clear in color', async t => {
1011cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
1021cb0ef41Sopenharmony_ci    mocks,
1031cb0ef41Sopenharmony_ci    globals,
1041cb0ef41Sopenharmony_ci    ...dirs,
1051cb0ef41Sopenharmony_ci    config: {
1061cb0ef41Sopenharmony_ci      color: 'always',
1071cb0ef41Sopenharmony_ci    },
1081cb0ef41Sopenharmony_ci  })
1091cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
1101cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
1111cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
1121cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
1131cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
1141cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
1151cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'everything is ok in color')
1161cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
1171cb0ef41Sopenharmony_ci})
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_cit.test('silent success', async t => {
1201cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
1211cb0ef41Sopenharmony_ci    mocks,
1221cb0ef41Sopenharmony_ci    globals,
1231cb0ef41Sopenharmony_ci    config: {
1241cb0ef41Sopenharmony_ci      loglevel: 'silent',
1251cb0ef41Sopenharmony_ci    },
1261cb0ef41Sopenharmony_ci    ...dirs,
1271cb0ef41Sopenharmony_ci  })
1281cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
1291cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
1301cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
1311cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
1321cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
1331cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
1341cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'output')
1351cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
1361cb0ef41Sopenharmony_ci})
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_cit.test('silent errors', async t => {
1391cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
1401cb0ef41Sopenharmony_ci    mocks,
1411cb0ef41Sopenharmony_ci    globals,
1421cb0ef41Sopenharmony_ci    config: {
1431cb0ef41Sopenharmony_ci      loglevel: 'silent',
1441cb0ef41Sopenharmony_ci    },
1451cb0ef41Sopenharmony_ci    ...dirs,
1461cb0ef41Sopenharmony_ci  })
1471cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
1481cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(404, '{}')
1491cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', ['ping']), {
1501cb0ef41Sopenharmony_ci    message: /Check logs/,
1511cb0ef41Sopenharmony_ci  })
1521cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'output')
1531cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
1541cb0ef41Sopenharmony_ci})
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_cit.test('ping 404', async t => {
1571cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
1581cb0ef41Sopenharmony_ci    mocks,
1591cb0ef41Sopenharmony_ci    globals,
1601cb0ef41Sopenharmony_ci    ...dirs,
1611cb0ef41Sopenharmony_ci  })
1621cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
1631cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(404, '{}')
1641cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
1651cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
1661cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
1671cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []), {
1681cb0ef41Sopenharmony_ci    message: /See above/,
1691cb0ef41Sopenharmony_ci  })
1701cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'ping 404')
1711cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
1721cb0ef41Sopenharmony_ci})
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_cit.test('ping 404 in color', async t => {
1751cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
1761cb0ef41Sopenharmony_ci    mocks,
1771cb0ef41Sopenharmony_ci    globals,
1781cb0ef41Sopenharmony_ci    ...dirs,
1791cb0ef41Sopenharmony_ci    config: {
1801cb0ef41Sopenharmony_ci      color: 'always',
1811cb0ef41Sopenharmony_ci    },
1821cb0ef41Sopenharmony_ci  })
1831cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
1841cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(404, '{}')
1851cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
1861cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
1871cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
1881cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
1891cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'ping 404 in color')
1901cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
1911cb0ef41Sopenharmony_ci})
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_cit.test('ping exception with code', async t => {
1941cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
1951cb0ef41Sopenharmony_ci    mocks,
1961cb0ef41Sopenharmony_ci    globals,
1971cb0ef41Sopenharmony_ci    ...dirs,
1981cb0ef41Sopenharmony_ci  })
1991cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
2001cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').replyWithError({ message: 'Test Error', code: 'TEST' })
2011cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
2021cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
2031cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
2041cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
2051cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'ping failure')
2061cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
2071cb0ef41Sopenharmony_ci})
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_cit.test('ping exception without code', async t => {
2101cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
2111cb0ef41Sopenharmony_ci    mocks,
2121cb0ef41Sopenharmony_ci    globals,
2131cb0ef41Sopenharmony_ci    ...dirs,
2141cb0ef41Sopenharmony_ci  })
2151cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
2161cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').replyWithError({ message: 'Test Error', code: false })
2171cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
2181cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
2191cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
2201cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
2211cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'ping failure')
2221cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
2231cb0ef41Sopenharmony_ci})
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_cit.test('npm out of date', async t => {
2261cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
2271cb0ef41Sopenharmony_ci    mocks,
2281cb0ef41Sopenharmony_ci    globals,
2291cb0ef41Sopenharmony_ci    ...dirs,
2301cb0ef41Sopenharmony_ci  })
2311cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
2321cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
2331cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest('2.0.0'))
2341cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
2351cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
2361cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
2371cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'npm is out of date')
2381cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
2391cb0ef41Sopenharmony_ci})
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_cit.test('node out of date - lts', async t => {
2421cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
2431cb0ef41Sopenharmony_ci    mocks,
2441cb0ef41Sopenharmony_ci    globals: (context) => {
2451cb0ef41Sopenharmony_ci      const g = globals(context)
2461cb0ef41Sopenharmony_ci      return {
2471cb0ef41Sopenharmony_ci        ...g,
2481cb0ef41Sopenharmony_ci        process: {
2491cb0ef41Sopenharmony_ci          ...g.process,
2501cb0ef41Sopenharmony_ci          version: 'v0.0.1',
2511cb0ef41Sopenharmony_ci        },
2521cb0ef41Sopenharmony_ci      }
2531cb0ef41Sopenharmony_ci    },
2541cb0ef41Sopenharmony_ci    ...dirs,
2551cb0ef41Sopenharmony_ci  })
2561cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
2571cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
2581cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
2591cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
2601cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
2611cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
2621cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'node is out of date')
2631cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
2641cb0ef41Sopenharmony_ci})
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_cit.test('node out of date - current', async t => {
2671cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
2681cb0ef41Sopenharmony_ci    mocks,
2691cb0ef41Sopenharmony_ci    globals: (context) => {
2701cb0ef41Sopenharmony_ci      const g = globals(context)
2711cb0ef41Sopenharmony_ci      return {
2721cb0ef41Sopenharmony_ci        ...g,
2731cb0ef41Sopenharmony_ci        process: {
2741cb0ef41Sopenharmony_ci          ...g.process,
2751cb0ef41Sopenharmony_ci          version: 'v2.0.0',
2761cb0ef41Sopenharmony_ci        },
2771cb0ef41Sopenharmony_ci      }
2781cb0ef41Sopenharmony_ci    },
2791cb0ef41Sopenharmony_ci    ...dirs,
2801cb0ef41Sopenharmony_ci  })
2811cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
2821cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
2831cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
2841cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
2851cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
2861cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
2871cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'node is out of date')
2881cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
2891cb0ef41Sopenharmony_ci})
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_cit.test('non-default registry', async t => {
2921cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
2931cb0ef41Sopenharmony_ci    mocks,
2941cb0ef41Sopenharmony_ci    globals,
2951cb0ef41Sopenharmony_ci    config: { registry: 'http://some-other-url.npmjs.org' },
2961cb0ef41Sopenharmony_ci    ...dirs,
2971cb0ef41Sopenharmony_ci  })
2981cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
2991cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
3001cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
3011cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
3021cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
3031cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
3041cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'non default registry')
3051cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
3061cb0ef41Sopenharmony_ci})
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_cit.test('missing git', async t => {
3091cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
3101cb0ef41Sopenharmony_ci    mocks: {
3111cb0ef41Sopenharmony_ci      ...mocks,
3121cb0ef41Sopenharmony_ci      which: async () => {
3131cb0ef41Sopenharmony_ci        throw new Error('test error')
3141cb0ef41Sopenharmony_ci      },
3151cb0ef41Sopenharmony_ci    },
3161cb0ef41Sopenharmony_ci    globals,
3171cb0ef41Sopenharmony_ci    ...dirs,
3181cb0ef41Sopenharmony_ci  })
3191cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
3201cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
3211cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
3221cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
3231cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
3241cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
3251cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'missing git')
3261cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
3271cb0ef41Sopenharmony_ci})
3281cb0ef41Sopenharmony_ci
3291cb0ef41Sopenharmony_cit.test('windows skips permissions checks', async t => {
3301cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
3311cb0ef41Sopenharmony_ci    mocks,
3321cb0ef41Sopenharmony_ci    globals: (context) => {
3331cb0ef41Sopenharmony_ci      const g = globals(context)
3341cb0ef41Sopenharmony_ci      return {
3351cb0ef41Sopenharmony_ci        ...g,
3361cb0ef41Sopenharmony_ci        process: {
3371cb0ef41Sopenharmony_ci          ...g.process,
3381cb0ef41Sopenharmony_ci          platform: 'win32',
3391cb0ef41Sopenharmony_ci        },
3401cb0ef41Sopenharmony_ci      }
3411cb0ef41Sopenharmony_ci    },
3421cb0ef41Sopenharmony_ci    prefixDir: {},
3431cb0ef41Sopenharmony_ci    globalPrefixDir: {},
3441cb0ef41Sopenharmony_ci  })
3451cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
3461cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
3471cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
3481cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
3491cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
3501cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
3511cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'no permissions checks')
3521cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
3531cb0ef41Sopenharmony_ci})
3541cb0ef41Sopenharmony_ci
3551cb0ef41Sopenharmony_cit.test('missing global directories', async t => {
3561cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
3571cb0ef41Sopenharmony_ci    mocks,
3581cb0ef41Sopenharmony_ci    globals,
3591cb0ef41Sopenharmony_ci    prefixDir: dirs.prefixDir,
3601cb0ef41Sopenharmony_ci    globalPrefixDir: {},
3611cb0ef41Sopenharmony_ci  })
3621cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
3631cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
3641cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
3651cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
3661cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
3671cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
3681cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'missing global directories')
3691cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
3701cb0ef41Sopenharmony_ci})
3711cb0ef41Sopenharmony_ci
3721cb0ef41Sopenharmony_cit.test('missing local node_modules', async t => {
3731cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
3741cb0ef41Sopenharmony_ci    mocks,
3751cb0ef41Sopenharmony_ci    globals,
3761cb0ef41Sopenharmony_ci    globalPrefixDir: dirs.globalPrefixDir,
3771cb0ef41Sopenharmony_ci  })
3781cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
3791cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
3801cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
3811cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
3821cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
3831cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
3841cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'missing local node_modules')
3851cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
3861cb0ef41Sopenharmony_ci})
3871cb0ef41Sopenharmony_ci
3881cb0ef41Sopenharmony_cit.test('incorrect owner', async t => {
3891cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
3901cb0ef41Sopenharmony_ci    mocks: {
3911cb0ef41Sopenharmony_ci      ...mocks,
3921cb0ef41Sopenharmony_ci      fs: {
3931cb0ef41Sopenharmony_ci        ...fs,
3941cb0ef41Sopenharmony_ci        lstat: (p, cb) => {
3951cb0ef41Sopenharmony_ci          const stat = fs.lstatSync(p)
3961cb0ef41Sopenharmony_ci          if (p.endsWith('_cacache')) {
3971cb0ef41Sopenharmony_ci            stat.uid += 1
3981cb0ef41Sopenharmony_ci            stat.gid += 1
3991cb0ef41Sopenharmony_ci          }
4001cb0ef41Sopenharmony_ci          return cb(null, stat)
4011cb0ef41Sopenharmony_ci        },
4021cb0ef41Sopenharmony_ci      },
4031cb0ef41Sopenharmony_ci    },
4041cb0ef41Sopenharmony_ci    globals,
4051cb0ef41Sopenharmony_ci    ...dirs,
4061cb0ef41Sopenharmony_ci  })
4071cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
4081cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
4091cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
4101cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
4111cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
4121cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
4131cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'incorrect owner')
4141cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
4151cb0ef41Sopenharmony_ci})
4161cb0ef41Sopenharmony_ci
4171cb0ef41Sopenharmony_cit.test('incorrect permissions', async t => {
4181cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
4191cb0ef41Sopenharmony_ci    mocks: {
4201cb0ef41Sopenharmony_ci      ...mocks,
4211cb0ef41Sopenharmony_ci      fs: {
4221cb0ef41Sopenharmony_ci        ...fs,
4231cb0ef41Sopenharmony_ci        access: () => {
4241cb0ef41Sopenharmony_ci          throw new Error('Test Error')
4251cb0ef41Sopenharmony_ci        },
4261cb0ef41Sopenharmony_ci      },
4271cb0ef41Sopenharmony_ci    },
4281cb0ef41Sopenharmony_ci    globals,
4291cb0ef41Sopenharmony_ci    ...dirs,
4301cb0ef41Sopenharmony_ci  })
4311cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
4321cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
4331cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
4341cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
4351cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
4361cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
4371cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'incorrect owner')
4381cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
4391cb0ef41Sopenharmony_ci})
4401cb0ef41Sopenharmony_ci
4411cb0ef41Sopenharmony_cit.test('error reading directory', async t => {
4421cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
4431cb0ef41Sopenharmony_ci    mocks: {
4441cb0ef41Sopenharmony_ci      ...mocks,
4451cb0ef41Sopenharmony_ci      fs: {
4461cb0ef41Sopenharmony_ci        ...fs,
4471cb0ef41Sopenharmony_ci        readdir: () => {
4481cb0ef41Sopenharmony_ci          throw new Error('Test Error')
4491cb0ef41Sopenharmony_ci        },
4501cb0ef41Sopenharmony_ci      },
4511cb0ef41Sopenharmony_ci    },
4521cb0ef41Sopenharmony_ci    globals,
4531cb0ef41Sopenharmony_ci    ...dirs,
4541cb0ef41Sopenharmony_ci  })
4551cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
4561cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
4571cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
4581cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
4591cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
4601cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
4611cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'readdir error')
4621cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
4631cb0ef41Sopenharmony_ci})
4641cb0ef41Sopenharmony_ci
4651cb0ef41Sopenharmony_cit.test('cacache badContent', async t => {
4661cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
4671cb0ef41Sopenharmony_ci    mocks: {
4681cb0ef41Sopenharmony_ci      ...mocks,
4691cb0ef41Sopenharmony_ci      cacache: {
4701cb0ef41Sopenharmony_ci        verify: async () => {
4711cb0ef41Sopenharmony_ci          return { badContentCount: 1, reclaimedCount: 0, missingContent: 0, verifiedContent: 2 }
4721cb0ef41Sopenharmony_ci        },
4731cb0ef41Sopenharmony_ci      },
4741cb0ef41Sopenharmony_ci    },
4751cb0ef41Sopenharmony_ci    globals,
4761cb0ef41Sopenharmony_ci    ...dirs,
4771cb0ef41Sopenharmony_ci  })
4781cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
4791cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
4801cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
4811cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
4821cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
4831cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
4841cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'corrupted cache content')
4851cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
4861cb0ef41Sopenharmony_ci})
4871cb0ef41Sopenharmony_ci
4881cb0ef41Sopenharmony_cit.test('cacache reclaimedCount', async t => {
4891cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
4901cb0ef41Sopenharmony_ci    mocks: {
4911cb0ef41Sopenharmony_ci      ...mocks,
4921cb0ef41Sopenharmony_ci      cacache: {
4931cb0ef41Sopenharmony_ci        verify: async () => {
4941cb0ef41Sopenharmony_ci          return { badContentCount: 0, reclaimedCount: 1, missingContent: 0, verifiedContent: 2 }
4951cb0ef41Sopenharmony_ci        },
4961cb0ef41Sopenharmony_ci      },
4971cb0ef41Sopenharmony_ci    },
4981cb0ef41Sopenharmony_ci    globals,
4991cb0ef41Sopenharmony_ci    ...dirs,
5001cb0ef41Sopenharmony_ci  })
5011cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
5021cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
5031cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
5041cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
5051cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
5061cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
5071cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'content garbage collected')
5081cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
5091cb0ef41Sopenharmony_ci})
5101cb0ef41Sopenharmony_ci
5111cb0ef41Sopenharmony_cit.test('cacache missingContent', async t => {
5121cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
5131cb0ef41Sopenharmony_ci    mocks: {
5141cb0ef41Sopenharmony_ci      ...mocks,
5151cb0ef41Sopenharmony_ci      cacache: {
5161cb0ef41Sopenharmony_ci        verify: async () => {
5171cb0ef41Sopenharmony_ci          return { badContentCount: 0, reclaimedCount: 0, missingContent: 1, verifiedContent: 2 }
5181cb0ef41Sopenharmony_ci        },
5191cb0ef41Sopenharmony_ci      },
5201cb0ef41Sopenharmony_ci    },
5211cb0ef41Sopenharmony_ci    globals,
5221cb0ef41Sopenharmony_ci    ...dirs,
5231cb0ef41Sopenharmony_ci  })
5241cb0ef41Sopenharmony_ci  tnock(t, npm.config.get('registry'))
5251cb0ef41Sopenharmony_ci    .get('/-/ping?write=true').reply(200, '{}')
5261cb0ef41Sopenharmony_ci    .get('/npm').reply(200, npmManifest(npm.version))
5271cb0ef41Sopenharmony_ci  tnock(t, 'https://nodejs.org')
5281cb0ef41Sopenharmony_ci    .get('/dist/index.json').reply(200, nodeVersions)
5291cb0ef41Sopenharmony_ci  await npm.exec('doctor', [])
5301cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'missing content')
5311cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
5321cb0ef41Sopenharmony_ci})
5331cb0ef41Sopenharmony_ci
5341cb0ef41Sopenharmony_cit.test('bad proxy', async t => {
5351cb0ef41Sopenharmony_ci  const { joinedOutput, logs, npm } = await loadMockNpm(t, {
5361cb0ef41Sopenharmony_ci    mocks,
5371cb0ef41Sopenharmony_ci    globals,
5381cb0ef41Sopenharmony_ci    config: {
5391cb0ef41Sopenharmony_ci      proxy: 'ssh://npmjs.org',
5401cb0ef41Sopenharmony_ci    },
5411cb0ef41Sopenharmony_ci    ...dirs,
5421cb0ef41Sopenharmony_ci  })
5431cb0ef41Sopenharmony_ci  await t.rejects(npm.exec('doctor', []))
5441cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'output')
5451cb0ef41Sopenharmony_ci  t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
5461cb0ef41Sopenharmony_ci})
5471cb0ef41Sopenharmony_ci
5481cb0ef41Sopenharmony_cit.test('discrete checks', t => {
5491cb0ef41Sopenharmony_ci  t.test('ping', async t => {
5501cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
5511cb0ef41Sopenharmony_ci      mocks,
5521cb0ef41Sopenharmony_ci      globals,
5531cb0ef41Sopenharmony_ci      ...dirs,
5541cb0ef41Sopenharmony_ci    })
5551cb0ef41Sopenharmony_ci    tnock(t, npm.config.get('registry'))
5561cb0ef41Sopenharmony_ci      .get('/-/ping?write=true').reply(200, '{}')
5571cb0ef41Sopenharmony_ci    await npm.exec('doctor', ['ping'])
5581cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
5591cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
5601cb0ef41Sopenharmony_ci  })
5611cb0ef41Sopenharmony_ci
5621cb0ef41Sopenharmony_ci  t.test('versions', async t => {
5631cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
5641cb0ef41Sopenharmony_ci      mocks,
5651cb0ef41Sopenharmony_ci      globals,
5661cb0ef41Sopenharmony_ci      ...dirs,
5671cb0ef41Sopenharmony_ci    })
5681cb0ef41Sopenharmony_ci    tnock(t, npm.config.get('registry'))
5691cb0ef41Sopenharmony_ci      .get('/npm').reply(200, npmManifest(npm.version))
5701cb0ef41Sopenharmony_ci    tnock(t, 'https://nodejs.org')
5711cb0ef41Sopenharmony_ci      .get('/dist/index.json').reply(200, nodeVersions)
5721cb0ef41Sopenharmony_ci    await npm.exec('doctor', ['versions'])
5731cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
5741cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
5751cb0ef41Sopenharmony_ci  })
5761cb0ef41Sopenharmony_ci
5771cb0ef41Sopenharmony_ci  t.test('registry', async t => {
5781cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
5791cb0ef41Sopenharmony_ci      mocks,
5801cb0ef41Sopenharmony_ci      globals,
5811cb0ef41Sopenharmony_ci      ...dirs,
5821cb0ef41Sopenharmony_ci    })
5831cb0ef41Sopenharmony_ci    tnock(t, npm.config.get('registry'))
5841cb0ef41Sopenharmony_ci      .get('/-/ping?write=true').reply(200, '{}')
5851cb0ef41Sopenharmony_ci    await npm.exec('doctor', ['registry'])
5861cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
5871cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
5881cb0ef41Sopenharmony_ci  })
5891cb0ef41Sopenharmony_ci
5901cb0ef41Sopenharmony_ci  t.test('git', async t => {
5911cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
5921cb0ef41Sopenharmony_ci      mocks,
5931cb0ef41Sopenharmony_ci      globals,
5941cb0ef41Sopenharmony_ci      ...dirs,
5951cb0ef41Sopenharmony_ci    })
5961cb0ef41Sopenharmony_ci    await npm.exec('doctor', ['git'])
5971cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
5981cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
5991cb0ef41Sopenharmony_ci  })
6001cb0ef41Sopenharmony_ci
6011cb0ef41Sopenharmony_ci  t.test('permissions - not windows', async t => {
6021cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
6031cb0ef41Sopenharmony_ci      mocks,
6041cb0ef41Sopenharmony_ci      globals,
6051cb0ef41Sopenharmony_ci      ...dirs,
6061cb0ef41Sopenharmony_ci    })
6071cb0ef41Sopenharmony_ci    await npm.exec('doctor', ['permissions'])
6081cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
6091cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
6101cb0ef41Sopenharmony_ci  })
6111cb0ef41Sopenharmony_ci
6121cb0ef41Sopenharmony_ci  t.test('cache', async t => {
6131cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
6141cb0ef41Sopenharmony_ci      mocks,
6151cb0ef41Sopenharmony_ci      globals,
6161cb0ef41Sopenharmony_ci      ...dirs,
6171cb0ef41Sopenharmony_ci    })
6181cb0ef41Sopenharmony_ci    await npm.exec('doctor', ['cache'])
6191cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
6201cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
6211cb0ef41Sopenharmony_ci  })
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_ci  t.test('permissions - windows', async t => {
6241cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
6251cb0ef41Sopenharmony_ci      mocks,
6261cb0ef41Sopenharmony_ci      globals: (context) => {
6271cb0ef41Sopenharmony_ci        const g = globals(context)
6281cb0ef41Sopenharmony_ci        return {
6291cb0ef41Sopenharmony_ci          ...g,
6301cb0ef41Sopenharmony_ci          process: {
6311cb0ef41Sopenharmony_ci            ...g.process,
6321cb0ef41Sopenharmony_ci            platform: 'win32',
6331cb0ef41Sopenharmony_ci          },
6341cb0ef41Sopenharmony_ci        }
6351cb0ef41Sopenharmony_ci      },
6361cb0ef41Sopenharmony_ci      prefixDir: {},
6371cb0ef41Sopenharmony_ci      globalPrefixDir: {},
6381cb0ef41Sopenharmony_ci    })
6391cb0ef41Sopenharmony_ci    await npm.exec('doctor', ['permissions'])
6401cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
6411cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
6421cb0ef41Sopenharmony_ci  })
6431cb0ef41Sopenharmony_ci
6441cb0ef41Sopenharmony_ci  t.test('invalid environment', async t => {
6451cb0ef41Sopenharmony_ci    const { joinedOutput, logs, npm } = await loadMockNpm(t, {
6461cb0ef41Sopenharmony_ci      mocks,
6471cb0ef41Sopenharmony_ci      globals: (context) => {
6481cb0ef41Sopenharmony_ci        const g = globals(context)
6491cb0ef41Sopenharmony_ci        return {
6501cb0ef41Sopenharmony_ci          ...g,
6511cb0ef41Sopenharmony_ci          process: {
6521cb0ef41Sopenharmony_ci            ...g.process,
6531cb0ef41Sopenharmony_ci            'env.PATH': '/nope',
6541cb0ef41Sopenharmony_ci          },
6551cb0ef41Sopenharmony_ci        }
6561cb0ef41Sopenharmony_ci      },
6571cb0ef41Sopenharmony_ci      prefixDir: {},
6581cb0ef41Sopenharmony_ci      globalPrefixDir: {},
6591cb0ef41Sopenharmony_ci    })
6601cb0ef41Sopenharmony_ci    await t.rejects(npm.exec('doctor', ['environment']))
6611cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'output')
6621cb0ef41Sopenharmony_ci    t.matchSnapshot({ info: logs.info, warn: logs.warn, error: logs.error }, 'logs')
6631cb0ef41Sopenharmony_ci  })
6641cb0ef41Sopenharmony_ci
6651cb0ef41Sopenharmony_ci  t.end()
6661cb0ef41Sopenharmony_ci})
667