|
3 | 3 | const la = require('lazy-ass') |
4 | 4 | const R = require('ramda') |
5 | 5 | const { stubSpawnShellOnce } = require('stub-spawn-once') |
| 6 | +const Promise = require('bluebird') |
| 7 | +const snapshot = require('snap-shot-it') |
6 | 8 |
|
7 | 9 | /* eslint-env mocha */ |
8 | 10 | describe('utils', () => { |
| 11 | + const { gitCommands } = require('./utils') |
| 12 | + |
| 13 | + describe('getting commit info', () => { |
| 14 | + const { |
| 15 | + getMessage, |
| 16 | + getEmail, |
| 17 | + getAuthor, |
| 18 | + getSha, |
| 19 | + getRemoteOrigin |
| 20 | + } = require('./utils') |
| 21 | + |
| 22 | + it('works', () => { |
| 23 | + stubSpawnShellOnce(gitCommands.message, 0, 'important commit', '') |
| 24 | + stubSpawnShellOnce(gitCommands.email, 0, '[email protected]', '') |
| 25 | + stubSpawnShellOnce(gitCommands.author, 0, 'John Doe', '') |
| 26 | + stubSpawnShellOnce(gitCommands.sha, 0, 'abc123', '') |
| 27 | + stubSpawnShellOnce( |
| 28 | + gitCommands.remoteOriginUrl, |
| 29 | + 0, |
| 30 | + |
| 31 | + '' |
| 32 | + ) |
| 33 | + |
| 34 | + return Promise.props({ |
| 35 | + message: getMessage(), |
| 36 | + email: getEmail(), |
| 37 | + author: getAuthor(), |
| 38 | + sha: getSha(), |
| 39 | + remote: getRemoteOrigin() |
| 40 | + }).then(snapshot) |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
9 | 44 | describe('getBranch', () => { |
10 | 45 | const { getBranch } = require('./utils') |
11 | 46 |
|
@@ -43,24 +78,21 @@ describe('utils', () => { |
43 | 78 | }) |
44 | 79 |
|
45 | 80 | it('uses git to determine branch', () => { |
46 | | - const cmd = 'git rev-parse --abbrev-ref HEAD' |
47 | | - stubSpawnShellOnce(cmd, 0, 'mock-test-branch', '') |
| 81 | + stubSpawnShellOnce(gitCommands.branch, 0, 'mock-test-branch', '') |
48 | 82 | return getBranch().then(branch => |
49 | 83 | la(branch === 'mock-test-branch', 'wrong branch from git', branch) |
50 | 84 | ) |
51 | 85 | }) |
52 | 86 |
|
53 | 87 | it('returns empty string on failure', () => { |
54 | | - const cmd = 'git rev-parse --abbrev-ref HEAD' |
55 | | - stubSpawnShellOnce(cmd, 1, '', 'nope') |
| 88 | + stubSpawnShellOnce(gitCommands.branch, 1, '', 'nope') |
56 | 89 | return getBranch().then(branch => |
57 | 90 | la(branch === '', 'wrong empty branch from git', branch) |
58 | 91 | ) |
59 | 92 | }) |
60 | 93 |
|
61 | 94 | it('returns empty string on HEAD', () => { |
62 | | - const cmd = 'git rev-parse --abbrev-ref HEAD' |
63 | | - stubSpawnShellOnce(cmd, 0, 'HEAD', '') |
| 95 | + stubSpawnShellOnce(gitCommands.branch, 0, 'HEAD', '') |
64 | 96 | return getBranch().then(branch => |
65 | 97 | la(branch === '', 'wrong HEAD branch from git', branch) |
66 | 98 | ) |
|
0 commit comments