Skip to content

test: split validator and sanitizer tests into per-function files#2698

Open
WikiRik wants to merge 95 commits intomasterfrom
WikiRik/split-tests-ai
Open

test: split validator and sanitizer tests into per-function files#2698
WikiRik wants to merge 95 commits intomasterfrom
WikiRik/split-tests-ai

Conversation

@WikiRik
Copy link
Copy Markdown
Member

@WikiRik WikiRik commented Apr 15, 2026

Summary

  • split the remaining validator tests from test/validators.test.js into per-validator files under test/validators/
  • split the sanitizer tests from test/sanitizers.test.js into per-sanitizer files under test/sanitizers/ and extend test/testFunctions.js so sanitizers can use the shared helper too
  • most of the extraction work was done with local helper scripts and with the use of AI, with manual fixes applied where mixed blocks or lint issues needed small follow-up cleanup

Validation

  • ran npm test -- --grep "<name>" for each split validator and sanitizer
  • each run went through pretest, so build and lint also ran during validation

Background

  • I want to work on doing some upgrades for the next major release. This is the first major PR for it

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e36b279) to head (4bfcb36).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2698   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2586      2586           
  Branches       656       656           
=========================================
  Hits          2586      2586           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WikiRik WikiRik marked this pull request as ready for review April 15, 2026 21:26
@WikiRik WikiRik requested review from profnandaa and rubiin April 15, 2026 21:26
@profnandaa profnandaa requested a review from Copilot April 16, 2026 03:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the test suite by splitting validator and sanitizer tests into per-function files, and extends the shared test/testFunctions.js helper to support sanitizer expectations.

Changes:

  • Added per-validator test files under test/validators/.
  • Added per-sanitizer test files under test/sanitizers/.
  • Updated test/testFunctions.js to support sanitizer + expect-style assertions.

Reviewed changes

