-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Command } from "commander"; | ||
const program = new Command(); | ||
|
||
program | ||
.name('random-bunny') | ||
.description('Get a random image url from a subreddit of your choosing') | ||
.version('2.2'); | ||
|
||
program.parse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { exec } from "child_process"; | ||
import path from "path"; | ||
|
||
describe('version', () => { | ||
test('GIVEN -V flag is supplied, EXPECT version returned', async () => { | ||
const result = await cli(['-V'], '.'); | ||
|
||
expect(result.code).toBe(0); | ||
expect(result.stdout).toBe('2.2\n'); | ||
}); | ||
|
||
test('GIVEN --version is supplied, EXPECT version returned', async () => { | ||
const result = await cli(['--version'], '.'); | ||
|
||
expect(result.code).toBe(0); | ||
expect(result.stdout).toBe('2.2\n'); | ||
}); | ||
}); | ||
|
||
describe('help', () => { | ||
test('GIVEN -h is supplied, EXPECT help returned', async () => { | ||
const result = await cli(['-h'], '.'); | ||
|
||
expect(result.code).toBe(0); | ||
expect(result.stdout.split('\n')[0]).toBe('Usage: random-bunny [options]'); | ||
}); | ||
|
||
test('GIVEN --help is supplied, EXPECT help returned', async () => { | ||
const result = await cli(['--help'], '.'); | ||
|
||
expect(result.code).toBe(0); | ||
expect(result.stdout.split('\n')[0]).toBe('Usage: random-bunny [options]'); | ||
}); | ||
}) | ||
|
||
function cli(args: string[], cwd: string): Promise<cliResult> { | ||
return new Promise(resolve => { | ||
exec(`node ${path.resolve('./dist/cli.js')} ${args.join(' ')}`, | ||
{ cwd }, | ||
(error, stdout, stderr) => { resolve({ | ||
code: error && error.code ? error.code : 0, | ||
error, | ||
stdout, | ||
stderr }); | ||
}); | ||
}); | ||
} | ||
|
||
interface cliResult { | ||
code: number, | ||
error: any, | ||
stdout: string, | ||
stderr: string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters