@@ -6,7 +6,7 @@ import { withTmpFile } from "../../src/util";
66import {
77 hasValidChangenoteCategory ,
88 isValidChangenoteContent ,
9- isValidChangenoteFile ,
9+ isValidChangenoteFileOrDir ,
1010 isValidChangenoteFilename ,
1111 VALID_CHANGE_NOTE_CATEGORIES ,
1212} from "./validate.mjs" ;
@@ -139,23 +139,55 @@ await describe("hasValidChangenoteCategory", async () => {
139139 } ) ;
140140} ) ;
141141
142- await describe ( "isValidChangenoteFile " , async ( ) => {
142+ await describe ( "isValidChangenoteFileOrDir " , async ( ) => {
143143 await it ( "accepts a valid change-note file" , async ( ) => {
144144 await withTmpFile (
145145 "2026-01-01-fix-bug.md" ,
146146 "---\ncategory: fix\n---\n- Fixed a bug\n" ,
147147 ( filePath ) => {
148- assert . equal ( isValidChangenoteFile ( filePath ) , true ) ;
148+ assert . equal ( isValidChangenoteFileOrDir ( filePath ) , true ) ;
149149 } ,
150150 ) ;
151151 } ) ;
152152
153+ await it ( "accepts a directory of valid change-note files" , async ( ) => {
154+ await withTmpDir ( async ( tmpDir ) => {
155+ fs . writeFileSync (
156+ path . join ( tmpDir , "2026-01-01-fix-bug.md" ) ,
157+ "---\ncategory: fix\n---\n- Fixed a bug\n" ,
158+ ) ;
159+ fs . writeFileSync (
160+ path . join ( tmpDir , "2026-01-02-add-feature.md" ) ,
161+ "---\ncategory: feature\n---\n- Added a feature\n" ,
162+ ) ;
163+ assert . equal ( isValidChangenoteFileOrDir ( tmpDir ) , true ) ;
164+ } ) ;
165+ } ) ;
166+
167+ await it ( "accepts an empty directory" , async ( ) => {
168+ await withTmpDir ( async ( tmpDir ) => {
169+ assert . equal ( isValidChangenoteFileOrDir ( tmpDir ) , true ) ;
170+ } ) ;
171+ } ) ;
172+
173+ await it ( "accepts a directory of .gitkeep only" , async ( ) => {
174+ await withTmpFile ( ".gitkeep" , "" , async ( filePath ) => {
175+ const dirPath = path . dirname ( filePath ) ;
176+ assert . equal ( isValidChangenoteFileOrDir ( dirPath ) , true ) ;
177+ } ) ;
178+ } ) ;
179+
180+ await it ( "rejects a non-existent path" , async ( ) => {
181+ assert . equal ( isValidChangenoteFileOrDir ( "non-existent-file.md" ) , false ) ;
182+ assert . equal ( isValidChangenoteFileOrDir ( "this-dir-does-not-exist" ) , false ) ;
183+ } ) ;
184+
153185 await it ( "rejects invalid filename" , async ( ) => {
154186 await withTmpFile (
155187 "fix-bug.md" ,
156188 "---\ncategory: fix\n---\n- Fixed a bug\n" ,
157189 ( filePath ) => {
158- assert . equal ( isValidChangenoteFile ( filePath ) , false ) ;
190+ assert . equal ( isValidChangenoteFileOrDir ( filePath ) , false ) ;
159191 } ,
160192 ) ;
161193 } ) ;
@@ -165,7 +197,7 @@ await describe("isValidChangenoteFile", async () => {
165197 "2026-01-01-fix-bug.md" ,
166198 "- Fixed a bug\n" ,
167199 ( filePath ) => {
168- assert . equal ( isValidChangenoteFile ( filePath ) , false ) ;
200+ assert . equal ( isValidChangenoteFileOrDir ( filePath ) , false ) ;
169201 } ,
170202 ) ;
171203 } ) ;
@@ -175,8 +207,22 @@ await describe("isValidChangenoteFile", async () => {
175207 "2026-01-01-fix-bug.md" ,
176208 "---\ncategory: fix\n---\n* Fixed a bug\n" ,
177209 ( filePath ) => {
178- assert . equal ( isValidChangenoteFile ( filePath ) , false ) ;
210+ assert . equal ( isValidChangenoteFileOrDir ( filePath ) , false ) ;
179211 } ,
180212 ) ;
181213 } ) ;
214+
215+ await it ( "rejects directory with one invalid change-note file" , async ( ) => {
216+ await withTmpDir ( async ( tmpDir ) => {
217+ fs . writeFileSync (
218+ path . join ( tmpDir , "2026-01-01-fix-bug.md" ) ,
219+ "---\ncategory: fix\n---\n- Fixed a bug\n" ,
220+ ) ;
221+ fs . writeFileSync (
222+ path . join ( tmpDir , "2026-01-02-wrong-category.md" ) ,
223+ "---\ncategory: foobar\n---\n- Added a feature\n" ,
224+ ) ;
225+ assert . equal ( isValidChangenoteFileOrDir ( tmpDir ) , false ) ;
226+ } ) ;
227+ } ) ;
182228} ) ;
0 commit comments