Skip to content

Commit 1e375f7

Browse files
authored
fix: coverage config (#13)
- should report correct code coverage - added a few more tests
1 parent e4d0ffc commit 1e375f7

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

.nycrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.nycrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript",
3+
"include": ["src/**/*.ts"],
4+
"exclude": ["src/types/**"]
5+
}

src/prompts/project-options.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,19 @@
55
import { join } from 'path';
66
import { prompt, registerPrompt, Answers } from 'inquirer';
77
import autocomplete from 'inquirer-autocomplete-prompt';
8-
import chalk from 'chalk';
98
import fuzzy from 'fuzzy';
10-
import { kebabCase, startCase } from '../util';
9+
import { kebabCase, startCase, displayAsPath } from '../util';
1110
import { ProjectOptions } from '../types';
1211

1312
registerPrompt('autocomplete', autocomplete);
1413

15-
const displayAsPath = (newProjectDir: string): string => {
16-
return `${chalk.gray(process.cwd() + '/')}${chalk.cyan(kebabCase(newProjectDir))}`;
17-
};
18-
1914
async function buildOptions(repoNames: string[]): Promise<ProjectOptions> {
2015
const opts = await prompt([
2116
{
2217
type: 'autocomplete',
2318
name: 'sourceRepo',
2419
message: 'search for a repo to replicate',
25-
async source(answers: Answers[], input: string): Promise<string[]> {
26-
input = input || '';
27-
const fuzzyResult = fuzzy.filter(input, repoNames);
28-
return fuzzyResult.map(el => el.original);
29-
},
20+
source: fuzzyMatch(repoNames),
3021
},
3122
{
3223
type: 'input',
@@ -73,4 +64,12 @@ async function confirmOptions(): Promise<boolean> {
7364
return confirmation;
7465
}
7566

76-
export { buildOptions, confirmOptions };
67+
function fuzzyMatch(repoNames: string[]) {
68+
return async (answers: Answers[], input: string): Promise<string[]> => {
69+
input = input || '';
70+
const fuzzyResult = fuzzy.filter(input, repoNames);
71+
return fuzzyResult.map(el => el.original);
72+
};
73+
}
74+
75+
export { buildOptions, confirmOptions, fuzzyMatch };

src/util/strings.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import path from 'path';
2+
import chalk from 'chalk';
3+
14
function kebabCase(text: string): string {
25
return text.toLowerCase().replace(/\s/g, '-');
36
}
@@ -19,8 +22,12 @@ function password(text: string): string {
1922
.join('');
2023
}
2124

25+
function displayAsPath(newProjectDir: string): string {
26+
return `${chalk.gray(process.cwd() + path.sep)}${chalk.cyan(kebabCase(newProjectDir))}`;
27+
}
28+
2229
function tarUrl(repoName: string, branch = 'master'): string {
2330
return `https://api.github.com/repos/sparkbox/${repoName}/tarball/${branch}`;
2431
}
2532

26-
export { kebabCase, startCase, password, tarUrl };
33+
export { kebabCase, startCase, password, tarUrl, displayAsPath };

test/util.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import test from 'ava';
33
import tempy from 'tempy';
4-
import { password, kebabCase, startCase, tarUrl, write } from '../src/util';
4+
import { password, kebabCase, startCase, displayAsPath, tarUrl, write, run } from '../src/util';
55

66
test('password', t => {
77
const hiddenText = password('secret');
@@ -18,6 +18,13 @@ test('startCase', t => {
1818
t.is(humanText, 'These Are Words');
1919
});
2020

21+
test('displayAsPath', t => {
22+
const cwd = process.cwd();
23+
const displayPath = displayAsPath('my-new-project');
24+
t.assert(displayPath.includes(cwd));
25+
t.assert(displayPath.includes('my-new-project'));
26+
});
27+
2128
test('tarUrl', t => {
2229
const url = tarUrl('my-repo');
2330
t.is(url, 'https://api.github.com/repos/sparkbox/my-repo/tarball/master');
@@ -31,3 +38,16 @@ test('write is a promisified fs.write', async t => {
3138
await promiseWrite;
3239
t.is(fs.readFileSync(testFile, 'utf-8'), 'some-data');
3340
});
41+
42+
test('run', async t => {
43+
const stdout = await run(`echo "hello"`);
44+
t.assert(stdout.includes('hello'));
45+
});
46+
47+
test('run rejects with a ShellError', async t => {
48+
try {
49+
await run('invalid command');
50+
} catch (e) {
51+
t.is(e.name, 'ShellError');
52+
}
53+
});

0 commit comments

Comments
 (0)