Skip to content

test(eslint-config): add tests for no-direct-currency-formatting rule#3964

Merged
nima-ct merged 3 commits intoFEC-753-no-direct-currency-formatting-rulefrom
FEC-753-no-direct-currency-formatting-rule-tests
Apr 8, 2026
Merged

test(eslint-config): add tests for no-direct-currency-formatting rule#3964
nima-ct merged 3 commits intoFEC-753-no-direct-currency-formatting-rulefrom
FEC-753-no-direct-currency-formatting-rule-tests

Conversation

@misama-ct
Copy link
Copy Markdown
Contributor

@misama-ct misama-ct commented Apr 8, 2026

Summary

  • Test infrastructure: Added an eslint-rules Jest project to jest.test.config.js using the node environment, since ESLint's RuleTester requires structuredClone and has no DOM dependencies — incompatible with the existing jsdom/MC app preset setup. The main test suite excludes the rules directory, so there's no interference. Future rule tests under packages/eslint-config-mc-app/rules/ are picked up automatically.
  • Test coverage: Added 48 test cases for the no-direct-currency-formatting rule covering intl.formatNumber, destructured/aliased variants (including formatCurrency), Intl.NumberFormat, variable-resolved options, spread elements (including nested), currency in first argument, <FormattedNumber /> (named, aliased, namespace, and require imports), and allowlisted wrapper paths (Unix + Windows).
  • Documents a bug: 5 tests are currently expected to fail — they prove that <FormattedNumber /> imported from react-intl is flagged even for non-currency usage (style="percent", style="decimal", no style prop — via both named and namespace imports). The rule's JSXOpeningElement handler needs to inspect JSX attributes for currency props, similar to how the CallExpression handler already checks arguments.

CI note

All CI failures (including starter template jobs) are caused by the same 5 intentionally-failing tests. No infrastructure or unrelated tests are broken.

Test plan

  • pnpm jest --config jest.test.config.js --testPathPatterns='eslint-config-mc-app/rules' runs the rule tests (43 pass, 5 fail on the known bug)
  • pnpm test runs both the main suite and the rule tests without interference
  • Once the <FormattedNumber /> false-positive bug is fixed in the rule, all 48 tests should pass

Use Jest projects in jest.test.config.js so custom ESLint rule tests
run in a node environment alongside the existing jsdom test suite.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mc-app-kit-playground Ready Ready Preview, Comment Apr 8, 2026 10:24am
merchant-center-application-kit-components-playground Ready Ready Preview, Comment Apr 8, 2026 10:24am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 8, 2026

⚠️ No Changeset found

Latest commit: 25248f5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Covers intl.formatNumber, destructured/aliased variants, Intl.NumberFormat,
variable-resolved options, spread elements, and <FormattedNumber /> from
react-intl. Includes cases proving the false-positive bug where non-currency
<FormattedNumber /> usage (percent, decimal, no style) is incorrectly flagged.
The eslint-rules project inherits Babel config resolution which loads
babel-plugin-istanbul, conflicting with Jest's own coverage instrumentation.
Setting transform: {} avoids this since the rule files are plain CommonJS.
@nima-ct nima-ct merged commit 25248f5 into FEC-753-no-direct-currency-formatting-rule Apr 8, 2026
12 of 18 checks passed
@nima-ct nima-ct deleted the FEC-753-no-direct-currency-formatting-rule-tests branch April 8, 2026 10:51
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