diff --git a/lib/internal/streams/lazy_transform.js b/lib/internal/streams/lazy_transform.js index 80e0bacf29df7c..c4d8c64b3dd041 100644 --- a/lib/internal/streams/lazy_transform.js +++ b/lib/internal/streams/lazy_transform.js @@ -5,7 +5,10 @@ const stream = require('stream'); const util = require('util'); -const crypto = require('crypto'); + +const { + getDefaultEncoding +} = require('internal/crypto/util'); module.exports = LazyTransform; @@ -22,7 +25,7 @@ function makeGetter(name) { this._writableState.decodeStrings = false; if (!this._options || !this._options.defaultEncoding) { - this._writableState.defaultEncoding = crypto.DEFAULT_ENCODING; + this._writableState.defaultEncoding = getDefaultEncoding(); } return this[name]; diff --git a/test/sequential/test-native-module-deps.js b/test/sequential/test-native-module-deps.js new file mode 100644 index 00000000000000..f01c55a7c36822 --- /dev/null +++ b/test/sequential/test-native-module-deps.js @@ -0,0 +1,43 @@ +'use strict'; + +// This tests that all the native modules can be loaded independently +// Flags: --expose-internals + +if (process.argv[3]) { + require(process.argv[3]); + return; +} + +require('../common'); +const { + cachableBuiltins +} = require('internal/bootstrap/cache'); +const { fork } = require('child_process'); +const assert = require('assert'); + +for (const key of cachableBuiltins) { + run(key); +} + +function run(key) { + const child = fork(__filename, + [ '--expose-internals', key ], + { silent: true } + ); + + let stdout = ''; + let stderr = ''; + child.stdout.on('data', (data) => (stdout += data.toString())); + child.stderr.on('data', (data) => (stderr += data.toString())); + child.on('close', (code) => { + if (code === 0) { + return; + } + console.log(`Failed to require ${key}`); + console.log('----- stderr ----'); + console.log(stderr); + console.log('----- stdout ----'); + console.log(stdout); + assert.strictEqual(code, 0); + }); +}