11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ciconst fs = require('fs/promises')
31cb0ef41Sopenharmony_ciconst { resolve, basename } = require('path')
41cb0ef41Sopenharmony_ciconst _mockNpm = require('../../fixtures/mock-npm')
51cb0ef41Sopenharmony_ciconst { cleanTime } = require('../../fixtures/clean-snapshot')
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cit.cleanSnapshot = cleanTime
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst mockNpm = async (t, { noLog, libnpmexec, initPackageJson, ...opts } = {}) => {
101cb0ef41Sopenharmony_ci  const res = await _mockNpm(t, {
111cb0ef41Sopenharmony_ci    ...opts,
121cb0ef41Sopenharmony_ci    mocks: {
131cb0ef41Sopenharmony_ci      ...(libnpmexec ? { libnpmexec } : {}),
141cb0ef41Sopenharmony_ci      ...(initPackageJson ? { 'init-package-json': initPackageJson } : {}),
151cb0ef41Sopenharmony_ci    },
161cb0ef41Sopenharmony_ci    globals: {
171cb0ef41Sopenharmony_ci      // init-package-json prints directly to console.log
181cb0ef41Sopenharmony_ci      // this avoids poluting test output with those logs
191cb0ef41Sopenharmony_ci      ...(noLog ? { 'console.log': () => {} } : {}),
201cb0ef41Sopenharmony_ci    },
211cb0ef41Sopenharmony_ci  })
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  return res
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cit.test('displays output', async t => {
271cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await mockNpm(t, {
281cb0ef41Sopenharmony_ci    initPackageJson: async () => {},
291cb0ef41Sopenharmony_ci  })
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  await npm.exec('init', [])
321cb0ef41Sopenharmony_ci  t.matchSnapshot(joinedOutput(), 'displays helper info')
331cb0ef41Sopenharmony_ci})
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_cit.test('classic npm init -y', async t => {
361cb0ef41Sopenharmony_ci  const { npm, prefix } = await mockNpm(t, {
371cb0ef41Sopenharmony_ci    config: { yes: true },
381cb0ef41Sopenharmony_ci    noLog: true,
391cb0ef41Sopenharmony_ci  })
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  await npm.exec('init', [])
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  const pkg = require(resolve(prefix, 'package.json'))
441cb0ef41Sopenharmony_ci  t.equal(pkg.version, '1.0.0')
451cb0ef41Sopenharmony_ci  t.equal(pkg.license, 'ISC')
461cb0ef41Sopenharmony_ci})
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_cit.test('classic interactive npm init', async t => {
491cb0ef41Sopenharmony_ci  t.plan(1)
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
521cb0ef41Sopenharmony_ci    initPackageJson: async (path) => {
531cb0ef41Sopenharmony_ci      t.equal(
541cb0ef41Sopenharmony_ci        path,
551cb0ef41Sopenharmony_ci        resolve(npm.localPrefix),
561cb0ef41Sopenharmony_ci        'should start init package.json in expected path'
571cb0ef41Sopenharmony_ci      )
581cb0ef41Sopenharmony_ci    },
591cb0ef41Sopenharmony_ci  })
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci  await npm.exec('init', [])
621cb0ef41Sopenharmony_ci})
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_cit.test('npm init <arg>', async t => {
651cb0ef41Sopenharmony_ci  t.plan(1)
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
681cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
691cb0ef41Sopenharmony_ci      t.same(
701cb0ef41Sopenharmony_ci        args,
711cb0ef41Sopenharmony_ci        ['create-react-app@*'],
721cb0ef41Sopenharmony_ci        'should npx with listed packages'
731cb0ef41Sopenharmony_ci      )
741cb0ef41Sopenharmony_ci    },
751cb0ef41Sopenharmony_ci  })
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  await npm.exec('init', ['react-app'])
781cb0ef41Sopenharmony_ci})
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_cit.test('npm init <arg> -- other-args', async t => {
811cb0ef41Sopenharmony_ci  t.plan(1)
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
841cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
851cb0ef41Sopenharmony_ci      t.same(
861cb0ef41Sopenharmony_ci        args,
871cb0ef41Sopenharmony_ci        ['create-react-app@*', 'my-path', '--some-option', 'some-value'],
881cb0ef41Sopenharmony_ci        'should npm exec with expected args'
891cb0ef41Sopenharmony_ci      )
901cb0ef41Sopenharmony_ci    },
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci  })
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci  await npm.exec('init', ['react-app', 'my-path', '--some-option', 'some-value'])
951cb0ef41Sopenharmony_ci})
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_cit.test('npm init @scope/name', async t => {
981cb0ef41Sopenharmony_ci  t.plan(1)
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
1011cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
1021cb0ef41Sopenharmony_ci      t.same(
1031cb0ef41Sopenharmony_ci        args,
1041cb0ef41Sopenharmony_ci        ['@npmcli/create-something@*'],
1051cb0ef41Sopenharmony_ci        'should npx with scoped packages'
1061cb0ef41Sopenharmony_ci      )
1071cb0ef41Sopenharmony_ci    },
1081cb0ef41Sopenharmony_ci  })
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ci  await npm.exec('init', ['@npmcli/something'])
1111cb0ef41Sopenharmony_ci})
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_cit.test('npm init @scope@spec', async t => {
1141cb0ef41Sopenharmony_ci  t.plan(1)
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
1171cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
1181cb0ef41Sopenharmony_ci      t.same(
1191cb0ef41Sopenharmony_ci        args,
1201cb0ef41Sopenharmony_ci        ['@npmcli/create@foo'],
1211cb0ef41Sopenharmony_ci        'should npx with scoped packages'
1221cb0ef41Sopenharmony_ci      )
1231cb0ef41Sopenharmony_ci    },
1241cb0ef41Sopenharmony_ci  })
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci  await npm.exec('init', ['@npmcli@foo'])
1271cb0ef41Sopenharmony_ci})
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_cit.test('npm init @scope/name@spec', async t => {
1301cb0ef41Sopenharmony_ci  t.plan(1)
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
1331cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
1341cb0ef41Sopenharmony_ci      t.same(
1351cb0ef41Sopenharmony_ci        args,
1361cb0ef41Sopenharmony_ci        ['@npmcli/create-something@foo'],
1371cb0ef41Sopenharmony_ci        'should npx with scoped packages'
1381cb0ef41Sopenharmony_ci      )
1391cb0ef41Sopenharmony_ci    },
1401cb0ef41Sopenharmony_ci  })
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci  await npm.exec('init', ['@npmcli/something@foo'])
1431cb0ef41Sopenharmony_ci})
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_cit.test('npm init git spec', async t => {
1461cb0ef41Sopenharmony_ci  t.plan(1)
1471cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
1481cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
1491cb0ef41Sopenharmony_ci      t.same(
1501cb0ef41Sopenharmony_ci        args,
1511cb0ef41Sopenharmony_ci        ['npm/create-something'],
1521cb0ef41Sopenharmony_ci        'should npx with git-spec packages'
1531cb0ef41Sopenharmony_ci      )
1541cb0ef41Sopenharmony_ci    },
1551cb0ef41Sopenharmony_ci  })
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci  await npm.exec('init', ['npm/something'])
1581cb0ef41Sopenharmony_ci})
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_cit.test('npm init @scope', async t => {
1611cb0ef41Sopenharmony_ci  t.plan(1)
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
1641cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
1651cb0ef41Sopenharmony_ci      t.same(
1661cb0ef41Sopenharmony_ci        args,
1671cb0ef41Sopenharmony_ci        ['@npmcli/create'],
1681cb0ef41Sopenharmony_ci        'should npx with @scope/create pkgs'
1691cb0ef41Sopenharmony_ci      )
1701cb0ef41Sopenharmony_ci    },
1711cb0ef41Sopenharmony_ci  })
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_ci  await npm.exec('init', ['@npmcli'])
1741cb0ef41Sopenharmony_ci})
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_cit.test('npm init tgz', async t => {
1771cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t)
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_ci  await t.rejects(
1801cb0ef41Sopenharmony_ci    npm.exec('init', ['something.tgz']),
1811cb0ef41Sopenharmony_ci    /Unrecognized initializer: something.tgz/,
1821cb0ef41Sopenharmony_ci    'should throw error when using an unsupported spec'
1831cb0ef41Sopenharmony_ci  )
1841cb0ef41Sopenharmony_ci})
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_cit.test('npm init <arg>@next', async t => {
1871cb0ef41Sopenharmony_ci  t.plan(1)
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
1901cb0ef41Sopenharmony_ci    libnpmexec: ({ args }) => {
1911cb0ef41Sopenharmony_ci      t.same(
1921cb0ef41Sopenharmony_ci        args,
1931cb0ef41Sopenharmony_ci        ['create-something@next'],
1941cb0ef41Sopenharmony_ci        'should npx with something@next'
1951cb0ef41Sopenharmony_ci      )
1961cb0ef41Sopenharmony_ci    },
1971cb0ef41Sopenharmony_ci  })
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ci  await npm.exec('init', ['something@next'])
2001cb0ef41Sopenharmony_ci})
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_cit.test('npm init exec error', async t => {
2031cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
2041cb0ef41Sopenharmony_ci    libnpmexec: async () => {
2051cb0ef41Sopenharmony_ci      throw new Error('ERROR')
2061cb0ef41Sopenharmony_ci    },
2071cb0ef41Sopenharmony_ci  })
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci  await t.rejects(
2101cb0ef41Sopenharmony_ci    npm.exec('init', ['something@next']),
2111cb0ef41Sopenharmony_ci    /ERROR/,
2121cb0ef41Sopenharmony_ci    'should exit with exec error'
2131cb0ef41Sopenharmony_ci  )
2141cb0ef41Sopenharmony_ci})
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_cit.test('should not rewrite flatOptions', async t => {
2171cb0ef41Sopenharmony_ci  t.plan(1)
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
2201cb0ef41Sopenharmony_ci    libnpmexec: async ({ args }) => {
2211cb0ef41Sopenharmony_ci      t.same(
2221cb0ef41Sopenharmony_ci        args,
2231cb0ef41Sopenharmony_ci        ['create-react-app@*', 'my-app'],
2241cb0ef41Sopenharmony_ci        'should npx with extra args'
2251cb0ef41Sopenharmony_ci      )
2261cb0ef41Sopenharmony_ci    },
2271cb0ef41Sopenharmony_ci  })
2281cb0ef41Sopenharmony_ci
2291cb0ef41Sopenharmony_ci  await npm.exec('init', ['react-app', 'my-app'])
2301cb0ef41Sopenharmony_ci})
2311cb0ef41Sopenharmony_ci
2321cb0ef41Sopenharmony_cit.test('npm init cancel', async t => {
2331cb0ef41Sopenharmony_ci  const { npm, logs } = await mockNpm(t, {
2341cb0ef41Sopenharmony_ci    initPackageJson: async () => {
2351cb0ef41Sopenharmony_ci      throw new Error('canceled')
2361cb0ef41Sopenharmony_ci    },
2371cb0ef41Sopenharmony_ci  })
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_ci  await npm.exec('init', [])
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ci  t.equal(logs.warn[0][0], 'init', 'should have init title')
2421cb0ef41Sopenharmony_ci  t.equal(logs.warn[0][1], 'canceled', 'should log canceled')
2431cb0ef41Sopenharmony_ci})
2441cb0ef41Sopenharmony_ci
2451cb0ef41Sopenharmony_cit.test('npm init error', async t => {
2461cb0ef41Sopenharmony_ci  const { npm } = await mockNpm(t, {
2471cb0ef41Sopenharmony_ci    initPackageJson: async () => {
2481cb0ef41Sopenharmony_ci      throw new Error('Unknown Error')
2491cb0ef41Sopenharmony_ci    },
2501cb0ef41Sopenharmony_ci  })
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci  await t.rejects(
2531cb0ef41Sopenharmony_ci    npm.exec('init', []),
2541cb0ef41Sopenharmony_ci    /Unknown Error/,
2551cb0ef41Sopenharmony_ci    'should throw error'
2561cb0ef41Sopenharmony_ci  )
2571cb0ef41Sopenharmony_ci})
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_cit.test('workspaces', async t => {
2601cb0ef41Sopenharmony_ci  await t.test('no args -- yes', async t => {
2611cb0ef41Sopenharmony_ci    const { npm, prefix, joinedOutput } = await mockNpm(t, {
2621cb0ef41Sopenharmony_ci      prefixDir: {
2631cb0ef41Sopenharmony_ci        'package.json': JSON.stringify({
2641cb0ef41Sopenharmony_ci          name: 'top-level',
2651cb0ef41Sopenharmony_ci        }),
2661cb0ef41Sopenharmony_ci      },
2671cb0ef41Sopenharmony_ci      config: { workspace: 'a', yes: true },
2681cb0ef41Sopenharmony_ci      noLog: true,
2691cb0ef41Sopenharmony_ci    })
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_ci    await npm.exec('init', [])
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci    const pkg = require(resolve(prefix, 'a/package.json'))
2741cb0ef41Sopenharmony_ci    t.equal(pkg.name, 'a')
2751cb0ef41Sopenharmony_ci    t.equal(pkg.version, '1.0.0')
2761cb0ef41Sopenharmony_ci    t.equal(pkg.license, 'ISC')
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_ci    t.matchSnapshot(joinedOutput(), 'should print helper info')
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci    const lock = require(resolve(prefix, 'package-lock.json'))
2811cb0ef41Sopenharmony_ci    t.ok(lock.packages.a)
2821cb0ef41Sopenharmony_ci  })
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ci  await t.test('no args, existing folder', async t => {
2851cb0ef41Sopenharmony_ci    const { npm, prefix } = await mockNpm(t, {
2861cb0ef41Sopenharmony_ci      prefixDir: {
2871cb0ef41Sopenharmony_ci        packages: {
2881cb0ef41Sopenharmony_ci          a: {
2891cb0ef41Sopenharmony_ci            'package.json': JSON.stringify({
2901cb0ef41Sopenharmony_ci              name: 'a',
2911cb0ef41Sopenharmony_ci              version: '2.0.0',
2921cb0ef41Sopenharmony_ci            }),
2931cb0ef41Sopenharmony_ci          },
2941cb0ef41Sopenharmony_ci        },
2951cb0ef41Sopenharmony_ci        'package.json': JSON.stringify({
2961cb0ef41Sopenharmony_ci          name: 'top-level',
2971cb0ef41Sopenharmony_ci          workspaces: ['packages/a'],
2981cb0ef41Sopenharmony_ci        }),
2991cb0ef41Sopenharmony_ci      },
3001cb0ef41Sopenharmony_ci      config: { workspace: 'packages/a', yes: true },
3011cb0ef41Sopenharmony_ci      noLog: true,
3021cb0ef41Sopenharmony_ci    })
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ci    await npm.exec('init', [])
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci    const pkg = require(resolve(prefix, 'packages/a/package.json'))
3071cb0ef41Sopenharmony_ci    t.equal(pkg.name, 'a')
3081cb0ef41Sopenharmony_ci    t.equal(pkg.version, '2.0.0')
3091cb0ef41Sopenharmony_ci    t.equal(pkg.license, 'ISC')
3101cb0ef41Sopenharmony_ci  })
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci  await t.test('fail parsing top-level package.json to set workspace', async t => {
3131cb0ef41Sopenharmony_ci    const { npm } = await mockNpm(t, {
3141cb0ef41Sopenharmony_ci      prefixDir: {
3151cb0ef41Sopenharmony_ci        'package.json': 'not json[',
3161cb0ef41Sopenharmony_ci      },
3171cb0ef41Sopenharmony_ci      config: { workspace: 'a', yes: true },
3181cb0ef41Sopenharmony_ci      noLog: true,
3191cb0ef41Sopenharmony_ci    })
3201cb0ef41Sopenharmony_ci
3211cb0ef41Sopenharmony_ci    await t.rejects(
3221cb0ef41Sopenharmony_ci      npm.exec('init', []),
3231cb0ef41Sopenharmony_ci      { code: 'EJSONPARSE' }
3241cb0ef41Sopenharmony_ci    )
3251cb0ef41Sopenharmony_ci  })
3261cb0ef41Sopenharmony_ci
3271cb0ef41Sopenharmony_ci  await t.test('missing top-level package.json when settting workspace', async t => {
3281cb0ef41Sopenharmony_ci    const { npm, logs } = await mockNpm(t, {
3291cb0ef41Sopenharmony_ci      config: { workspace: 'a' },
3301cb0ef41Sopenharmony_ci    })
3311cb0ef41Sopenharmony_ci
3321cb0ef41Sopenharmony_ci    await t.rejects(
3331cb0ef41Sopenharmony_ci      npm.exec('init', []),
3341cb0ef41Sopenharmony_ci      { code: 'ENOENT' },
3351cb0ef41Sopenharmony_ci      'should exit with missing package.json file error'
3361cb0ef41Sopenharmony_ci    )
3371cb0ef41Sopenharmony_ci
3381cb0ef41Sopenharmony_ci    t.equal(logs.warn[0][0], 'Missing package.json. Try with `--include-workspace-root`.')
3391cb0ef41Sopenharmony_ci  })
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_ci  await t.test('bad package.json when settting workspace', async t => {
3421cb0ef41Sopenharmony_ci    const { npm, logs } = await mockNpm(t, {
3431cb0ef41Sopenharmony_ci      prefixDir: {
3441cb0ef41Sopenharmony_ci        'package.json': '{{{{',
3451cb0ef41Sopenharmony_ci      },
3461cb0ef41Sopenharmony_ci      config: { workspace: 'a' },
3471cb0ef41Sopenharmony_ci    })
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_ci    await t.rejects(
3501cb0ef41Sopenharmony_ci      npm.exec('init', []),
3511cb0ef41Sopenharmony_ci      { code: 'EJSONPARSE' },
3521cb0ef41Sopenharmony_ci      'should exit with parse file error'
3531cb0ef41Sopenharmony_ci    )
3541cb0ef41Sopenharmony_ci
3551cb0ef41Sopenharmony_ci    t.strictSame(logs.warn, [])
3561cb0ef41Sopenharmony_ci  })
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ci  await t.test('using args - no package.json', async t => {
3591cb0ef41Sopenharmony_ci    const { npm, prefix } = await mockNpm(t, {
3601cb0ef41Sopenharmony_ci      prefixDir: {
3611cb0ef41Sopenharmony_ci        b: {
3621cb0ef41Sopenharmony_ci          'package.json': JSON.stringify({
3631cb0ef41Sopenharmony_ci            name: 'b',
3641cb0ef41Sopenharmony_ci          }),
3651cb0ef41Sopenharmony_ci        },
3661cb0ef41Sopenharmony_ci        'package.json': JSON.stringify({
3671cb0ef41Sopenharmony_ci          name: 'top-level',
3681cb0ef41Sopenharmony_ci          workspaces: ['b'],
3691cb0ef41Sopenharmony_ci        }),
3701cb0ef41Sopenharmony_ci      },
3711cb0ef41Sopenharmony_ci      // Important: exec did not write a package.json here
3721cb0ef41Sopenharmony_ci      libnpmexec: async () => {},
3731cb0ef41Sopenharmony_ci      config: { workspace: 'a', yes: true },
3741cb0ef41Sopenharmony_ci    })
3751cb0ef41Sopenharmony_ci
3761cb0ef41Sopenharmony_ci    await npm.exec('init', ['react-app'])
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ci    const pkg = require(resolve(prefix, 'package.json'))
3791cb0ef41Sopenharmony_ci    t.strictSame(pkg.workspaces, ['b'], 'pkg workspaces did not get updated')
3801cb0ef41Sopenharmony_ci  })
3811cb0ef41Sopenharmony_ci
3821cb0ef41Sopenharmony_ci  await t.test('init template - bad package.json', async t => {
3831cb0ef41Sopenharmony_ci    const { npm, prefix } = await mockNpm(t, {
3841cb0ef41Sopenharmony_ci      prefixDir: {
3851cb0ef41Sopenharmony_ci        b: {
3861cb0ef41Sopenharmony_ci          'package.json': JSON.stringify({
3871cb0ef41Sopenharmony_ci            name: 'b',
3881cb0ef41Sopenharmony_ci          }),
3891cb0ef41Sopenharmony_ci        },
3901cb0ef41Sopenharmony_ci        'package.json': JSON.stringify({
3911cb0ef41Sopenharmony_ci          name: 'top-level',
3921cb0ef41Sopenharmony_ci          workspaces: ['b'],
3931cb0ef41Sopenharmony_ci        }),
3941cb0ef41Sopenharmony_ci      },
3951cb0ef41Sopenharmony_ci      initPackageJson: async (...args) => {
3961cb0ef41Sopenharmony_ci        const [dir] = args
3971cb0ef41Sopenharmony_ci        if (dir.endsWith('c')) {
3981cb0ef41Sopenharmony_ci          await fs.writeFile(resolve(dir, 'package.json'), JSON.stringify({
3991cb0ef41Sopenharmony_ci            name: basename(dir),
4001cb0ef41Sopenharmony_ci          }), 'utf-8')
4011cb0ef41Sopenharmony_ci        }
4021cb0ef41Sopenharmony_ci      },
4031cb0ef41Sopenharmony_ci      config: { yes: true, workspace: ['a', 'c'] },
4041cb0ef41Sopenharmony_ci    })
4051cb0ef41Sopenharmony_ci
4061cb0ef41Sopenharmony_ci    await npm.exec('init', [])
4071cb0ef41Sopenharmony_ci
4081cb0ef41Sopenharmony_ci    const pkg = require(resolve(prefix, 'package.json'))
4091cb0ef41Sopenharmony_ci    t.strictSame(pkg.workspaces, ['b', 'c'])
4101cb0ef41Sopenharmony_ci
4111cb0ef41Sopenharmony_ci    const lock = require(resolve(prefix, 'package-lock.json'))
4121cb0ef41Sopenharmony_ci    t.notOk(lock.packages.a)
4131cb0ef41Sopenharmony_ci  })
4141cb0ef41Sopenharmony_ci
4151cb0ef41Sopenharmony_ci  t.test('workspace root', async t => {
4161cb0ef41Sopenharmony_ci    const { npm } = await mockNpm(t, {
4171cb0ef41Sopenharmony_ci      config: { workspace: 'packages/a', 'include-workspace-root': true, yes: true },
4181cb0ef41Sopenharmony_ci      noLog: true,
4191cb0ef41Sopenharmony_ci    })
4201cb0ef41Sopenharmony_ci
4211cb0ef41Sopenharmony_ci    await npm.exec('init', [])
4221cb0ef41Sopenharmony_ci
4231cb0ef41Sopenharmony_ci    const pkg = require(resolve(npm.localPrefix, 'package.json'))
4241cb0ef41Sopenharmony_ci    t.equal(pkg.version, '1.0.0')
4251cb0ef41Sopenharmony_ci    t.equal(pkg.license, 'ISC')
4261cb0ef41Sopenharmony_ci    t.strictSame(pkg.workspaces, ['packages/a'])
4271cb0ef41Sopenharmony_ci
4281cb0ef41Sopenharmony_ci    const ws = require(resolve(npm.localPrefix, 'packages/a/package.json'))
4291cb0ef41Sopenharmony_ci    t.equal(ws.version, '1.0.0')
4301cb0ef41Sopenharmony_ci    t.equal(ws.license, 'ISC')
4311cb0ef41Sopenharmony_ci  })
4321cb0ef41Sopenharmony_ci})
433