Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adds tests for vm invalid arguments #18282

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion test/parallel/test-vm-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const vm = require('vm');

Expand Down Expand Up @@ -69,3 +69,56 @@ assert.strictEqual(result, 'undefined');
const sandbox3 = {};
const context2 = vm.createContext(sandbox3);
assert.strictEqual(sandbox3, context2);

// Test 6: invalid arguments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't be opposed to a follow up PR that removes these "Test n:" comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went with what was already there 😅

common.expectsError(() => {
vm.createContext({}, null);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type object. Received type null'
});

common.expectsError(() => {
vm.createContext({}, 'string');
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type object. Received type string'
});

common.expectsError(() => {
vm.createContext({}, { name: null });
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.name" property must be of type string. ' +
'Received type null'
});

common.expectsError(() => {
vm.createContext({}, { origin: null });
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.origin" property must be of type string. ' +
'Received type null'
});

common.expectsError(() => {
vm.runInNewContext('', {}, { contextName: null });
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.contextName" property must be of type string. ' +
'Received type null'
});

common.expectsError(() => {
vm.runInNewContext('', {}, { contextOrigin: null });
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options.contextOrigin" property must be of type string. ' +
'Received type null'
});