|
| 1 | +const t = require('tap') |
| 2 | +const { setup, child, isChild } = require('./fixtures/setup') |
| 3 | + |
| 4 | +if (isChild()) { |
| 5 | + return child() |
| 6 | +} |
| 7 | + |
| 8 | +t.test('author from config used as default', async (t) => { |
| 9 | + const { data } = await setup(t, __filename, { |
| 10 | + inputs: { |
| 11 | + name: 'the-name', |
| 12 | + author: [ |
| 13 | + [/author: \(npmbot <n@p\.m> \(http:\/\/npm\.im\)\) $/, ''], |
| 14 | + ], |
| 15 | + }, |
| 16 | + config: { |
| 17 | + 'init-author-name': 'npmbot', |
| 18 | + 'init-author-email': 'n@p.m', |
| 19 | + 'init-author-url': 'http://npm.im', |
| 20 | + }, |
| 21 | + }) |
| 22 | + |
| 23 | + t.equal(data.author, 'npmbot <n@p.m> (http://npm.im)', 'uses config author as default') |
| 24 | +}) |
| 25 | + |
| 26 | +t.test('author from config in yes mode', async (t) => { |
| 27 | + const { data } = await setup(t, __filename, { |
| 28 | + config: { |
| 29 | + yes: 'yes', |
| 30 | + 'init-author-name': 'npmbot', |
| 31 | + 'init-author-email': 'n@p.m', |
| 32 | + 'init-author-url': 'http://npm.im', |
| 33 | + }, |
| 34 | + }) |
| 35 | + |
| 36 | + t.equal(data.author, 'npmbot <n@p.m> (http://npm.im)', 'uses config author in yes mode') |
| 37 | +}) |
| 38 | + |
| 39 | +t.test('author omitted when left blank', async (t) => { |
| 40 | + const { data } = await setup(t, __filename, { |
| 41 | + inputs: { |
| 42 | + name: 'the-name', |
| 43 | + author: [ |
| 44 | + [/author: $/, ''], |
| 45 | + ], |
| 46 | + }, |
| 47 | + }) |
| 48 | + |
| 49 | + t.equal(data.author, undefined, 'author is omitted when left blank') |
| 50 | +}) |
| 51 | + |
| 52 | +t.test('author preserved from existing package.json', async (t) => { |
| 53 | + const { data } = await setup(t, __filename, { |
| 54 | + testdir: { |
| 55 | + 'package.json': JSON.stringify({ |
| 56 | + name: 'existing-package', |
| 57 | + version: '1.0.0', |
| 58 | + author: 'Existing Author <exist@example.com>', |
| 59 | + }), |
| 60 | + }, |
| 61 | + config: { yes: 'yes' }, |
| 62 | + }) |
| 63 | + |
| 64 | + t.equal(data.author, 'Existing Author <exist@example.com>', 'preserves existing author') |
| 65 | +}) |
| 66 | + |
| 67 | +t.test('author name only from config', async (t) => { |
| 68 | + const { data } = await setup(t, __filename, { |
| 69 | + config: { |
| 70 | + yes: 'yes', |
| 71 | + 'init-author-name': 'npmbot', |
| 72 | + }, |
| 73 | + }) |
| 74 | + |
| 75 | + t.equal(data.author, 'npmbot', 'uses author name only when no email/url configured') |
| 76 | +}) |
0 commit comments