Skip to content

Commit

Permalink
test: add testcase for SourceTextModule custom inspect
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ch1ller0 authored and targos committed May 31, 2019
1 parent 630cc3a commit b5b234d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/parallel/test-vm-module-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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]');
}

0 comments on commit b5b234d

Please sign in to comment.