| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -193,11 +193,11 @@ export default [ | |||
| 193 | 193 | 'wpt', | |
| 194 | 194 | ].join(',')}}/**/*.{js,mjs,cjs}`, | |
| 195 | 195 | `test/parallel/test-{${ | |
| 196 | + // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' | ||
| 197 | + Array.from({ length: 3 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') | ||
| 198 | + },${ | ||
| 196 | 199 | // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…' | |
| 197 | 200 | Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') | |
| 198 | - },${ | ||
| 199 | - // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' | ||
| 200 | - Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') | ||
| 201 | 201 | }}.{js,mjs,cjs}`, | |
| 202 | 202 | ], | |
| 203 | 203 | rules: { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,31 +36,31 @@ function createChild(options, callback) { | |||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | test('normal execution of a child process is handled', (_, done) => { | |
| 39 | - createChild({}, (err, stdout, stderr) => { | ||
| 39 | + createChild({}, common.mustCall((err, stdout, stderr) => { | ||
| 40 | 40 | assert.strictEqual(err, null); | |
| 41 | 41 | assert.strictEqual(stdout, ''); | |
| 42 | 42 | assert.strictEqual(stderr, ''); | |
| 43 | 43 | done(); | |
| 44 | - }); | ||
| 44 | + })); | ||
| 45 | 45 | }); | |
| 46 | 46 | ||
| 47 | 47 | test('execution with an error event is handled', (_, done) => { | |
| 48 | 48 | const error = new Error('foo'); | |
| 49 | - const child = createChild({}, (err, stdout, stderr) => { | ||
| 49 | + const child = createChild({}, common.mustCall((err, stdout, stderr) => { | ||
| 50 | 50 | assert.strictEqual(err, error); | |
| 51 | 51 | assert.strictEqual(stdout, ''); | |
| 52 | 52 | assert.strictEqual(stderr, ''); | |
| 53 | 53 | done(); | |
| 54 | - }); | ||
| 54 | + })); | ||
| 55 | 55 | ||
| 56 | 56 | child.emit('error', error); | |
| 57 | 57 | }); | |
| 58 | 58 | ||
| 59 | 59 | test('execution with a killed process is handled', (_, done) => { | |
| 60 | - createChild({ timeout: 1 }, (err, stdout, stderr) => { | ||
| 60 | + createChild({ timeout: 1 }, common.mustCall((err, stdout, stderr) => { | ||
| 61 | 61 | assert.strictEqual(err.killed, true); | |
| 62 | 62 | assert.strictEqual(stdout, ''); | |
| 63 | 63 | assert.strictEqual(stderr, ''); | |
| 64 | 64 | done(); | |
| 65 | - }); | ||
| 65 | + })); | ||
| 66 | 66 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | // Tests that a spawned child process can write to stdout without throwing. | |
| 3 | 3 | // See https://github.com/nodejs/node-v0.x-archive/issues/1899. | |
| 4 | 4 | ||
| 5 | - require('../common'); | ||
| 5 | + const common = require('../common'); | ||
| 6 | 6 | const fixtures = require('../common/fixtures'); | |
| 7 | 7 | const assert = require('assert'); | |
| 8 | 8 | const spawn = require('child_process').spawn; | |
@@ -16,7 +16,7 @@ child.stdout.on('data', function(data) { | |||
| 16 | 16 | output += data; | |
| 17 | 17 | }); | |
| 18 | 18 | ||
| 19 | - child.on('exit', function(code, signal) { | ||
| 19 | + child.on('exit', common.mustCall((code) => { | ||
| 20 | 20 | assert.strictEqual(code, 0); | |
| 21 | 21 | assert.strictEqual(output, 'hello, world!\n'); | |
| 22 | - }); | ||
| 22 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ const { spawn } = require('child_process'); | |||
| 32 | 32 | // - whether the child pid is undefined or number, | |
| 33 | 33 | // - whether the exit code equals expectCode, | |
| 34 | 34 | // - optionally whether the trimmed stdout result matches expectData | |
| 35 | - function testCwd(options, expectPidType, expectCode = 0, expectData) { | ||
| 35 | + function testCwd(options, expectPidType, expectCode = 0, expectData, shouldCallExit = true) { | ||
| 36 | 36 | const child = spawn(...common.pwdCommand, options); | |
| 37 | 37 | ||
| 38 | 38 | assert.strictEqual(typeof child.pid, expectPidType); | |
@@ -47,9 +47,9 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) { | |||
| 47 | 47 | ||
| 48 | 48 | // Can't assert callback, as stayed in to API: | |
| 49 | 49 | // _The 'exit' event may or may not fire after an error has occurred._ | |
| 50 | - child.on('exit', function(code, signal) { | ||
| 50 | + child.on('exit', shouldCallExit ? common.mustCall((code) => { | ||
| 51 | 51 | assert.strictEqual(code, expectCode); | |
| 52 | - }); | ||
| 52 | + }) : common.mustNotCall()); | ||
| 53 | 53 | ||
| 54 | 54 | child.on('close', common.mustCall(function() { | |
| 55 | 55 | if (expectData) { | |
@@ -68,7 +68,7 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) { | |||
| 68 | 68 | ||
| 69 | 69 | // Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT | |
| 70 | 70 | { | |
| 71 | - testCwd({ cwd: 'does-not-exist' }, 'undefined', -1) | ||
| 71 | + testCwd({ cwd: 'does-not-exist' }, 'undefined', -1, undefined, false) | ||
| 72 | 72 | .on('error', common.mustCall(function(e) { | |
| 73 | 73 | assert.strictEqual(e.code, 'ENOENT'); | |
| 74 | 74 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,13 +30,13 @@ if (process.argv[2] === 'child') { | |||
| 30 | 30 | ||
| 31 | 31 | // Check that the 'disconnect' event is deferred to the next event loop tick. | |
| 32 | 32 | const disconnect = process.disconnect; | |
| 33 | - process.disconnect = function() { | ||
| 33 | + process.disconnect = common.mustCall(function() { | ||
| 34 | 34 | disconnect.apply(this, arguments); | |
| 35 | 35 | // If the event is emitted synchronously, we're too late by now. | |
| 36 | 36 | process.once('disconnect', common.mustCall(disconnectIsNotAsync)); | |
| 37 | 37 | // The funky function name makes it show up legible in mustCall errors. | |
| 38 | 38 | function disconnectIsNotAsync() {} | |
| 39 | - }; | ||
| 39 | + }); | ||
| 40 | 40 | ||
| 41 | 41 | const server = net.createServer(); | |
| 42 | 42 | ||
@@ -81,13 +81,13 @@ if (process.argv[2] === 'child') { | |||
| 81 | 81 | child.on('exit', common.mustCall()); | |
| 82 | 82 | ||
| 83 | 83 | // When child is listening | |
| 84 | - child.on('message', function(obj) { | ||
| 84 | + child.on('message', common.mustCallAtLeast((obj) => { | ||
| 85 | 85 | if (obj && obj.msg === 'ready') { | |
| 86 | 86 | ||
| 87 | 87 | // Connect to child using TCP to know if disconnect was emitted | |
| 88 | 88 | const socket = net.connect(obj.port); | |
| 89 | 89 | ||
| 90 | - socket.on('data', function(data) { | ||
| 90 | + socket.on('data', common.mustCallAtLeast((data) => { | ||
| 91 | 91 | data = data.toString(); | |
| 92 | 92 | ||
| 93 | 93 | // Ready to be disconnected | |
@@ -103,10 +103,10 @@ if (process.argv[2] === 'child') { | |||
| 103 | 103 | ||
| 104 | 104 | // 'disconnect' is emitted | |
| 105 | 105 | childFlag = (data === 'true'); | |
| 106 | - }); | ||
| 106 | + })); | ||
| 107 | 107 | ||
| 108 | 108 | } | |
| 109 | - }); | ||
| 109 | + })); | ||
| 110 | 110 | ||
| 111 | 111 | process.on('exit', function() { | |
| 112 | 112 | assert.strictEqual(childFlag, false); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,28 +22,28 @@ if (process.argv[2] === 'child') { | |||
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | // Test default encoding, which should be utf8. | |
| 25 | - run({}, (stdout, stderr) => { | ||
| 25 | + run({}, common.mustCall((stdout, stderr) => { | ||
| 26 | 26 | assert.strictEqual(typeof stdout, 'string'); | |
| 27 | 27 | assert.strictEqual(typeof stderr, 'string'); | |
| 28 | 28 | assert.strictEqual(stdout, expectedStdout); | |
| 29 | 29 | assert.strictEqual(stderr, expectedStderr); | |
| 30 | - }); | ||
| 30 | + })); | ||
| 31 | 31 | ||
| 32 | 32 | // Test explicit utf8 encoding. | |
| 33 | - run({ encoding: 'utf8' }, (stdout, stderr) => { | ||
| 33 | + run({ encoding: 'utf8' }, common.mustCall((stdout, stderr) => { | ||
| 34 | 34 | assert.strictEqual(typeof stdout, 'string'); | |
| 35 | 35 | assert.strictEqual(typeof stderr, 'string'); | |
| 36 | 36 | assert.strictEqual(stdout, expectedStdout); | |
| 37 | 37 | assert.strictEqual(stderr, expectedStderr); | |
| 38 | - }); | ||
| 38 | + })); | ||
| 39 | 39 | ||
| 40 | 40 | // Test cases that result in buffer encodings. | |
| 41 | 41 | [undefined, null, 'buffer', 'invalid'].forEach((encoding) => { | |
| 42 | - run({ encoding }, (stdout, stderr) => { | ||
| 42 | + run({ encoding }, common.mustCall((stdout, stderr) => { | ||
| 43 | 43 | assert(stdout instanceof Buffer); | |
| 44 | 44 | assert(stdout instanceof Buffer); | |
| 45 | 45 | assert.strictEqual(stdout.toString(), expectedStdout); | |
| 46 | 46 | assert.strictEqual(stderr.toString(), expectedStderr); | |
| 47 | - }); | ||
| 47 | + })); | ||
| 48 | 48 | }); | |
| 49 | 49 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,14 +65,14 @@ common.expectWarning( | |||
| 65 | 65 | const ac = new AbortController(); | |
| 66 | 66 | const { signal } = ac; | |
| 67 | 67 | ||
| 68 | - const test = () => { | ||
| 68 | + const test = common.mustCall(() => { | ||
| 69 | 69 | const check = common.mustCall((err) => { | |
| 70 | 70 | assert.strictEqual(err.code, 'ABORT_ERR'); | |
| 71 | 71 | assert.strictEqual(err.name, 'AbortError'); | |
| 72 | 72 | assert.strictEqual(err.signal, undefined); | |
| 73 | 73 | }); | |
| 74 | 74 | execFile(process.execPath, [echoFixture, 0], { signal }, check); | |
| 75 | - }; | ||
| 75 | + }); | ||
| 76 | 76 | ||
| 77 | 77 | // Verify that it still works the same way now that the signal is aborted. | |
| 78 | 78 | test(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ p.on('close', common.mustCall((code, signal) => { | |||
| 17 | 17 | ||
| 18 | 18 | p.stdout.read(); | |
| 19 | 19 | ||
| 20 | - const spawnWithReadable = () => { | ||
| 20 | + const spawnWithReadable = common.mustCall(() => { | ||
| 21 | 21 | const buffer = []; | |
| 22 | 22 | const p = cp.spawn('echo', ['123'], opts); | |
| 23 | 23 | p.on('close', common.mustCall((code, signal) => { | |
@@ -30,4 +30,4 @@ const spawnWithReadable = () => { | |||
| 30 | 30 | while ((buf = p.stdout.read()) !== null) | |
| 31 | 31 | buffer.push(buf); | |
| 32 | 32 | }); | |
| 33 | - }; | ||
| 33 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { mustCall, mustNotCall } = require('../common'); | |
| 4 | - const { strictEqual } = require('assert'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | 5 | const fixtures = require('../common/fixtures'); | |
| 6 | 6 | const { fork } = require('child_process'); | |
| 7 | 7 | ||
@@ -13,11 +13,11 @@ const { fork } = require('child_process'); | |||
| 13 | 13 | signal | |
| 14 | 14 | }); | |
| 15 | 15 | cp.on('exit', mustCall((code, killSignal) => { | |
| 16 | - strictEqual(code, null); | ||
| 17 | - strictEqual(killSignal, 'SIGTERM'); | ||
| 16 | + assert.strictEqual(code, null); | ||
| 17 | + assert.strictEqual(killSignal, 'SIGTERM'); | ||
| 18 | 18 | })); | |
| 19 | 19 | cp.on('error', mustCall((err) => { | |
| 20 | - strictEqual(err.name, 'AbortError'); | ||
| 20 | + assert.strictEqual(err.name, 'AbortError'); | ||
| 21 | 21 | })); | |
| 22 | 22 | process.nextTick(() => ac.abort()); | |
| 23 | 23 | } | |
@@ -30,13 +30,13 @@ const { fork } = require('child_process'); | |||
| 30 | 30 | signal | |
| 31 | 31 | }); | |
| 32 | 32 | cp.on('exit', mustCall((code, killSignal) => { | |
| 33 | - strictEqual(code, null); | ||
| 34 | - strictEqual(killSignal, 'SIGTERM'); | ||
| 33 | + assert.strictEqual(code, null); | ||
| 34 | + assert.strictEqual(killSignal, 'SIGTERM'); | ||
| 35 | 35 | })); | |
| 36 | 36 | cp.on('error', mustCall((err) => { | |
| 37 | - strictEqual(err.name, 'AbortError'); | ||
| 38 | - strictEqual(err.cause.name, 'Error'); | ||
| 39 | - strictEqual(err.cause.message, 'boom'); | ||
| 37 | + assert.strictEqual(err.name, 'AbortError'); | ||
| 38 | + assert.strictEqual(err.cause.name, 'Error'); | ||
| 39 | + assert.strictEqual(err.cause.message, 'boom'); | ||
| 40 | 40 | })); | |
| 41 | 41 | process.nextTick(() => ac.abort(new Error('boom'))); | |
| 42 | 42 | } | |
@@ -48,11 +48,11 @@ const { fork } = require('child_process'); | |||
| 48 | 48 | signal | |
| 49 | 49 | }); | |
| 50 | 50 | cp.on('exit', mustCall((code, killSignal) => { | |
| 51 | - strictEqual(code, null); | ||
| 52 | - strictEqual(killSignal, 'SIGTERM'); | ||
| 51 | + assert.strictEqual(code, null); | ||
| 52 | + assert.strictEqual(killSignal, 'SIGTERM'); | ||
| 53 | 53 | })); | |
| 54 | 54 | cp.on('error', mustCall((err) => { | |
| 55 | - strictEqual(err.name, 'AbortError'); | ||
| 55 | + assert.strictEqual(err.name, 'AbortError'); | ||
| 56 | 56 | })); | |
| 57 | 57 | } | |
| 58 | 58 | ||
@@ -63,13 +63,13 @@ const { fork } = require('child_process'); | |||
| 63 | 63 | signal | |
| 64 | 64 | }); | |
| 65 | 65 | cp.on('exit', mustCall((code, killSignal) => { | |
| 66 | - strictEqual(code, null); | ||
| 67 | - strictEqual(killSignal, 'SIGTERM'); | ||
| 66 | + assert.strictEqual(code, null); | ||
| 67 | + assert.strictEqual(killSignal, 'SIGTERM'); | ||
| 68 | 68 | })); | |
| 69 | 69 | cp.on('error', mustCall((err) => { | |
| 70 | - strictEqual(err.name, 'AbortError'); | ||
| 71 | - strictEqual(err.cause.name, 'Error'); | ||
| 72 | - strictEqual(err.cause.message, 'boom'); | ||
| 70 | + assert.strictEqual(err.name, 'AbortError'); | ||
| 71 | + assert.strictEqual(err.cause.name, 'Error'); | ||
| 72 | + assert.strictEqual(err.cause.message, 'boom'); | ||
| 73 | 73 | })); | |
| 74 | 74 | } | |
| 75 | 75 | ||
@@ -81,11 +81,11 @@ const { fork } = require('child_process'); | |||
| 81 | 81 | killSignal: 'SIGKILL', | |
| 82 | 82 | }); | |
| 83 | 83 | cp.on('exit', mustCall((code, killSignal) => { | |
| 84 | - strictEqual(code, null); | ||
| 85 | - strictEqual(killSignal, 'SIGKILL'); | ||
| 84 | + assert.strictEqual(code, null); | ||
| 85 | + assert.strictEqual(killSignal, 'SIGKILL'); | ||
| 86 | 86 | })); | |
| 87 | 87 | cp.on('error', mustCall((err) => { | |
| 88 | - strictEqual(err.name, 'AbortError'); | ||
| 88 | + assert.strictEqual(err.name, 'AbortError'); | ||
| 89 | 89 | })); | |
| 90 | 90 | } | |
| 91 | 91 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ const server = net | |||
| 28 | 28 | s.destroy(); | |
| 29 | 29 | }, 100); | |
| 30 | 30 | }) | |
| 31 | - .listen(0, function() { | ||
| 31 | + .listen(0, common.mustCall(() => { | ||
| 32 | 32 | const worker = cluster.fork(); | |
| 33 | 33 | ||
| 34 | 34 | worker.on('error', function(err) { | |
@@ -70,9 +70,8 @@ const server = net | |||
| 70 | 70 | }) | |
| 71 | 71 | ); | |
| 72 | 72 | ||
| 73 | - worker.on('online', function() { | ||
| 74 | - send(function(err) { | ||
| 75 | - assert.ifError(err); | ||
| 73 | + worker.on('online', common.mustCall(() => { | ||
| 74 | + send(common.mustSucceed(() => { | ||
| 76 | 75 | send(function(err) { | |
| 77 | 76 | // Ignore errors when sending the second handle because the worker | |
| 78 | 77 | // may already have exited. | |
@@ -83,6 +82,6 @@ const server = net | |||
| 83 | 82 | throw err; | |
| 84 | 83 | } | |
| 85 | 84 | }); | |
| 86 | - }); | ||
| 87 | - }); | ||
| 88 | - }); | ||
| 85 | + })); | ||
| 86 | + })); | ||
| 87 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments