1
1
import { promisify } from 'util' ;
2
+ import path from 'path' ;
2
3
import test from 'ava' ;
4
+ import { outputJson } from 'fs-extra' ;
3
5
import escape from 'escape-string-regexp' ;
6
+ import tempy from 'tempy' ;
7
+ import proxyquire from 'proxyquire' ;
8
+ import { spy } from 'sinon' ;
4
9
import { generateNotes } from '..' ;
5
10
6
11
const 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 } ` ;
8
16
const lastRelease = { gitTag : 'v1.0.0' } ;
9
17
const nextRelease = { gitTag : 'v2.0.0' , version : '2.0.0' } ;
10
18
@@ -25,6 +33,61 @@ test('Use "conventional-changelog-angular" by default', async t => {
25
33
) ;
26
34
} ) ;
27
35
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
+
28
91
test ( 'Accept a "preset" option' , async t => {
29
92
const commits = [
30
93
{ hash : '111' , message : 'Fix: First fix (fixes #123)' } ,
0 commit comments