Skip to content

Commit 2e3b758

Browse files
refackjasnell
authored andcommitted
test,module: make message check MUI dependent
PR-URL: #13393 Fixes: #13376 Reviewed-By: Tobias Nießen <[email protected]>
1 parent afe91ec commit 2e3b758

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

test/parallel/test-module-loading-error.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,38 @@
2222
'use strict';
2323
const common = require('../common');
2424
const assert = require('assert');
25+
const { execSync } = require('child_process');
2526

26-
const error_desc = {
27+
const errorMessagesByPlatform = {
2728
win32: ['%1 is not a valid Win32 application'],
2829
linux: ['file too short', 'Exec format error'],
2930
sunos: ['unknown file type', 'not an ELF file'],
3031
darwin: ['file too short']
3132
};
32-
const dlerror_msg = error_desc[process.platform];
33+
// If we don't know a priori what the error would be, we accept anything.
34+
const errorMessages = errorMessagesByPlatform[process.platform] || [''];
35+
36+
// On Windows, error messages are MUI dependent
37+
// Ref: https://github.com/nodejs/node/issues/13376
38+
let localeOk = true;
39+
if (common.isWindows) {
40+
const powerShellFindMUI =
41+
'powershell -NoProfile -ExecutionPolicy Unrestricted -c ' +
42+
'"(Get-UICulture).TwoLetterISOLanguageName"';
43+
try {
44+
// If MUI != 'en' we'll ignore the content of the message
45+
localeOk = execSync(powerShellFindMUI).toString('utf8').trim() === 'en';
46+
} catch (_) {
47+
// It's only a best effort try to find the MUI
48+
}
49+
}
3350

3451
assert.throws(
3552
() => { require('../fixtures/module-loading-error.node'); },
3653
(e) => {
37-
if (dlerror_msg && !dlerror_msg.some((msg) => e.message.includes(msg)))
38-
return false;
39-
if (e.name !== 'Error')
54+
if (localeOk && !errorMessages.some((msg) => e.message.includes(msg)))
4055
return false;
41-
return true;
56+
return e.name === 'Error';
4257
}
4358
);
4459

0 commit comments

Comments
 (0)