From 4aa38bdd5ffb18ab12c0938de1cd7f1dcafe4cf0 Mon Sep 17 00:00:00 2001 From: TheConfax <33484856+TheConfax@users.noreply.github.com> Date: Tue, 21 Jul 2026 10:32:55 +0200 Subject: [PATCH] [ChromeWebStoreUsers] Fix 1M+ counts rendering as "12000,000" not "12M" (#12028) * [ChromeWebStoreUsers] Fix 1M+ counts rendering as "12000,000" not "12M" The Chrome Web Store reports counts with thousands separators, e.g. "12,000,000". The handler stripped them with a string argument to String.prototype.replace, which only removes the first match, leaving "12000,000". metric() then coerced that to NaN and printed it verbatim. Counts below 1M have a single separator, so they were unaffected. Use a global regex so every separator is removed, and extract the logic into a testable static transform() (mirroring ChromeWebStoreSize) with deterministic unit tests for the millions case. * [ChromeWebStoreUsers] Address review: use replaceAll, drop redundant metric test --- .../chrome-web-store-users.service.js | 6 +++++- .../chrome-web-store-users.spec.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 services/chrome-web-store/chrome-web-store-users.spec.js diff --git a/services/chrome-web-store/chrome-web-store-users.service.js b/services/chrome-web-store/chrome-web-store-users.service.js index da35e20ddc..2f12709c8f 100644 --- a/services/chrome-web-store/chrome-web-store-users.service.js +++ b/services/chrome-web-store/chrome-web-store-users.service.js @@ -23,6 +23,10 @@ class ChromeWebStoreUsers extends BaseChromeWebStoreService { static defaultBadgeData = { label: 'users' } + static transform(users) { + return String(users.replaceAll(',', '')) + } + async handle({ storeId }) { const chromeWebStore = await this.fetch({ storeId }) const downloads = chromeWebStore.users() @@ -30,7 +34,7 @@ class ChromeWebStoreUsers extends BaseChromeWebStoreService { throw new NotFound({ prettyMessage: 'not found' }) } return renderDownloadsBadge({ - downloads: String(downloads.replace(',', '')), + downloads: this.constructor.transform(downloads), }) } } diff --git a/services/chrome-web-store/chrome-web-store-users.spec.js b/services/chrome-web-store/chrome-web-store-users.spec.js new file mode 100644 index 0000000000..4effb4e811 --- /dev/null +++ b/services/chrome-web-store/chrome-web-store-users.spec.js @@ -0,0 +1,15 @@ +import { test, given } from 'sazerac' +import { ChromeWebStoreUsers } from './chrome-web-store-users.service.js' + +describe('ChromeWebStoreUsers', function () { + describe('transform', function () { + it('strips every thousands separator, not just the first', function () { + test(ChromeWebStoreUsers.transform, () => { + given('8,000').expect('8000') + given('500,000').expect('500000') + given('3,000,000').expect('3000000') + given('12,000,000').expect('12000000') + }) + }) + }) +})