|
| 1 | +const t = require('tap') |
| 2 | +const { join } = require('path') |
| 3 | +const setup = require('../setup.js') |
| 4 | + |
| 5 | +t.test('custom node', async (t) => { |
| 6 | + const s = await setup(t, { |
| 7 | + ok: true, |
| 8 | + package: { |
| 9 | + templateOSS: { |
| 10 | + npmBin: 'node /path/to/npm', |
| 11 | + }, |
| 12 | + }, |
| 13 | + }) |
| 14 | + await s.apply() |
| 15 | + const { scripts } = await s.readJson('package.json') |
| 16 | + t.equal(scripts.posttest, 'node /path/to/npm run lint') |
| 17 | +}) |
| 18 | + |
| 19 | +t.test('custom node', async (t) => { |
| 20 | + const s = await setup(t, { |
| 21 | + ok: true, |
| 22 | + package: { |
| 23 | + templateOSS: { |
| 24 | + npmBin: 'node /path/to/npm', |
| 25 | + }, |
| 26 | + }, |
| 27 | + }) |
| 28 | + await s.apply() |
| 29 | + const { scripts } = await s.readJson('package.json') |
| 30 | + t.equal(scripts.posttest, 'node /path/to/npm run lint') |
| 31 | +}) |
| 32 | + |
| 33 | +t.test('relative npm bin with workspaces', async (t) => { |
| 34 | + const s = await setup(t, { |
| 35 | + ok: true, |
| 36 | + package: { |
| 37 | + templateOSS: { |
| 38 | + npmBin: 'cli.js', |
| 39 | + }, |
| 40 | + }, |
| 41 | + workspaces: { a: '@name/aaaa', b: 'bbb' }, |
| 42 | + }) |
| 43 | + await s.apply() |
| 44 | + const { scripts } = await s.readJson('package.json') |
| 45 | + const { scripts: scriptsA } = await s.readJson(join(s.workspaces.a, 'package.json')) |
| 46 | + const { scripts: scriptsB } = await s.readJson(join(s.workspaces.b, 'package.json')) |
| 47 | + t.equal(scripts.posttest, 'node cli.js run lint') |
| 48 | + t.equal(scriptsA.posttest, 'node ../../cli.js run lint') |
| 49 | + t.equal(scriptsB.posttest, 'node ../../cli.js run lint') |
| 50 | +}) |
| 51 | + |
| 52 | +t.test('npm bin workspaces only with root config', async (t) => { |
| 53 | + const s = await setup(t, { |
| 54 | + ok: true, |
| 55 | + package: { |
| 56 | + templateOSS: { |
| 57 | + rootRepo: false, |
| 58 | + rootModule: false, |
| 59 | + npmBin: './cli.js', |
| 60 | + }, |
| 61 | + }, |
| 62 | + workspaces: { a: '@name/aaaa', b: 'bbb' }, |
| 63 | + }) |
| 64 | + await s.apply() |
| 65 | + const { scripts } = await s.readJson('package.json') |
| 66 | + const { scripts: scriptsA } = await s.readJson(join(s.workspaces.a, 'package.json')) |
| 67 | + const { scripts: scriptsB } = await s.readJson(join(s.workspaces.b, 'package.json')) |
| 68 | + t.equal(scripts, undefined) |
| 69 | + t.equal(scriptsA.posttest, 'node ../../cli.js run lint') |
| 70 | + t.equal(scriptsB.posttest, 'node ../../cli.js run lint') |
| 71 | +}) |
| 72 | + |
| 73 | +t.test('separate workspace configs', async (t) => { |
| 74 | + const s = await setup(t, { |
| 75 | + ok: true, |
| 76 | + package: { |
| 77 | + templateOSS: { |
| 78 | + rootRepo: false, |
| 79 | + rootModule: false, |
| 80 | + }, |
| 81 | + }, |
| 82 | + workspaces: { |
| 83 | + a: { |
| 84 | + name: 'a', |
| 85 | + templateOSS: { |
| 86 | + npmBin: 'bin_a.js', |
| 87 | + }, |
| 88 | + }, |
| 89 | + b: { |
| 90 | + name: 'b', |
| 91 | + templateOSS: { |
| 92 | + npmBin: 'bin_b.js', |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + }) |
| 97 | + await s.apply() |
| 98 | + const { scripts } = await s.readJson('package.json') |
| 99 | + const { scripts: scriptsA } = await s.readJson(join(s.workspaces.a, 'package.json')) |
| 100 | + const { scripts: scriptsB } = await s.readJson(join(s.workspaces.b, 'package.json')) |
| 101 | + t.equal(scripts, undefined) |
| 102 | + t.equal(scriptsA.posttest, 'node bin_a.js run lint') |
| 103 | + t.equal(scriptsB.posttest, 'node bin_b.js run lint') |
| 104 | +}) |
0 commit comments