|
1 | 1 | import assert from "node:assert/strict"; |
| 2 | +import * as fs from "node:fs"; |
| 3 | +import * as path from "node:path"; |
2 | 4 | import { describe, it } from "node:test"; |
3 | 5 |
|
4 | | -import { withTmpFile } from "../../src/util"; |
| 6 | +import { withTmpDir, withTmpFile } from "../../src/util"; |
5 | 7 |
|
6 | 8 | import { |
7 | 9 | hasValidChangenoteCategory, |
| 10 | + isValidAllChangenoteFiles, |
8 | 11 | isValidChangenoteContent, |
9 | 12 | isValidChangenoteFile, |
10 | 13 | isValidChangenoteFilename, |
@@ -150,6 +153,10 @@ await describe("isValidChangenoteFile", async () => { |
150 | 153 | ); |
151 | 154 | }); |
152 | 155 |
|
| 156 | + await it("rejects a non-existent path", async () => { |
| 157 | + assert.equal(isValidChangenoteFile("non-existent-file.md"), false); |
| 158 | + }); |
| 159 | + |
153 | 160 | await it("rejects invalid filename", async () => { |
154 | 161 | await withTmpFile( |
155 | 162 | "fix-bug.md", |
@@ -180,3 +187,39 @@ await describe("isValidChangenoteFile", async () => { |
180 | 187 | ); |
181 | 188 | }); |
182 | 189 | }); |
| 190 | + |
| 191 | +await describe("isValidAllChangenoteFiles", async () => { |
| 192 | + await it("accepts list of file paths of valid change-notes", async () => { |
| 193 | + await withTmpDir(async (tmpDir) => { |
| 194 | + const fileName1 = path.join(tmpDir, "2026-01-01-fix-bug.md"); |
| 195 | + const fileName2 = path.join(tmpDir, "2026-01-02-add-feature.md"); |
| 196 | + fs.writeFileSync(fileName1, "---\ncategory: fix\n---\n- Fixed a bug\n"); |
| 197 | + fs.writeFileSync( |
| 198 | + fileName2, |
| 199 | + "---\ncategory: feature\n---\n- Added a feature\n", |
| 200 | + ); |
| 201 | + assert.equal(isValidAllChangenoteFiles([fileName1, fileName2]), true); |
| 202 | + }); |
| 203 | + }); |
| 204 | + |
| 205 | + await it("accepts the empty list", async () => { |
| 206 | + assert.equal(isValidAllChangenoteFiles([]), true); |
| 207 | + }); |
| 208 | + |
| 209 | + await it("accepts list of .gitkeep", async () => { |
| 210 | + assert.equal(isValidAllChangenoteFiles([".gitkeep"]), true); |
| 211 | + }); |
| 212 | + |
| 213 | + await it("rejects list containing a file path to an invalid change-note", async () => { |
| 214 | + await withTmpDir(async (tmpDir) => { |
| 215 | + const fileName1 = path.join(tmpDir, "2026-01-01-fix-bug.md"); |
| 216 | + const fileName2 = path.join(tmpDir, "2026-01-02-wrong-category.md"); |
| 217 | + fs.writeFileSync(fileName1, "---\ncategory: fix\n---\n- Fixed a bug\n"); |
| 218 | + fs.writeFileSync( |
| 219 | + fileName2, |
| 220 | + "---\ncategory: foobar\n---\n- Added a feature\n", |
| 221 | + ); |
| 222 | + assert.equal(isValidAllChangenoteFiles([fileName1, fileName2]), false); |
| 223 | + }); |
| 224 | + }); |
| 225 | +}); |
0 commit comments