From b5b234deff631a8da7dcd8953231ce781553a49e Mon Sep 17 00:00:00 2001 From: Grigory Gorshkov Date: Sun, 26 May 2019 14:11:42 +0300 Subject: [PATCH] test: add testcase for SourceTextModule custom inspect PR-URL: https://github.com/nodejs/node/pull/27889 Reviewed-By: Anna Henningsen Reviewed-By: Ujjwal Sharma Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott Reviewed-By: Gireesh Punathil --- test/parallel/test-vm-module-basic.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/parallel/test-vm-module-basic.js b/test/parallel/test-vm-module-basic.js index 8cf687c2bb23a8..caf4be328d5873 100644 --- a/test/parallel/test-vm-module-basic.js +++ b/test/parallel/test-vm-module-basic.js @@ -5,6 +5,7 @@ const common = require('../common'); const assert = require('assert'); const { SourceTextModule, createContext } = require('vm'); +const util = require('util'); (async function test1() { const context = createContext({ @@ -63,3 +64,21 @@ const { SourceTextModule, createContext } = require('vm'); const m3 = new SourceTextModule('3', { context: context2 }); assert.strictEqual(m3.url, 'vm:module(0)'); })(); + +// Check inspection of the instance +{ + const context = createContext({ foo: 'bar' }); + const m = new SourceTextModule('1', { context }); + + assert.strictEqual( + util.inspect(m), + "SourceTextModule {\n status: 'uninstantiated',\n linkingStatus:" + + " 'unlinked',\n url: 'vm:module(0)',\n context: { foo: 'bar' }\n}" + ); + assert.strictEqual( + m[util.inspect.custom].call(Object.create(null)), + 'SourceTextModule {\n status: undefined,\n linkingStatus: undefined,' + + '\n url: undefined,\n context: undefined\n}' + ); + assert.strictEqual(util.inspect(m, { depth: -1 }), '[SourceTextModule]'); +}