From 5770ae057e67551c586680e84d6decdfa28f638a Mon Sep 17 00:00:00 2001 From: "Bruce A. MacNaughton" Date: Thu, 9 Jul 2020 17:27:46 -0700 Subject: [PATCH] doc: fix module syncBuiltinESMExports example Fix failing code and add explanations of each assert. PR-URL: https://github.com/nodejs/node/pull/34284 Reviewed-By: Guy Bedford Reviewed-By: Antoine du Hamel --- doc/api/module.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/api/module.md b/doc/api/module.md index 2fb6ca884b4443..3a00e6d47b014e 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -87,21 +87,29 @@ does not add or remove exported names from the [ES Modules][]. ```js const fs = require('fs'); +const assert = require('assert'); const { syncBuiltinESMExports } = require('module'); -fs.readFile = null; +fs.readFile = newAPI; delete fs.readFileSync; -fs.newAPI = function newAPI() { +function newAPI() { // ... -}; +} + +fs.newAPI = newAPI; syncBuiltinESMExports(); import('fs').then((esmFS) => { - assert.strictEqual(esmFS.readFile, null); - assert.strictEqual('readFileSync' in fs, true); + // It syncs the existing readFile property with the new value + assert.strictEqual(esmFS.readFile, newAPI); + // readFileSync has been deleted from the required fs + assert.strictEqual('readFileSync' in fs, false); + // syncBuiltinESMExports() does not remove readFileSync from esmFS + assert.strictEqual('readFileSync' in esmFS, true); + // syncBuiltinESMExports() does not add names assert.strictEqual(esmFS.newAPI, undefined); }); ```