• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const dgram = require('dgram');
6const fork = require('child_process').fork;
7
8const sock = dgram.createSocket('udp4');
9
10const testNumber = parseInt(process.argv[2], 10);
11
12const propertiesToTest = [
13  '_handle',
14  '_receiving',
15  '_bindState',
16  '_queue',
17  '_reuseAddr',
18];
19
20const methodsToTest = [
21  '_healthCheck',
22  '_stopReceiving',
23];
24
25const propertyCases = propertiesToTest.map((propName) => {
26  return [
27    () => {
28      // Test property getter
29      common.expectWarning(
30        'DeprecationWarning',
31        `Socket.prototype.${propName} is deprecated`,
32        'DEP0112'
33      );
34      sock[propName]; // eslint-disable-line no-unused-expressions
35    },
36    () => {
37      // Test property setter
38      common.expectWarning(
39        'DeprecationWarning',
40        `Socket.prototype.${propName} is deprecated`,
41        'DEP0112'
42      );
43      sock[propName] = null;
44    },
45  ];
46});
47
48const methodCases = methodsToTest.map((propName) => {
49  return () => {
50    common.expectWarning(
51      'DeprecationWarning',
52      `Socket.prototype.${propName}() is deprecated`,
53      'DEP0112'
54    );
55    sock[propName]();
56  };
57});
58
59const cases = [].concat(
60  ...propertyCases,
61  ...methodCases
62);
63
64// If we weren't passed a test ID then we need to spawn all of the cases.
65// We run the cases in child processes since deprecations print once.
66if (Number.isNaN(testNumber)) {
67  const children = cases.map((_case, i) =>
68    fork(process.argv[1], [ String(i) ]));
69
70  children.forEach((child) => {
71    child.on('close', (code) => {
72      // Pass on child exit code
73      if (code > 0) {
74        process.exit(code);
75      }
76    });
77  });
78
79  return;
80}
81
82// We were passed a test ID - run the test case
83assert.ok(cases[testNumber]);
84cases[testNumber]();
85