test: add Jest tests for validate-filepaths#20615
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a Jest test suite for the .github/script/validate-filepaths tooling intended to validate DMCA notice filepath conventions.
Changes:
- Added a new Jest test file covering year-folder detection and
YYYY-MM-DDdate substring matching in filenames. - Added basic “structure” scenarios combining the above checks.
Comments suppressed due to low confidence (3)
.github/script/validate-filepaths/tests/validate.test.js:36
isFilepathDateValidis redefined here rather than importing the real implementation fromutils/validators.js. That means changes to the actual validator won’t be caught by these tests. Importing the exported function will make this test suite a true regression check for the repo’s validation behavior.
function isFilepathDateValid(filepath) {
const filename = filepath.split("/").pop();
const dateStringInFilename = filename.match(/\d{4}-\d{2}-\d{2}/);
return dateStringInFilename !== null;
}
.github/script/validate-filepaths/tests/validate.test.js:67
- The helper functions are duplicated across describe blocks (
isFileInsideAYearFolderandisFilepathDateValidare declared twice). Once you switch to importing production code, this duplication will go away; otherwise, consider defining these helpers once at the top-level to avoid divergence between blocks.
function isFileInsideAYearFolder(filepath) {
return filepath.match(/^\d{4}/) !== null;
}
function isFilepathDateValid(filepath) {
const filename = filepath.split("/").pop();
const dateStringInFilename = filename.match(/\d{4}-\d{2}-\d{2}/);
return dateStringInFilename !== null;
}
.github/script/validate-filepaths/tests/validate.test.js:91
- The last two tests are labeled as “structure validation”, but they only assert
isFilepathDateValidis true (even when the year/month folders don’t match the filename date). If the intent is to validate structure, these should assert against the realisFileInCorrectFoldervalidator (fromutils/validators.js) so the tests actually catch mis-foldered notices.
test("incorrect structure with missing year folder", () => {
const invalidPath = "brand/2024-06-15-brand.markdown";
expect(isFileInsideAYearFolder(invalidPath)).toBe(false);
expect(isFilepathDateValid(invalidPath)).toBe(true);
});
test("incorrect structure with non-matching date in filename", () => {
const invalidPath = "2024/06/2023-06-15-brand.markdown";
expect(isFileInsideAYearFolder(invalidPath)).toBe(true);
expect(isFilepathDateValid(invalidPath)).toBe(true);
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Vsehffhf |
|
Thanks for the catches, @copilot and @vallesiocristian0-pixel — quick status: @copilot's inline review (about @vallesiocristian0-pixel's comment: noted — looks like spam/test input; no action needed on my side. If a maintainer prefers, I'm happy to fold the ESM Jest config into this PR directly instead of splitting — let me know. — sent via hermes-pr-bot (OAuth-authenticated). |
Adds Jest tests for the validate-filepaths script, covering file path validation logic for the YYYY-MM-DD-brand.markdown naming pattern.