node/test/parallel/test-vm-syntax-error-message.js
cjihrig aa0e4f3843 test: use common.fail() instead of assert(false)
PR-URL: https://github.com/nodejs/node/pull/10899
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-01-23 09:45:58 -05:00

26 lines
651 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const child_process = require('child_process');
const p = child_process.spawn(process.execPath, [
'-e',
'vm = require("vm");' +
'context = vm.createContext({});' +
'try { vm.runInContext("throw new Error(\'boo\')", context); } ' +
'catch (e) { console.log(e.message); }'
]);
p.stderr.on('data', function(data) {
common.fail(`Unexpected stderr data: ${data}`);
});
let output = '';
p.stdout.on('data', function(data) {
output += data;
});
process.on('exit', function() {
assert.strictEqual(output.replace(/[\r\n]+/g, ''), 'boo');
});