@@ -6,7 +6,7 @@ const { gitInit, gitCommitAll, gitGetCommits } = require("../helpers/git");
66
77// Tests.
88describe ( "getCommitsFiltered()" , ( ) => {
9- test ( "Works correctly (no lastHead )" , async ( ) => {
9+ test ( "Works correctly (no lastRelease )" , async ( ) => {
1010 // Create Git repo with copy of Yarn workspaces fixture.
1111 const cwd = await gitInit ( ) ;
1212 writeFileSync ( `${ cwd } /AAA.txt` , "AAA" ) ;
@@ -24,7 +24,7 @@ describe("getCommitsFiltered()", () => {
2424 expect ( commits [ 0 ] . hash ) . toBe ( sha2 ) ;
2525 expect ( commits [ 0 ] . subject ) . toBe ( "Commit 2" ) ;
2626 } ) ;
27- test ( "Works correctly (with lastHead )" , async ( ) => {
27+ test ( "Works correctly (with lastRelease )" , async ( ) => {
2828 // Create Git repo with copy of Yarn workspaces fixture.
2929 const cwd = await gitInit ( ) ;
3030 writeFileSync ( `${ cwd } /AAA.txt` , "AAA" ) ;
@@ -40,6 +40,26 @@ describe("getCommitsFiltered()", () => {
4040 const commits = await getCommitsFiltered ( cwd , "bbb/" , sha3 ) ;
4141 expect ( commits . length ) . toBe ( 0 ) ;
4242 } ) ;
43+
44+ test ( "Works correctly (with lastRelease and nextRelease)" , async ( ) => {
45+ // Create Git repo with copy of Yarn workspaces fixture.
46+ const cwd = await gitInit ( ) ;
47+ writeFileSync ( `${ cwd } /AAA.txt` , "AAA" ) ;
48+ const sha1 = await gitCommitAll ( cwd , "Commit 1" ) ;
49+ mkdirSync ( `${ cwd } /bbb` ) ;
50+ writeFileSync ( `${ cwd } /bbb/BBB.txt` , "BBB" ) ;
51+ const sha2 = await gitCommitAll ( cwd , "Commit 2" ) ;
52+ writeFileSync ( `${ cwd } /bbb/BBB2.txt` , "BBB2" ) ;
53+ const sha3 = await gitCommitAll ( cwd , "Commit 3" ) ;
54+ mkdirSync ( `${ cwd } /ccc` ) ;
55+ writeFileSync ( `${ cwd } /ccc/CCC.txt` , "CCC" ) ;
56+ const sha4 = await gitCommitAll ( cwd , "Commit 4" ) ;
57+
58+ // Filter a single directory from sha2 (lastRelease) to sha3 (nextRelease)
59+ const commits = await getCommitsFiltered ( cwd , "bbb/" , sha2 , sha3 ) ;
60+ expect ( commits . length ) . toBe ( 1 ) ;
61+ expect ( commits [ 0 ] . hash ) . toBe ( sha3 ) ;
62+ } ) ;
4363 test ( "Works correctly (initial commit)" , async ( ) => {
4464 // Create Git repo with copy of Yarn workspaces fixture.
4565 const cwd = await gitInit ( ) ;
@@ -108,20 +128,37 @@ describe("getCommitsFiltered()", () => {
108128 message : expect . stringMatching ( "dir: Must be inside cwd" ) ,
109129 } ) ;
110130 } ) ;
111- test ( "TypeError if lastHead is not 40char alphanumeric Git SHA hash" , async ( ) => {
131+ test ( "TypeError if lastRelease is not 40char alphanumeric Git SHA hash" , async ( ) => {
112132 const cwd = tempy . directory ( ) ;
113133 mkdirSync ( join ( cwd , "dir" ) ) ;
114134 await expect ( getCommitsFiltered ( cwd , "dir" , false ) ) . rejects . toBeInstanceOf ( TypeError ) ;
115135 await expect ( getCommitsFiltered ( cwd , "dir" , false ) ) . rejects . toMatchObject ( {
116- message : expect . stringMatching ( "lastHead : Must be alphanumeric string with size 40 or empty" ) ,
136+ message : expect . stringMatching ( "lastRelease : Must be alphanumeric string with size 40 or empty" ) ,
117137 } ) ;
118138 await expect ( getCommitsFiltered ( cwd , "dir" , 123 ) ) . rejects . toBeInstanceOf ( TypeError ) ;
119139 await expect ( getCommitsFiltered ( cwd , "dir" , 123 ) ) . rejects . toMatchObject ( {
120- message : expect . stringMatching ( "lastHead : Must be alphanumeric string with size 40 or empty" ) ,
140+ message : expect . stringMatching ( "lastRelease : Must be alphanumeric string with size 40 or empty" ) ,
121141 } ) ;
122142 await expect ( getCommitsFiltered ( cwd , "dir" , "nottherightlength" ) ) . rejects . toBeInstanceOf ( TypeError ) ;
123143 await expect ( getCommitsFiltered ( cwd , "dir" , "nottherightlength" ) ) . rejects . toMatchObject ( {
124- message : expect . stringMatching ( "lastHead: Must be alphanumeric string with size 40 or empty" ) ,
144+ message : expect . stringMatching ( "lastRelease: Must be alphanumeric string with size 40 or empty" ) ,
145+ } ) ;
146+ } ) ;
147+
148+ test ( "TypeError if nextRelease is not 40char alphanumeric Git SHA hash" , async ( ) => {
149+ const cwd = tempy . directory ( ) ;
150+ mkdirSync ( join ( cwd , "dir" ) ) ;
151+ await expect ( getCommitsFiltered ( cwd , "dir" , undefined , false ) ) . rejects . toBeInstanceOf ( TypeError ) ;
152+ await expect ( getCommitsFiltered ( cwd , "dir" , undefined , false ) ) . rejects . toMatchObject ( {
153+ message : expect . stringMatching ( "nextRelease: Must be alphanumeric string with size 40 or empty" ) ,
154+ } ) ;
155+ await expect ( getCommitsFiltered ( cwd , "dir" , undefined , 123 ) ) . rejects . toBeInstanceOf ( TypeError ) ;
156+ await expect ( getCommitsFiltered ( cwd , "dir" , undefined , 123 ) ) . rejects . toMatchObject ( {
157+ message : expect . stringMatching ( "nextRelease: Must be alphanumeric string with size 40 or empty" ) ,
158+ } ) ;
159+ await expect ( getCommitsFiltered ( cwd , "dir" , undefined , "nottherightlength" ) ) . rejects . toBeInstanceOf ( TypeError ) ;
160+ await expect ( getCommitsFiltered ( cwd , "dir" , undefined , "nottherightlength" ) ) . rejects . toMatchObject ( {
161+ message : expect . stringMatching ( "nextRelease: Must be alphanumeric string with size 40 or empty" ) ,
125162 } ) ;
126163 } ) ;
127164} ) ;
0 commit comments