From 0cb11f3ba197a0c98a86b5fe7e656c3aa8139e7e Mon Sep 17 00:00:00 2001 From: cyphercodes Date: Tue, 28 Apr 2026 16:59:43 +0300 Subject: [PATCH 1/3] test: stabilize program tests locale --- tests/unit/test.program.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index e159aec3e8..c1fba06f9d 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -1,7 +1,7 @@ import path from 'path'; import fs from 'fs/promises'; -import { describe, it } from 'mocha'; +import { after, before, describe, it } from 'mocha'; import git from 'git-rev-sync'; import * as sinon from 'sinon'; import { assert } from 'chai'; @@ -29,7 +29,32 @@ import { const { spy } = sinon; +const localeEnvVars = ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']; +const stableLocale = 'en_US.UTF-8'; + describe('program.Program', () => { + let originalLocaleEnv; + + before(() => { + // yargs localizes some validation errors based on the environment locale. + // Keep tests that assert on these messages deterministic across systems. + originalLocaleEnv = {}; + localeEnvVars.forEach((name) => { + originalLocaleEnv[name] = process.env[name]; + process.env[name] = stableLocale; + }); + }); + + after(() => { + localeEnvVars.forEach((name) => { + if (originalLocaleEnv[name] === undefined) { + delete process.env[name]; + } else { + process.env[name] = originalLocaleEnv[name]; + } + }); + }); + function execProgram(program, options = {}) { const fakeProcess = createFakeProcess(); const absolutePackageDir = path.join( From 3e5027242891b765e66b4d3ea329284189ea7042 Mon Sep 17 00:00:00 2001 From: cyphercodes Date: Thu, 21 May 2026 20:45:19 +0300 Subject: [PATCH 2/3] test: only set LC_ALL for locale-stable program tests --- tests/unit/test.program.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index c1fba06f9d..a0c0774e3d 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -29,30 +29,24 @@ import { const { spy } = sinon; -const localeEnvVars = ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']; const stableLocale = 'en_US.UTF-8'; describe('program.Program', () => { - let originalLocaleEnv; + let originalLcAll; before(() => { // yargs localizes some validation errors based on the environment locale. // Keep tests that assert on these messages deterministic across systems. - originalLocaleEnv = {}; - localeEnvVars.forEach((name) => { - originalLocaleEnv[name] = process.env[name]; - process.env[name] = stableLocale; - }); + originalLcAll = process.env.LC_ALL; + process.env.LC_ALL = stableLocale; }); after(() => { - localeEnvVars.forEach((name) => { - if (originalLocaleEnv[name] === undefined) { - delete process.env[name]; - } else { - process.env[name] = originalLocaleEnv[name]; - } - }); + if (originalLcAll === undefined) { + delete process.env.LC_ALL; + } else { + process.env.LC_ALL = originalLcAll; + } }); function execProgram(program, options = {}) { From 6f8f71341cdda7dc5ac71b88d61469b5cf22c185 Mon Sep 17 00:00:00 2001 From: cyphercodes Date: Sun, 24 May 2026 03:26:23 +0300 Subject: [PATCH 3/3] test: inline locale test value --- tests/unit/test.program.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/test.program.js b/tests/unit/test.program.js index a0c0774e3d..15cb07fcbb 100644 --- a/tests/unit/test.program.js +++ b/tests/unit/test.program.js @@ -29,8 +29,6 @@ import { const { spy } = sinon; -const stableLocale = 'en_US.UTF-8'; - describe('program.Program', () => { let originalLcAll; @@ -38,7 +36,7 @@ describe('program.Program', () => { // yargs localizes some validation errors based on the environment locale. // Keep tests that assert on these messages deterministic across systems. originalLcAll = process.env.LC_ALL; - process.env.LC_ALL = stableLocale; + process.env.LC_ALL = 'en_US.UTF-8'; }); after(() => {