11import { promisify } from 'util' ;
2+ import path from 'path' ;
23import test from 'ava' ;
4+ import { outputJson } from 'fs-extra' ;
35import escape from 'escape-string-regexp' ;
6+ import tempy from 'tempy' ;
7+ import proxyquire from 'proxyquire' ;
8+ import { spy } from 'sinon' ;
49import { generateNotes } from '..' ;
510
611const cwd = process . cwd ( ) ;
7- const repositoryUrl = 'https://github.com/owner/repo' ;
12+ const host = 'https://github.com' ;
13+ const owner = 'owner' ;
14+ const repository = 'repo' ;
15+ const repositoryUrl = `${ host } /${ owner } /${ repository } ` ;
816const lastRelease = { gitTag : 'v1.0.0' } ;
917const nextRelease = { gitTag : 'v2.0.0' , version : '2.0.0' } ;
1018
@@ -25,6 +33,61 @@ test('Use "conventional-changelog-angular" by default', async t => {
2533 ) ;
2634} ) ;
2735
36+ test ( 'Set conventional-changelog-writer context' , async t => {
37+ const cwd = tempy . directory ( ) ;
38+ const writer = spy ( require ( 'conventional-changelog-writer' ) ) ;
39+ const { generateNotes} = proxyquire ( '..' , { 'conventional-changelog-writer' : writer } ) ;
40+
41+ const commits = [
42+ { hash : '111' , message : 'fix(scope1): First fix' } ,
43+ { hash : '222' , message : 'feat(scope2): Second feature' } ,
44+ ] ;
45+ await generateNotes ( { } , { cwd, options : { repositoryUrl} , lastRelease, nextRelease, commits} ) ;
46+
47+ t . deepEqual ( writer . args [ 0 ] [ 0 ] , {
48+ version : nextRelease . version ,
49+ host,
50+ owner,
51+ repository,
52+ previousTag : lastRelease . gitTag ,
53+ currentTag : nextRelease . gitTag ,
54+ linkCompare : lastRelease . gitTag ,
55+ issue : 'issues' ,
56+ commit : 'commit' ,
57+ packageData : undefined ,
58+ linkReferences : undefined ,
59+ } ) ;
60+ } ) ;
61+
62+ test ( 'Set conventional-changelog-writer context with package.json' , async t => {
63+ const cwd = tempy . directory ( ) ;
64+ const writer = spy ( require ( 'conventional-changelog-writer' ) ) ;
65+ const { generateNotes} = proxyquire ( '..' , { 'conventional-changelog-writer' : writer } ) ;
66+
67+ const packageData = { name : 'package' , version : '0.0.0' } ;
68+ await outputJson ( path . resolve ( cwd , 'package.json' ) , packageData ) ;
69+
70+ const commits = [
71+ { hash : '111' , message : 'fix(scope1): First fix' } ,
72+ { hash : '222' , message : 'feat(scope2): Second feature' } ,
73+ ] ;
74+ await generateNotes ( { } , { cwd, options : { repositoryUrl} , lastRelease, nextRelease, commits} ) ;
75+
76+ t . deepEqual ( writer . args [ 0 ] [ 0 ] , {
77+ version : nextRelease . version ,
78+ host,
79+ owner,
80+ repository,
81+ previousTag : lastRelease . gitTag ,
82+ currentTag : nextRelease . gitTag ,
83+ linkCompare : lastRelease . gitTag ,
84+ issue : 'issues' ,
85+ commit : 'commit' ,
86+ packageData,
87+ linkReferences : undefined ,
88+ } ) ;
89+ } ) ;
90+
2891test ( 'Accept a "preset" option' , async t => {
2992 const commits = [
3093 { hash : '111' , message : 'Fix: First fix (fixes #123)' } ,
0 commit comments