-
-
Notifications
You must be signed in to change notification settings - Fork 298
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
106 additions
and
11 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 |
---|---|---|
@@ -1,12 +1,57 @@ | ||
import test from 'ava'; | ||
import {linkifyIssues, linkifyCommit} from '../source/util'; | ||
import test, {afterEach} from 'ava'; | ||
import sinon from 'sinon'; | ||
import terminalLink from 'terminal-link'; | ||
|
||
test('link issues', t => { | ||
t.is(linkifyIssues('https://github.com/unicorn/rainbow', 'Commit message - fixes #4'), 'Commit message - fixes ]8;;https://github.com/unicorn/rainbow/issues/4#4]8;;'); | ||
t.is(linkifyIssues('https://github.com/unicorn/rainbow', 'Commit message - fixes #3 #4'), 'Commit message - fixes ]8;;https://github.com/unicorn/rainbow/issues/3#3]8;; ]8;;https://github.com/unicorn/rainbow/issues/4#4]8;;'); | ||
t.is(linkifyIssues('https://github.com/unicorn/rainbow', 'Commit message - fixes foo/bar#4'), 'Commit message - fixes ]8;;https://github.com/foo/bar/issues/4foo/bar#4]8;;'); | ||
import {linkifyIssues, linkifyCommit, linkifyCommitRange} from '../source/util'; | ||
|
||
const MOCK_REPO_URL = 'https://github.com/unicorn/rainbow'; | ||
const MOCK_COMMIT_HASH = '5063f8a'; | ||
const MOCK_COMMIT_RANGE = `${MOCK_COMMIT_HASH}...master`; | ||
|
||
const sandbox = sinon.createSandbox(); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
const mockTerminalLinkUnsupported = () => | ||
sandbox.stub(terminalLink, 'isSupported').value(false); | ||
|
||
test('linkifyIssues correctly links issues', t => { | ||
t.is(linkifyIssues(MOCK_REPO_URL, 'Commit message - fixes #4'), 'Commit message - fixes ]8;;https://github.com/unicorn/rainbow/issues/4#4]8;;'); | ||
t.is(linkifyIssues(MOCK_REPO_URL, 'Commit message - fixes #3 #4'), 'Commit message - fixes ]8;;https://github.com/unicorn/rainbow/issues/3#3]8;; ]8;;https://github.com/unicorn/rainbow/issues/4#4]8;;'); | ||
t.is(linkifyIssues(MOCK_REPO_URL, 'Commit message - fixes foo/bar#4'), 'Commit message - fixes ]8;;https://github.com/foo/bar/issues/4foo/bar#4]8;;'); | ||
}); | ||
|
||
test('linkifyIssues returns raw message if url is not provided', t => { | ||
const msg = 'Commit message - fixes #5'; | ||
t.is(linkifyIssues(undefined, msg), msg); | ||
}); | ||
|
||
test.serial('linkifyIssues returns raw message if terminalLink is not supported', t => { | ||
mockTerminalLinkUnsupported(); | ||
const msg = 'Commit message - fixes #6'; | ||
t.is(linkifyIssues(MOCK_REPO_URL, msg), msg); | ||
}); | ||
|
||
test('linkifyCommit correctly links commits', t => { | ||
t.is(linkifyCommit(MOCK_REPO_URL, MOCK_COMMIT_HASH), ']8;;https://github.com/unicorn/rainbow/commit/5063f8a5063f8a]8;;'); | ||
}); | ||
|
||
test('linkifyCommit returns raw commit hash if url is not provided', t => { | ||
t.is(linkifyCommit(undefined, MOCK_COMMIT_HASH), MOCK_COMMIT_HASH); | ||
}); | ||
|
||
test.serial('linkifyCommit returns raw commit hash if terminalLink is not supported', t => { | ||
mockTerminalLinkUnsupported(); | ||
t.is(linkifyCommit(MOCK_REPO_URL, MOCK_COMMIT_HASH), MOCK_COMMIT_HASH); | ||
}); | ||
|
||
test('linkifyCommitRange returns raw commitRange if url is not provided', t => { | ||
t.is(linkifyCommitRange(undefined, MOCK_COMMIT_RANGE), MOCK_COMMIT_RANGE); | ||
}); | ||
|
||
test('link commit', t => { | ||
t.is(linkifyCommit('https://github.com/unicorn/rainbow', '5063f8a'), ']8;;https://github.com/unicorn/rainbow/commit/5063f8a5063f8a]8;;'); | ||
test.serial('linkifyCommitRange returns raw commitRange if terminalLink is not supported', t => { | ||
mockTerminalLinkUnsupported(); | ||
t.is(linkifyCommitRange(MOCK_REPO_URL, MOCK_COMMIT_RANGE), MOCK_COMMIT_RANGE); | ||
}); |
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 |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import test from 'ava'; | ||
import test, {afterEach} from 'ava'; | ||
import sinon from 'sinon'; | ||
import execa from 'execa'; | ||
import {getTagVersionPrefix} from '../source/util'; | ||
|
||
const sandbox = sinon.createSandbox(); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
test('get tag prefix', async t => { | ||
t.is(await getTagVersionPrefix({yarn: false}), 'v'); | ||
t.is(await getTagVersionPrefix({yarn: true}), 'v'); | ||
}); | ||
|
||
test('no options passed', async t => { | ||
test.serial('no options passed', async t => { | ||
await t.throwsAsync(getTagVersionPrefix(), {message: 'Expected `options` to be of type `object` but received type `undefined`'}); | ||
await t.throwsAsync(getTagVersionPrefix({}), {message: 'Expected object `options` to have keys `["yarn"]`'}); | ||
}); | ||
|
||
test.serial('defaults to "v" when command fails', async t => { | ||
sandbox.stub(execa, 'stdout') | ||
.onFirstCall() | ||
.rejects(new Error()); | ||
t.is(await getTagVersionPrefix({yarn: true}), 'v'); | ||
}); |
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,33 @@ | ||
import * as fs from 'fs'; | ||
|
||
import test from 'ava'; | ||
import {withinTmpdir} from 'with-tmp'; | ||
|
||
import {readPkg} from '../source/util'; | ||
|
||
test.serial('readPkg throws error when no package.json is found', t => { | ||
t.plan(1); | ||
|
||
return withinTmpdir('readPkg-no-pkg', () => { | ||
t.throws(() => readPkg()); | ||
}); | ||
}); | ||
|
||
test.serial('readPkg gets package.json', t => { | ||
t.plan(1); | ||
|
||
const manifest = { | ||
version: '0.0.1', | ||
name: 'test-package', | ||
license: 'MIT' | ||
}; | ||
return withinTmpdir('readPkg-valid-pkg', () => { | ||
fs.writeFileSync('package.json', JSON.stringify(manifest)); | ||
const pkg = readPkg(); | ||
t.deepEqual(pkg, { | ||
...manifest, | ||
_id: 'test-package@0.0.1', | ||
readme: 'ERROR: No README data found!' | ||
}); | ||
}); | ||
}); |