diff --git a/src/cli/tasks.ts b/src/cli/tasks.ts index e5e89c6..c77de38 100644 --- a/src/cli/tasks.ts +++ b/src/cli/tasks.ts @@ -15,10 +15,10 @@ export interface Tasks { readonly cloneRepo: ( dir: string ) => Promise<{ readonly commitHash: string; readonly gitHistoryDir: string }>; - readonly getGithubUsername: (email: string) => Promise; + readonly getGithubUsername: (email: string | undefined) => Promise; readonly getUserInfo: () => Promise<{ - readonly gitEmail: string; - readonly gitName: string; + readonly gitEmail: string | undefined; + readonly gitName: string | undefined; }>; readonly initialCommit: (hash: string, projectDir: string) => Promise; readonly install: ( @@ -65,23 +65,37 @@ export const cloneRepo = (spawner: ExecaStatic) => async (dir: string) => { } }; -export const getGithubUsername = (fetcher: any) => async (email: string) => - fetcher(email).catch(() => { +export const getGithubUsername = (fetcher: any) => async ( + email: string | undefined +) => { + const placeholder = 'YOUR_USER_NAME'; + if (email === undefined) { + return placeholder; + } + return fetcher(email).catch(() => { // if username isn't found, just return a placeholder - return 'YOUR_USER_NAME'; + return placeholder; }); +}; export const getUserInfo = (spawner: ExecaStatic) => async () => { const opts: Options = { encoding: 'utf8', stdio: ['pipe', 'pipe', inherit] }; - const nameResult = await spawner('git', ['config', 'user.name'], opts); - const emailResult = await spawner('git', ['config', 'user.email'], opts); - return { - gitEmail: emailResult.stdout, - gitName: nameResult.stdout - }; + try { + const nameResult = await spawner('git', ['config', 'user.name'], opts); + const emailResult = await spawner('git', ['config', 'user.email'], opts); + return { + gitEmail: emailResult.stdout, + gitName: nameResult.stdout + }; + } catch (err) { + return { + gitEmail: undefined, + gitName: undefined + }; + } }; export const initialCommit = (spawner: ExecaStatic) => async ( diff --git a/src/cli/tests/cli.integration.spec.ts b/src/cli/tests/cli.integration.spec.ts index 7ce930a..f372846 100644 --- a/src/cli/tests/cli.integration.spec.ts +++ b/src/cli/tests/cli.integration.spec.ts @@ -116,7 +116,7 @@ async function testInteractive( const lastCheck = entry[3] !== undefined; t.plan(lastCheck ? 6 : 5); - const proc = execa(`../bin/typescript-starter`, ['--noinstall'], { + const proc = execa(`../bin/typescript-starter`, { cwd: join(process.cwd(), 'build'), env: { TYPESCRIPT_STARTER_REPO_URL: process.cwd() @@ -157,7 +157,6 @@ async function testInteractive( clearBuffer(); type(`${entry[2][0]}${enter}`); await ms(200); - const search = `${entry[2][1]}.|s*global type definitions`; const exp = lastCheck ? new RegExp(`${search}`) // should match @@ -170,8 +169,6 @@ async function testInteractive( await ms(200); checkBuffer(new RegExp(`${entry[3][1]}`)); } - - // TODO: validate contents? } test('integration test 3: interactive mode, javascript library', async t => { diff --git a/src/cli/tests/cli.unit.spec.ts b/src/cli/tests/cli.unit.spec.ts index b6af6fa..3bd1939 100644 --- a/src/cli/tests/cli.unit.spec.ts +++ b/src/cli/tests/cli.unit.spec.ts @@ -110,9 +110,12 @@ test('getGithubUsername: returns placeholder if not found', async t => { t.is(username, 'YOUR_USER_NAME'); }); -test('getUserInfo: throws generated errors', async t => { - const error = await t.throws(getUserInfo(mockErr(1))()); - t.is(error.code, 1); +test('getUserInfo: suppresses errors and returns undefined', async t => { + const result = await getUserInfo(mockErr(1))(); + t.deepEqual(result, { + gitEmail: undefined, + gitName: undefined + }); }); test('initialCommit: throws generated errors', async t => {