Most tests in `test/parallel` work when invoked with `node` rather than `tools/test.py` but not test-os-checked-function because it doesn't load the `common` module initially, which means it won't get re-spawned with the necessary flags (in the Flags: comment, in this case --expose_internals). Now that common delays loading 'os' until it needs to load it, this test can load the common module and it will work from the command line without the test harness. Additionally, we now can remove a comment disabling a lint rule. PR-URL: https://github.com/nodejs/node/pull/30914 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
20 lines
519 B
JavaScript
20 lines
519 B
JavaScript
'use strict';
|
|
// Flags: --expose_internals
|
|
|
|
const common = require('../common');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
|
|
// Monkey patch the os binding before requiring any other modules, including
|
|
// common, which requires the os module.
|
|
internalBinding('os').getHomeDirectory = function(ctx) {
|
|
ctx.syscall = 'foo';
|
|
ctx.code = 'bar';
|
|
ctx.message = 'baz';
|
|
};
|
|
|
|
const os = require('os');
|
|
|
|
common.expectsError(os.homedir, {
|
|
message: /^A system error occurred: foo returned bar \(baz\)$/
|
|
});
|