Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit fa99728

Browse files
vincepmartinachingbrain
authored andcommitted
test: change locale to en_US.UTF-8 during CLI testing (#2501)
Set locale to en_US.UTF-8 during CLI testing to stop tests from failing in non English locales. License: MIT Signed-off-by: Vincent Martin <[email protected]>
1 parent 1dca93d commit fa99728

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/utils/on-and-off.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const df = DaemonFactory.create({
1212
IpfsClient: require('ipfs-http-client')
1313
})
1414
const path = require('path')
15+
const origLocale = process.env.LC_ALL
1516

1617
function off (tests) {
1718
describe('daemon off (directly to core)', function () {
@@ -22,6 +23,7 @@ function off (tests) {
2223
let repoPath
2324

2425
before(function () {
26+
setLocaleToEnglish()
2527
this.timeout(60 * 1000)
2628

2729
repoPath = os.tmpdir() + '/ipfs-' + hat()
@@ -32,6 +34,7 @@ function off (tests) {
3234
})
3335

3436
after(async function () {
37+
resetLocaleToSystem()
3538
this.timeout(20 * 1000)
3639
await clean(repoPath)
3740
})
@@ -49,6 +52,8 @@ function on (tests) {
4952

5053
let ipfsd
5154
before(async function () {
55+
setLocaleToEnglish()
56+
5257
// CI takes longer to instantiate the daemon,
5358
// so we need to increase the timeout for the
5459
// before step
@@ -65,6 +70,7 @@ function on (tests) {
6570
})
6671

6772
after(function () {
73+
resetLocaleToSystem()
6874
if (ipfsd) {
6975
this.timeout(15 * 1000)
7076
return ipfsd.stop()
@@ -75,6 +81,46 @@ function on (tests) {
7581
})
7682
}
7783

84+
function setLocaleToEnglish () {
85+
Object.assign(process.env, {
86+
LANG: 'en_US.UTF-8',
87+
LANGUAGE: 'en_US.UTF-8',
88+
LC_CTYPE: 'en_US.UTF-8',
89+
LC_NUMERIC: 'en_US.UTF-8',
90+
LC_TIME: 'en_US.UTF-8',
91+
LC_COLLATE: 'en_US.UTF-8',
92+
LC_MONETARY: 'en_US.UTF-8',
93+
LC_MESSAGES: 'en_US.UTF-8',
94+
LC_PAPER: 'en_US.UTF-8',
95+
LC_NAME: 'en_US.UTF-8',
96+
LC_ADDRESS: 'en_US.UTF-8',
97+
LC_TELEPHONE: 'en_US.UTF-8',
98+
LC_MEASUREMENT: 'en_US.UTF-8',
99+
LC_IDENTIFICATION: 'en_US.UTF-8',
100+
LC_ALL: 'en_US.UTF-8'
101+
})
102+
}
103+
104+
function resetLocaleToSystem () {
105+
Object.assign(process.env, {
106+
LANG: origLocale,
107+
LANGUAGE: origLocale,
108+
LC_CTYPE: origLocale,
109+
LC_NUMERIC: origLocale,
110+
LC_TIME: origLocale,
111+
LC_COLLATE: origLocale,
112+
LC_MONETARY: origLocale,
113+
LC_MESSAGES: origLocale,
114+
LC_PAPER: origLocale,
115+
LC_NAME: origLocale,
116+
LC_ADDRESS: origLocale,
117+
LC_TELEPHONE: origLocale,
118+
LC_MEASUREMENT: origLocale,
119+
LC_IDENTIFICATION: origLocale,
120+
LC_ALL: origLocale
121+
})
122+
}
123+
78124
/*
79125
* CLI Utility to run the tests offline (daemon off) and online (daemon on)
80126
*/

0 commit comments

Comments
 (0)