Copilot reviewed 95 out of 97 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/testFunctions.js Generalized helper to support both validator and sanitizer, and added expect assertions.
test/validators/contains.test.js Added dedicated tests for contains.
test/validators/equals.test.js Added dedicated tests for equals.
test/validators/matches.test.js Added dedicated tests for matches.
test/validators/isWhitelisted.test.js Added dedicated tests for isWhitelisted.
test/validators/isVariableWidth.test.js Added dedicated tests for isVariableWidth.
test/validators/isUppercase.test.js Added dedicated tests for isUppercase.
test/validators/isUUID.test.js Added dedicated tests for isUUID.
test/validators/isULID.test.js Added dedicated tests for isULID.
test/validators/isTime.test.js Added dedicated tests for isTime.
test/validators/isSurrogatePair.test.js Added dedicated tests for isSurrogatePair.
test/validators/isStrongPassword.test.js Added dedicated tests for isStrongPassword (validator).
test/validators/isSlug.test.js Added dedicated tests for isSlug.
test/validators/isSemVer.test.js Added dedicated tests for isSemVer.
test/validators/isRgbColor.test.js Added dedicated tests for isRgbColor.
test/validators/isRFC3339.test.js Added dedicated tests for isRFC3339.
test/validators/isPostalCode.test.js Added dedicated tests for isPostalCode.
test/validators/isPort.test.js Added dedicated tests for isPort.
test/validators/isOctal.test.js Added dedicated tests for isOctal.
test/validators/isNumeric.test.js Added dedicated tests for isNumeric.
test/validators/isMultibyte.test.js Added dedicated tests for isMultibyte.
test/validators/isMongoId.test.js Added dedicated tests for isMongoId.
test/validators/isMimeType.test.js Added dedicated tests for isMimeType.
test/validators/isMailtoURI.test.js Added dedicated tests for isMailtoURI.
test/validators/isMagnetURI.test.js Added dedicated tests for isMagnetURI.
test/validators/isMD5.test.js Added dedicated tests for isMD5.
test/validators/isMACAddress.test.js Added dedicated tests for isMACAddress.
test/validators/isLuhnNumber.test.js Added dedicated tests for isLuhnNumber.
test/validators/isLowercase.test.js Added dedicated tests for isLowercase.
test/validators/isLocale.test.js Added dedicated tests for isLocale.
test/validators/isLicensePlate.test.js Added dedicated tests for isLicensePlate.
test/validators/isLatLong.test.js Added dedicated tests for isLatLong.
test/validators/isJWT.test.js Added dedicated tests for isJWT.
test/validators/isJSON.test.js Added dedicated tests for isJSON.
test/validators/isInt.test.js Added dedicated tests for isInt.
test/validators/isIn.test.js Added dedicated tests for isIn.
test/validators/isIdentityCard.test.js Added dedicated tests for isIdentityCard.
test/validators/isISSN.test.js Added dedicated tests for isISSN.
test/validators/isISRC.test.js Added dedicated tests for isISRC.
test/validators/isISO8601.test.js Added dedicated tests for isISO8601.
test/validators/isISO6391.test.js Added dedicated tests for isISO6391.
test/validators/isISO6346.test.js Added dedicated tests for isISO6346.
test/validators/isISO4217.test.js Added dedicated tests for isISO4217.
test/validators/isISO31661Numeric.test.js Added dedicated tests for isISO31661Numeric.
test/validators/isISO15924.test.js Added dedicated tests for isISO15924.
test/validators/isISIN.test.js Added dedicated tests for isISIN.
test/validators/isIPRange.test.js Added dedicated tests for isIPRange.
test/validators/isIMEI.test.js Added dedicated tests for isIMEI.
test/validators/isIBAN.test.js Added dedicated tests for isIBAN.
test/validators/isHexadecimal.test.js Added dedicated tests for isHexadecimal.
test/validators/isHexColor.test.js Added dedicated tests for isHexColor.
test/validators/isHash.test.js Added dedicated tests for isHash.
test/validators/isHalfWidth.test.js Added dedicated tests for isHalfWidth.
test/validators/isHSL.test.js Added dedicated tests for isHSL.
test/validators/isFullWidth.test.js Added dedicated tests for isFullWidth.
test/validators/isFreightContainerID.test.js Added dedicated tests for isFreightContainerID.
test/validators/isFloat.test.js Added dedicated tests for isFloat.
test/validators/isFQDN.test.js Expanded/organized dedicated tests for isFQDN.
test/validators/isEthereumAddress.test.js Added dedicated tests for isEthereumAddress.
test/validators/isEmpty.test.js Added dedicated tests for isEmpty.
test/validators/isEmail.test.js Added dedicated tests for isEmail.
test/validators/isEAN.test.js Added dedicated tests for isEAN.
test/validators/isDivisibleBy.test.js Added dedicated tests for isDivisibleBy.
test/validators/isDecimal.test.js Added dedicated tests for isDecimal.
test/validators/isDate.test.js Added dedicated tests for isDate.
test/validators/isDataURI.test.js Added dedicated tests for isDataURI.
test/validators/isCreditCard.test.js Added dedicated tests for isCreditCard.
test/validators/isByteLength.test.js Added dedicated tests for isByteLength.
test/validators/isBtcAddress.test.js Added dedicated tests for isBtcAddress.
test/validators/isBoolean.test.js Added dedicated tests for isBoolean.
test/validators/isBase58.test.js Added dedicated tests for isBase58.
test/validators/isBase32.test.js Added dedicated tests for isBase32.
test/validators/isBIC.test.js Added dedicated tests for isBIC.
test/validators/isAscii.test.js Added dedicated tests for isAscii.
test/validators/isAbaRouting.test.js Added dedicated tests for isAbaRouting.
test/sanitizers/blacklist.test.js Added dedicated tests for blacklist sanitizer.
test/sanitizers/escape.test.js Added dedicated tests for escape sanitizer.
test/sanitizers/isStrongPassword.test.js Added dedicated tests for isStrongPassword sanitizer behavior (scoring + default options).
test/sanitizers/ltrim.test.js Added dedicated tests for ltrim sanitizer.
test/sanitizers/normalizeEmail.test.js Updated to use shared testFunctions helper for normalizeEmail.
test/sanitizers/rtrim.test.js Added dedicated tests for rtrim sanitizer.
test/sanitizers/stripLow.test.js Added dedicated tests for stripLow sanitizer.
test/sanitizers/toBoolean.test.js Added dedicated tests for toBoolean sanitizer.
test/sanitizers/toFloat.test.js Added dedicated tests for toFloat sanitizer.
test/sanitizers/toInt.test.js Added dedicated tests for toInt sanitizer.
test/sanitizers/trim.test.js Added dedicated tests for trim sanitizer.
test/sanitizers/unescape.test.js Added dedicated tests for unescape sanitizer.
test/sanitizers/whitelist.test.js Added dedicated tests for whitelist sanitizer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/testFunctions.js
export default function test(options) {
const args = options.args || [];
const method = options.validator || options.sanitizer;

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test() now derives method from options.validator || options.sanitizer, but if neither is provided (or the name is misspelled), the failure will be a confusing validator[method] is not a function TypeError. Consider validating that method is set and that validator[method] is a function, and throw a clear error indicating the required option(s).

Suggested change
if (!method) {
throw new Error('test() requires either "validator" or "sanitizer" option');
}
if (typeof validator[method] !== 'function') {
throw new Error(format(
'test() received invalid validator/sanitizer "%s"; expected a function name exported by validator',
method
));
}

Copilot uses AI. Check for mistakes.
import test from '../testFunctions';

describe('isISO4217', () => {
it('should validate ISO 4217 corrency codes', () => {
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in test description: "corrency" should be "currency".

Copilot uses AI. Check for mistakes.
],
});

// test where include percent is true explciitly
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: "explciitly" should be "explicitly".

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants