MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/sequential/test-util-debug.js:58–110  ·  view source on GitHub ↗
(environ, shouldWrite, section, forceColors = false)

Source from the content-addressed store, hash-verified

56}
57
58function test(environ, shouldWrite, section, forceColors = false) {
59 let expectErr = '';
60 const expectOut = shouldWrite ? 'outer enabled\ninner enabled\n' : 'outer disabled\ninner disabled\n';
61
62 const spawn = require('child_process').spawn;
63 const child = spawn(process.execPath, [__filename, 'child', section], {
64 env: Object.assign(process.env, {
65 NODE_DEBUG: environ,
66 FORCE_COLOR: forceColors ? 'true' : 'false',
67 }),
68 });
69
70 if (shouldWrite) {
71 if (forceColors) {
72 const { colors, styles } = util.inspect;
73 const addCodes = (arr) => [`\x1B[${arr[0]}m`, `\x1B[${arr[1]}m`];
74 const num = addCodes(colors[styles.number]);
75 const str = addCodes(colors[styles.string]);
76 const start = `${section.toUpperCase()} ${num[0]}${child.pid}${num[1]}`;
77 const debugging = styles.regexp('/debugging/');
78 expectErr =
79 `${start}: this { is: ${str[0]}'a'${str[1]} } ${debugging}\n` +
80 `${start}: num=1 str=a obj={"foo":"bar"}\n`;
81 } else {
82 const start = `${section.toUpperCase()} ${child.pid}`;
83 expectErr =
84 `${start}: this { is: 'a' } /debugging/\n` +
85 `${start}: num=1 str=a obj={"foo":"bar"}\n`;
86 }
87 }
88
89 let err = '';
90 child.stderr.setEncoding('utf8');
91 child.stderr.on('data', (c) => {
92 err += c;
93 });
94
95 let out = '';
96 child.stdout.setEncoding('utf8');
97 child.stdout.on('data', (c) => {
98 out += c;
99 });
100
101 child.on('close', common.mustCall((c) => {
102 assert(!c);
103 assert.strictEqual(err, expectErr);
104 assert.strictEqual(out, expectOut);
105 // Run the test again, this time with colors enabled.
106 if (!forceColors) {
107 test(environ, shouldWrite, section, true);
108 }
109 }));
110}
111
112
113function child(section) {

Callers 1

parentFunction · 0.70

Calls 7

addCodesFunction · 0.85
assignMethod · 0.80
requireFunction · 0.50
spawnFunction · 0.50
assertFunction · 0.50
setEncodingMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…