forked from commitizen/cz-conventional-changelog
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from wizardzloy/feature/use-mainline-dependencies
feat(dependencies): Use official version of cz-conventional-changelog
- Loading branch information
Showing
4 changed files
with
87 additions
and
23 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
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,13 @@ | ||
const stubs = []; | ||
|
||
afterEach(() => { | ||
stubs.forEach((release) => release()); | ||
}); | ||
|
||
export default function stub(obj, method, fn) { | ||
const prev = obj[method]; | ||
obj[method] = fn; | ||
fn.__stubbed__ = true; | ||
stubs.push(() => obj[method] = prev); | ||
} | ||
|
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,57 @@ | ||
import assert from 'assert'; | ||
import shell from 'shelljs'; | ||
import PackageUtilities from 'lerna/lib/PackageUtilities'; | ||
|
||
import stub from './_stub'; | ||
import { prompter } from '../src/index'; | ||
|
||
|
||
const createMockCommitizenCli = (answers) => ({ | ||
prompt(questions) { | ||
let qs = questions; | ||
|
||
if (!Array.isArray(qs)) { | ||
qs = [qs]; | ||
} | ||
|
||
return Promise.resolve( | ||
qs.reduce((acc, question) => { | ||
acc[question.name] = answers[question.message]; | ||
|
||
return acc; | ||
}, {}) | ||
); | ||
} | ||
}); | ||
|
||
|
||
describe('cz-lerna-changelog', () => { | ||
it('should generate correct commit message from prompt answers', (done) => { | ||
stub(shell, 'exec', () => ({ stdout: '' })); | ||
stub(PackageUtilities, 'getPackages', () => ([{ | ||
name: 'test-package', | ||
location: 'packages/test-package' | ||
}])); | ||
|
||
const answers = { | ||
'Select the type of change that you\'re committing:': 'feat', | ||
'Denote the scope of this change ($location, $browser, $compile, etc.):\n': 'Fake Scope', | ||
'Write a short, imperative tense description of the change:\n': 'Test commit', | ||
'Provide a longer description of the change:\n': 'This commit is a fake one', | ||
'List any breaking changes or issues closed by this change:\n': '', | ||
'The packages that this commit has affected (0 detected)\n': ['test-package'] | ||
}; | ||
|
||
prompter(createMockCommitizenCli(answers), (commitMessage) => { | ||
try { | ||
assert.equal( | ||
commitMessage.trim(), | ||
'feat(Fake Scope): Test commit\n\naffects: test-package\n\nThis commit is a fake one' | ||
); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}) | ||
}); | ||
}); |