mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 06:02:29 +00:00

Enable linting for the test directory. A number of changes was made so all tests conform the current rules used by lib and src directories. The only exception for tests is that unreachable (dead) code is allowed. test-fs-non-number-arguments-throw had to be excluded from the changes because of a weird issue on Windows CI. PR-URL: https://github.com/nodejs/io.js/pull/1721 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
/* eslint-disable no-debugger */
|
|
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
var vm = require('vm');
|
|
var spawn = require('child_process').spawn;
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext('*');
|
|
}, /SyntaxError/);
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext({ toString: assert.fail });
|
|
}, /AssertionError/);
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext('throw URIError("BAM")');
|
|
}, /URIError/);
|
|
|
|
assert.throws(function() {
|
|
vm.runInDebugContext('(function(f) { f(f) })(function(f) { f(f) })');
|
|
}, /RangeError/);
|
|
|
|
assert.equal(typeof(vm.runInDebugContext('this')), 'object');
|
|
assert.equal(typeof(vm.runInDebugContext('Debug')), 'object');
|
|
|
|
assert.strictEqual(vm.runInDebugContext(), undefined);
|
|
assert.strictEqual(vm.runInDebugContext(0), 0);
|
|
assert.strictEqual(vm.runInDebugContext(null), null);
|
|
assert.strictEqual(vm.runInDebugContext(undefined), undefined);
|
|
|
|
// See https://github.com/nodejs/io.js/issues/1190, accessing named interceptors
|
|
// and accessors inside a debug event listener should not crash.
|
|
(function() {
|
|
var Debug = vm.runInDebugContext('Debug');
|
|
var breaks = 0;
|
|
|
|
function ondebugevent(evt, exc) {
|
|
if (evt !== Debug.DebugEvent.Break) return;
|
|
exc.frame(0).evaluate('process.env').properties(); // Named interceptor.
|
|
exc.frame(0).evaluate('process.title').getTruncatedValue(); // Accessor.
|
|
breaks += 1;
|
|
}
|
|
|
|
function breakpoint() {
|
|
debugger;
|
|
}
|
|
|
|
assert.equal(breaks, 0);
|
|
Debug.setListener(ondebugevent);
|
|
assert.equal(breaks, 0);
|
|
breakpoint();
|
|
assert.equal(breaks, 1);
|
|
})();
|
|
|
|
// See https://github.com/nodejs/io.js/issues/1190, fatal errors should not
|
|
// crash the process.
|
|
var script = common.fixturesDir + '/vm-run-in-debug-context.js';
|
|
var proc = spawn(process.execPath, [script]);
|
|
var data = [];
|
|
proc.stdout.on('data', assert.fail);
|
|
proc.stderr.on('data', data.push.bind(data));
|
|
proc.stderr.once('end', common.mustCall(function() {
|
|
var haystack = Buffer.concat(data).toString('utf8');
|
|
assert(/SyntaxError: Unexpected token \*/.test(haystack));
|
|
}));
|
|
proc.once('exit', common.mustCall(function(exitCode, signalCode) {
|
|
assert.equal(exitCode, 1);
|
|
assert.equal(signalCode, null);
|
|
}));
|
|
|
|
var proc = spawn(process.execPath, [script, 'handle-fatal-exception']);
|
|
proc.stdout.on('data', assert.fail);
|
|
proc.stderr.on('data', assert.fail);
|
|
proc.once('exit', common.mustCall(function(exitCode, signalCode) {
|
|
assert.equal(exitCode, 42);
|
|
assert.equal(signalCode, null);
|
|
}));
|