GeezerVison is showing github.com — test: ensure assertions are reachable in `test/sequential` · nodejs/node@12e9213
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/eslint.config_partial.mjs +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -178,6 +178,7 @@ export default [ | 178 | 178 | 'pummel', | 179 | 179 | 'report', | 180 | 180 | 'sea', | | 181 | + 'sequential', | 181 | 182 | 'sqlite', | 182 | 183 | 'system-ca', | 183 | 184 | 'test426', | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-child-process-execsync.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,9 +147,9 @@ const args = [ | 147 | 147 | assert.strictEqual(typeof err.pid, 'number'); | 148 | 148 | spawnSyncKeys | 149 | 149 | .filter((key) => key !== 'pid') | 150 | | - .forEach((key) => { | | 150 | + .forEach(common.mustCallAtLeast((key) => { | 151 | 151 | assert.deepStrictEqual(err[key], spawnSyncResult[key]); | 152 | | - }); | | 152 | + })); | 153 | 153 | return true; | 154 | 154 | }); | 155 | 155 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-child-process-pass-fd.js +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,7 @@ const N = 80; | 21 | 21 | let messageCallbackCount = 0; | 22 | 22 |
| 23 | 23 | function forkWorker() { | 24 | | - const messageCallback = (msg, handle) => { | | 24 | + const messageCallback = common.mustCall((msg, handle) => { | 25 | 25 | messageCallbackCount++; | 26 | 26 | assert.strictEqual(msg, 'handle'); | 27 | 27 | assert.ok(handle); | @@ -32,11 +32,11 @@ function forkWorker() { | 32 | 32 | recvData += data; | 33 | 33 | })); | 34 | 34 |
| 35 | | - handle.on('end', () => { | | 35 | + handle.on('end', common.mustCall(() => { | 36 | 36 | assert.strictEqual(recvData, 'hello'); | 37 | 37 | worker.kill(); | 38 | | - }); | 39 | | - }; | | 38 | + })); | | 39 | + }); | 40 | 40 |
| 41 | 41 | const worker = fork(__filename, ['child']); | 42 | 42 | worker.on('error', (err) => { | @@ -70,13 +70,13 @@ if (process.argv[2] !== 'child') { | 70 | 70 | // thus no work to do, and will exit immediately, preventing process leaks. | 71 | 71 | process.on('message', common.mustCall()); | 72 | 72 |
| 73 | | - const server = net.createServer((c) => { | 74 | | - process.once('message', (msg) => { | | 73 | + const server = net.createServer(common.mustCall((c) => { | | 74 | + process.once('message', common.mustCall((msg) => { | 75 | 75 | assert.strictEqual(msg, 'got'); | 76 | 76 | c.end('hello'); | 77 | | - }); | | 77 | + })); | 78 | 78 | socketConnected(); | 79 | | - }).unref(); | | 79 | + })).unref(); | 80 | 80 | server.listen(0, common.localhostIPv4, () => { | 81 | 81 | const { port } = server.address(); | 82 | 82 | socket = net.connect(port, common.localhostIPv4, socketConnected).unref(); | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-cluster-send-handle-large-payload.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,10 +23,9 @@ if (cluster.isPrimary) { | 23 | 23 | server.listen(0, common.mustCall(() => { | 24 | 24 | const port = server.address().port; | 25 | 25 | const socket = new net.Socket(); | 26 | | - socket.connect(port, (err) => { | 27 | | - assert.ifError(err); | | 26 | + socket.connect(port, common.mustSucceed(() => { | 28 | 27 | worker.send({ payload }, socket); | 29 | | - }); | | 28 | + })); | 30 | 29 | })); | 31 | 30 | } else { | 32 | 31 | process.on('message', common.mustCall(({ payload: received }, handle) => { | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-debugger-pid.js +2-6Lines changed: 2 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ const { spawn } = require('child_process'); | 11 | 11 |
| 12 | 12 | const script = fixtures.path('debugger', 'alive.js'); | 13 | 13 |
| 14 | | -const runTest = async () => { | | 14 | +(async () => { | 15 | 15 | const target = spawn(process.execPath, [script]); | 16 | 16 | const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false }); | 17 | 17 |
| @@ -24,12 +24,8 @@ const runTest = async () => { | 24 | 24 | cli.output, | 25 | 25 | /> 3 {3}\+\+x;/, | 26 | 26 | 'marks the 3rd line'); | 27 | | - } catch (error) { | 28 | | - assert.ifError(error); | 29 | 27 | } finally { | 30 | 28 | await cli.quit(); | 31 | 29 | target.kill(); | 32 | 30 | } | 33 | | -}; | 34 | | - | 35 | | -runTest().then(common.mustCall()); | | 31 | +})().then(common.mustCall()); |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-deprecation-flags.js +13-19Lines changed: 13 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | 21 |
| 22 | 22 | 'use strict'; | 23 | | -require('../common'); | | 23 | +const common = require('../common'); | 24 | 24 | const fixtures = require('../common/fixtures'); | 25 | 25 | const assert = require('assert'); | 26 | 26 | const execFile = require('child_process').execFile; | @@ -40,49 +40,43 @@ const normal = [depmod]; | 40 | 40 | const noDep = ['--no-deprecation', depmod]; | 41 | 41 | const traceDep = ['--trace-deprecation', depmod]; | 42 | 42 |
| 43 | | -execFile(node, normal, function(er, stdout, stderr) { | | 43 | +execFile(node, normal, common.mustSucceed((stdout, stderr) => { | 44 | 44 | console.error('normal: show deprecation warning'); | 45 | | - assert.strictEqual(er, null); | 46 | 45 | assert.strictEqual(stdout, ''); | 47 | 46 | assert.match(stderr, /this function is deprecated/); | 48 | 47 | console.log('normal ok'); | 49 | | -}); | | 48 | +})); | 50 | 49 |
| 51 | | -execFile(node, noDep, function(er, stdout, stderr) { | | 50 | +execFile(node, noDep, common.mustSucceed((stdout, stderr) => { | 52 | 51 | console.error('--no-deprecation: silence deprecations'); | 53 | | - assert.strictEqual(er, null); | 54 | 52 | assert.strictEqual(stdout, ''); | 55 | 53 | assert.strictEqual(stderr.trim(), 'This is deprecated'); | 56 | 54 | console.log('silent ok'); | 57 | | -}); | | 55 | +})); | 58 | 56 |
| 59 | | -execFile(node, traceDep, function(er, stdout, stderr) { | | 57 | +execFile(node, traceDep, common.mustSucceed((stdout, stderr) => { | 60 | 58 | console.error('--trace-deprecation: show stack'); | 61 | | - assert.strictEqual(er, null); | 62 | 59 | assert.strictEqual(stdout, ''); | 63 | 60 | const stack = stderr.trim().split('\n'); | 64 | 61 | // Just check the top and bottom. | 65 | 62 | assert.match(stack[1], /this function is deprecated/); | 66 | 63 | assert.match(stack[0], /This is deprecated/); | 67 | 64 | console.log('trace ok'); | 68 | | -}); | | 65 | +})); | 69 | 66 |
| 70 | | -execFile(node, [depUserlandFunction], function(er, stdout, stderr) { | | 67 | +execFile(node, [depUserlandFunction], common.mustSucceed((stdout, stderr) => { | 71 | 68 | console.error('normal: testing deprecated userland function'); | 72 | | - assert.strictEqual(er, null); | 73 | 69 | assert.strictEqual(stdout, ''); | 74 | 70 | assert.match(stderr, /deprecatedFunction is deprecated/); | 75 | 71 | console.error('normal: ok'); | 76 | | -}); | | 72 | +})); | 77 | 73 |
| 78 | | -execFile(node, [depUserlandClass], function(er, stdout, stderr) { | 79 | | - assert.strictEqual(er, null); | | 74 | +execFile(node, [depUserlandClass], common.mustSucceed((stdout, stderr) => { | 80 | 75 | assert.strictEqual(stdout, ''); | 81 | 76 | assert.match(stderr, /deprecatedClass is deprecated/); | 82 | | -}); | | 77 | +})); | 83 | 78 |
| 84 | | -execFile(node, [depUserlandSubClass], function(er, stdout, stderr) { | 85 | | - assert.strictEqual(er, null); | | 79 | +execFile(node, [depUserlandSubClass], common.mustSucceed((stdout, stderr) => { | 86 | 80 | assert.strictEqual(stdout, ''); | 87 | 81 | assert.match(stderr, /deprecatedClass is deprecated/); | 88 | | -}); | | 82 | +})); |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-dgram-pingpong.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,17 +14,17 @@ function pingPongTest(port, host) { | 14 | 14 | throw e; | 15 | 15 | }); | 16 | 16 |
| 17 | | - server.on('listening', function() { | | 17 | + server.on('listening', common.mustCall(() => { | 18 | 18 | console.log(`server listening on ${port}`); | 19 | 19 |
| 20 | 20 | const client = dgram.createSocket('udp4'); | 21 | 21 |
| 22 | | - client.on('message', function(msg) { | | 22 | + client.on('message', common.mustCall((msg) => { | 23 | 23 | assert.strictEqual(msg.toString('ascii'), 'PONG'); | 24 | 24 |
| 25 | 25 | client.close(); | 26 | 26 | server.close(); | 27 | | - }); | | 27 | + })); | 28 | 28 |
| 29 | 29 | client.on('error', function(e) { | 30 | 30 | throw e; | @@ -37,7 +37,7 @@ function pingPongTest(port, host) { | 37 | 37 | } | 38 | 38 |
| 39 | 39 | clientSend(); | 40 | | - }); | | 40 | + })); | 41 | 41 | server.bind(port, host); | 42 | 42 | return server; | 43 | 43 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-fs-readdir-recursive.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,11 +134,11 @@ function assertDirents(dirents) { | 134 | 134 | assert.strictEqual(dirents.length, expected.length); | 135 | 135 | dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1)); | 136 | 136 | assert.deepStrictEqual( | 137 | | - dirents.map((dirent) => { | | 137 | + dirents.map(common.mustCallAtLeast((dirent) => { | 138 | 138 | assert(dirent instanceof fs.Dirent); | 139 | 139 | assert.notStrictEqual(dirent.name, undefined); | 140 | 140 | return getDirentPath(dirent); | 141 | | - }), | | 141 | + })), | 142 | 142 | expected | 143 | 143 | ); | 144 | 144 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-heapdump-flag-custom-dir.js +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ if (common.isWindows) | 7 | 7 |
| 8 | 8 | const assert = require('assert'); | 9 | 9 |
| 10 | | -const validateHeapSnapshotFile = () => { | | 10 | +if (process.argv[2] === 'child') { | 11 | 11 | const fs = require('fs'); | 12 | 12 |
| 13 | 13 | assert.strictEqual(process.listenerCount('SIGUSR2'), 1); | @@ -31,10 +31,6 @@ const validateHeapSnapshotFile = () => { | 31 | 31 | JSON.parse(fs.readFileSync(files[i])); | 32 | 32 | } | 33 | 33 | })(); | 34 | | -}; | 35 | | - | 36 | | -if (process.argv[2] === 'child') { | 37 | | - validateHeapSnapshotFile(); | 38 | 34 | } else { | 39 | 35 | // Modify the timezone. So we can check the file date string still returning correctly. | 40 | 36 | process.env.TZ = 'America/New_York'; | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-http-econnrefused.js +10-10Lines changed: 10 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,20 +32,20 @@ const common = require('../common'); | 32 | 32 | const http = require('http'); | 33 | 33 | const assert = require('assert'); | 34 | 34 |
| 35 | | -const server = http.createServer(function(req, res) { | | 35 | +const server = http.createServer(common.mustCallAtLeast((req, res) => { | 36 | 36 | let body = ''; | 37 | 37 |
| 38 | 38 | req.setEncoding('utf8'); | 39 | 39 | req.on('data', function(chunk) { | 40 | 40 | body += chunk; | 41 | 41 | }); | 42 | 42 |
| 43 | | - req.on('end', function() { | | 43 | + req.on('end', common.mustCall(() => { | 44 | 44 | assert.strictEqual(body, 'PING'); | 45 | 45 | res.writeHead(200, { 'Connection': 'close' }); | 46 | 46 | res.end('PONG'); | 47 | | - }); | 48 | | -}); | | 47 | + })); | | 48 | +})); | 49 | 49 |
| 50 | 50 |
| 51 | 51 | server.on('listening', pingping); | @@ -109,36 +109,36 @@ function ping() { | 109 | 109 | method: 'POST' | 110 | 110 | }; | 111 | 111 |
| 112 | | - const req = http.request(opt, function(res) { | | 112 | + const req = http.request(opt, common.mustCallAtLeast((res) => { | 113 | 113 | let body = ''; | 114 | 114 |
| 115 | 115 | res.setEncoding('utf8'); | 116 | 116 | res.on('data', function(chunk) { | 117 | 117 | body += chunk; | 118 | 118 | }); | 119 | 119 |
| 120 | | - res.on('end', function() { | | 120 | + res.on('end', common.mustCall(() => { | 121 | 121 | assert.strictEqual(body, 'PONG'); | 122 | 122 | assert.ok(!hadError); | 123 | 123 | gotEnd = true; | 124 | 124 | afterPing('success'); | 125 | | - }); | 126 | | - }); | | 125 | + })); | | 126 | + }, 0)); | 127 | 127 |
| 128 | 128 | req.end('PING'); | 129 | 129 |
| 130 | 130 | let gotEnd = false; | 131 | 131 | let hadError = false; | 132 | 132 |
| 133 | | - req.on('error', function(error) { | | 133 | + req.on('error', common.mustCallAtLeast((error) => { | 134 | 134 | console.log(`Error making ping req: ${error}`); | 135 | 135 | hadError = true; | 136 | 136 | assert.ok(!gotEnd); | 137 | 137 |
| 138 | 138 | // Family autoselection might be skipped if only a single address is returned by DNS. | 139 | 139 | const actualError = Array.isArray(error.errors) ? error.errors[0] : error; | 140 | 140 | afterPing(actualError.message); | 141 | | - }); | | 141 | + }, 0)); | 142 | 142 | } | 143 | 143 |
| 144 | 144 |
| |
|