@@ -7,8 +7,9 @@ import { withTmpDir, withTmpFile } from "../../src/util"; |
7 | 7 |
|
8 | 8 | import { |
9 | 9 | hasValidChangenoteCategory, |
| 10 | + isValidAllChangenoteFiles, |
10 | 11 | isValidChangenoteContent, |
11 | | - isValidChangenoteFileOrDir, |
| 12 | + isValidChangenoteFile, |
12 | 13 | isValidChangenoteFilename, |
13 | 14 | VALID_CHANGE_NOTE_CATEGORIES, |
14 | 15 | } from "./validate.mjs"; |
@@ -141,90 +142,58 @@ await describe("hasValidChangenoteCategory", async () => { |
141 | 142 | }); |
142 | 143 | }); |
143 | 144 |
|
144 | | -await describe("isValidChangenoteFileOrDir", async () => { |
| 145 | +await describe("isValidChangenoteFile", async () => { |
145 | 146 | await it("accepts a valid change-note file", async () => { |
146 | 147 | await withTmpFile( |
147 | 148 | "2026-01-01-fix-bug.md", |
148 | 149 | "---\ncategory: fix\n---\n- Fixed a bug\n", |
149 | 150 | (filePath) => { |
150 | | - assert.equal(isValidChangenoteFileOrDir(filePath), true); |
| 151 | + assert.equal(isValidChangenoteFile(filePath), true); |
151 | 152 | }, |
152 | 153 | ); |
153 | 154 | }); |
154 | 155 |
|
| 156 | + await it("rejects a non-existent path", async () => { |
| 157 | + assert.equal(isValidChangenoteFile("non-existent-file.md"), false); |
| 158 | + }); |
| 159 | + |
| 160 | + await it("rejects invalid filename", async () => { |
| 161 | + assert.equal(isValidChangenoteFile("fix-bug.md"), false); |
| 162 | + }); |
| 163 | +}); |
| 164 | + |
| 165 | +await describe("isValidAllChangenoteFiles", async () => { |
155 | 166 | await it("accepts a directory of valid change-note files", async () => { |
156 | 167 | await withTmpDir(async (tmpDir) => { |
| 168 | + const fileName1 = path.join(tmpDir, "2026-01-01-fix-bug.md"); |
| 169 | + const fileName2 = path.join(tmpDir, "2026-01-02-add-feature.md"); |
| 170 | + fs.writeFileSync(fileName1, "---\ncategory: fix\n---\n- Fixed a bug\n"); |
157 | 171 | fs.writeFileSync( |
158 | | - path.join(tmpDir, "2026-01-01-fix-bug.md"), |
159 | | - "---\ncategory: fix\n---\n- Fixed a bug\n", |
160 | | - ); |
161 | | - fs.writeFileSync( |
162 | | - path.join(tmpDir, "2026-01-02-add-feature.md"), |
| 172 | + fileName2, |
163 | 173 | "---\ncategory: feature\n---\n- Added a feature\n", |
164 | 174 | ); |
165 | | - assert.equal(isValidChangenoteFileOrDir(tmpDir), true); |
166 | | - }); |
167 | | - }); |
168 | | - |
169 | | - await it("accepts an empty directory", async () => { |
170 | | - await withTmpDir(async (tmpDir) => { |
171 | | - assert.equal(isValidChangenoteFileOrDir(tmpDir), true); |
| 175 | + assert.equal(isValidAllChangenoteFiles([fileName1, fileName2]), true); |
172 | 176 | }); |
173 | 177 | }); |
174 | 178 |
|
175 | | - await it("accepts a directory of .gitkeep only", async () => { |
176 | | - await withTmpFile(".gitkeep", "", async (filePath) => { |
177 | | - const dirPath = path.dirname(filePath); |
178 | | - assert.equal(isValidChangenoteFileOrDir(dirPath), true); |
179 | | - }); |
| 179 | + await it("accepts an empty list", async () => { |
| 180 | + assert.equal(isValidAllChangenoteFiles([]), true); |
180 | 181 | }); |
181 | 182 |
|
182 | | - await it("rejects a non-existent path", async () => { |
183 | | - assert.equal(isValidChangenoteFileOrDir("non-existent-file.md"), false); |
184 | | - assert.equal(isValidChangenoteFileOrDir("this-dir-does-not-exist"), false); |
| 183 | + await it("accepts a list of .gitkeep only", async () => { |
| 184 | + assert.equal(isValidAllChangenoteFiles([".gitkeep"]), true); |
185 | 185 | }); |
186 | 186 |
|
187 | | - await it("rejects invalid filename", async () => { |
188 | | - await withTmpFile( |
189 | | - "fix-bug.md", |
190 | | - "---\ncategory: fix\n---\n- Fixed a bug\n", |
191 | | - (filePath) => { |
192 | | - assert.equal(isValidChangenoteFileOrDir(filePath), false); |
193 | | - }, |
194 | | - ); |
195 | | - }); |
196 | | - |
197 | | - await it("rejects missing frontmatter", async () => { |
198 | | - await withTmpFile( |
199 | | - "2026-01-01-fix-bug.md", |
200 | | - "- Fixed a bug\n", |
201 | | - (filePath) => { |
202 | | - assert.equal(isValidChangenoteFileOrDir(filePath), false); |
203 | | - }, |
204 | | - ); |
205 | | - }); |
206 | | - |
207 | | - await it("rejects invalid Markdown", async () => { |
208 | | - await withTmpFile( |
209 | | - "2026-01-01-fix-bug.md", |
210 | | - "---\ncategory: fix\n---\n* Fixed a bug\n", |
211 | | - (filePath) => { |
212 | | - assert.equal(isValidChangenoteFileOrDir(filePath), false); |
213 | | - }, |
214 | | - ); |
215 | | - }); |
216 | | - |
217 | | - await it("rejects directory with one invalid change-note file", async () => { |
| 187 | + await it("rejects directory with an invalid change-note file", async () => { |
218 | 188 | await withTmpDir(async (tmpDir) => { |
| 189 | + const fileName1 = path.join(tmpDir, "2026-01-01-fix-bug.md"); |
| 190 | + const fileName2 = path.join(tmpDir, "2026-01-02-wrong-category.md"); |
| 191 | + fs.writeFileSync(fileName1, "---\ncategory: fix\n---\n- Fixed a bug\n"); |
219 | 192 | fs.writeFileSync( |
220 | | - path.join(tmpDir, "2026-01-01-fix-bug.md"), |
221 | | - "---\ncategory: fix\n---\n- Fixed a bug\n", |
222 | | - ); |
223 | | - fs.writeFileSync( |
224 | | - path.join(tmpDir, "2026-01-02-wrong-category.md"), |
| 193 | + fileName2, |
225 | 194 | "---\ncategory: foobar\n---\n- Added a feature\n", |
226 | 195 | ); |
227 | | - assert.equal(isValidChangenoteFileOrDir(tmpDir), false); |
| 196 | + assert.equal(isValidAllChangenoteFiles([fileName1, fileName2]), false); |
228 | 197 | }); |
229 | 198 | }); |
230 | 199 | }); |