test: improve multiple vm tests · nodejs/node@f35f06d
@@ -6,29 +6,29 @@ const vm = require('vm');
66const Script = vm.Script;
77let script = new Script('"passed";');
889-console.error('run in a new empty context');
9+// Run in a new empty context
1010let context = vm.createContext();
1111let result = script.runInContext(context);
1212assert.strictEqual('passed', result);
131314-console.error('create a new pre-populated context');
15-context = vm.createContext({'foo': 'bar', 'thing': 'lala'});
14+// Create a new pre-populated context
15+context = vm.createContext({ 'foo': 'bar', 'thing': 'lala' });
1616assert.strictEqual('bar', context.foo);
1717assert.strictEqual('lala', context.thing);
181819-console.error('test updating context');
19+// Test updating context
2020script = new Script('foo = 3;');
2121result = script.runInContext(context);
2222assert.strictEqual(3, context.foo);
2323assert.strictEqual('lala', context.thing);
24242525// Issue GH-227:
26-assert.throws(function() {
26+assert.throws(() => {
2727vm.runInNewContext('', null, 'some.js');
2828}, /^TypeError: sandbox must be an object$/);
29293030// Issue GH-1140:
31-console.error('test runInContext signature');
31+// Test runInContext signature
3232let gh1140Exception;
3333try {
3434vm.runInContext('throw new Error()', context, 'expected-filename.js');
@@ -56,8 +56,8 @@ const contextifiedSandboxErrorMsg =
5656});
57575858// Issue GH-693:
59-console.error('test RegExp as argument to assert.throws');
60-script = vm.createScript('var assert = require(\'assert\'); assert.throws(' +
59+// Test RegExp as argument to assert.throws
60+script = vm.createScript('const assert = require(\'assert\'); assert.throws(' +
6161'function() { throw "hello world"; }, /hello/);',
6262'some.js');
6363script.runInNewContext({ require: require });
@@ -71,14 +71,14 @@ assert.strictEqual(script.runInContext(ctx), false);
71717272// Error on the first line of a module should
7373// have the correct line and column number
74-assert.throws(function() {
74+assert.throws(() => {
7575vm.runInContext('throw new Error()', context, {
7676filename: 'expected-filename.js',
7777lineOffset: 32,
7878columnOffset: 123
7979});
80-}, function(err) {
81-return /expected-filename.js:33:130/.test(err.stack);
80+}, (err) => {
81+return /expected-filename\.js:33:130/.test(err.stack);
8282}, 'Expected appearance of proper offset in Error stack');
83838484// https://github.com/nodejs/node/issues/6158