Skip to content

Commit b5b234d

Browse files
ch1ller0targos
authored andcommitted
test: add testcase for SourceTextModule custom inspect
PR-URL: #27889 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 630cc3a commit b5b234d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/parallel/test-vm-module-basic.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const common = require('../common');
66
const assert = require('assert');
77
const { SourceTextModule, createContext } = require('vm');
8+
const util = require('util');
89

910
(async function test1() {
1011
const context = createContext({
@@ -63,3 +64,21 @@ const { SourceTextModule, createContext } = require('vm');
6364
const m3 = new SourceTextModule('3', { context: context2 });
6465
assert.strictEqual(m3.url, 'vm:module(0)');
6566
})();
67+
68+
// Check inspection of the instance
69+
{
70+
const context = createContext({ foo: 'bar' });
71+
const m = new SourceTextModule('1', { context });
72+
73+
assert.strictEqual(
74+
util.inspect(m),
75+
"SourceTextModule {\n status: 'uninstantiated',\n linkingStatus:" +
76+
" 'unlinked',\n url: 'vm:module(0)',\n context: { foo: 'bar' }\n}"
77+
);
78+
assert.strictEqual(
79+
m[util.inspect.custom].call(Object.create(null)),
80+
'SourceTextModule {\n status: undefined,\n linkingStatus: undefined,' +
81+
'\n url: undefined,\n context: undefined\n}'
82+
);
83+
assert.strictEqual(util.inspect(m, { depth: -1 }), '[SourceTextModule]');
84+
}

0 commit comments

Comments
 (0)