From 93c410781b3bcb92b686f38002caa51013c6d630 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 17 Feb 2020 23:56:58 +0100 Subject: [PATCH] fixup: test --- test/parallel/test-fs-write-stream.js | 11 +++++------ test/parallel/test-net-socket-write-error.js | 12 ++++++------ test/parallel/test-net-write-arguments.js | 20 ++++++++++---------- test/parallel/test-stream2-writable.js | 12 ++++++------ test/parallel/test-zlib-invalid-input.js | 8 ++++---- test/parallel/test-zlib-object-write.js | 11 ++++++----- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/test/parallel/test-fs-write-stream.js b/test/parallel/test-fs-write-stream.js index f84b727c8662f8..9f422a644379e8 100644 --- a/test/parallel/test-fs-write-stream.js +++ b/test/parallel/test-fs-write-stream.js @@ -56,13 +56,12 @@ tmpdir.refresh(); // Throws if data is not of type Buffer. { const stream = fs.createWriteStream(file); - stream.on('error', common.expectsError({ + stream.on('error', common.mustNotCall()); + assert.throws(() => { + stream.write(42); + }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' - })); - stream.write(42, null, common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - })); + }); stream.destroy(); } diff --git a/test/parallel/test-net-socket-write-error.js b/test/parallel/test-net-socket-write-error.js index ab748480ea3c52..e68db68c0d4939 100644 --- a/test/parallel/test-net-socket-write-error.js +++ b/test/parallel/test-net-socket-write-error.js @@ -2,19 +2,19 @@ const common = require('../common'); const net = require('net'); +const assert = require('assert'); const server = net.createServer().listen(0, connectToServer); function connectToServer() { const client = net.createConnection(this.address().port, () => { - client.write(1337, common.expectsError({ + client.on('error', common.mustNotCall()); + assert.throws(() => { + client.write(1337); + }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' - })); - client.on('error', common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - name: 'TypeError' - })); + }); client.destroy(); }) diff --git a/test/parallel/test-net-write-arguments.js b/test/parallel/test-net-write-arguments.js index 407871afe6d3b3..2b81ed7d6a3634 100644 --- a/test/parallel/test-net-write-arguments.js +++ b/test/parallel/test-net-write-arguments.js @@ -1,20 +1,18 @@ 'use strict'; const common = require('../common'); const net = require('net'); - +const assert = require('assert'); const socket = net.Stream({ highWaterMark: 0 }); // Make sure that anything besides a buffer or a string throws. -socket.write(null, common.expectsError({ +socket.on('error', common.mustNotCall()); +assert.throws(() => { + socket.write(null); +}, { code: 'ERR_STREAM_NULL_VALUES', name: 'TypeError', message: 'May not write null values to stream' -})); -socket.on('error', common.expectsError({ - code: 'ERR_STREAM_NULL_VALUES', - name: 'TypeError', - message: 'May not write null values to stream' -})); +}); [ true, @@ -29,10 +27,12 @@ socket.on('error', common.expectsError({ ].forEach((value) => { // We need to check the callback since 'error' will only // be emitted once per instance. - socket.write(value, common.expectsError({ + assert.throws(() => { + socket.write(value); + }, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', message: 'The "chunk" argument must be of type string or an instance of ' + `Buffer or Uint8Array.${common.invalidArgTypeHelper(value)}` - })); + }); }); diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 0d9bc03fae7a94..03835bb1bd0465 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -422,12 +422,12 @@ const helloWorldBuffer = Buffer.from('hello world'); { // Verify that error is only emitted once when failing in write. const w = new W(); - w.on('error', common.mustCall((err) => { - assert.strictEqual(w._writableState.errorEmitted, true); - assert.strictEqual(err.code, 'ERR_STREAM_NULL_VALUES'); - })); - w.write(null); - w.destroy(new Error()); + w.on('error', common.mustNotCall()); + assert.throws(() => { + w.write(null); + }, { + code: 'ERR_STREAM_NULL_VALUES' + }); } { diff --git a/test/parallel/test-zlib-invalid-input.js b/test/parallel/test-zlib-invalid-input.js index 68fa3825b91ced..bd43499ce1d1f0 100644 --- a/test/parallel/test-zlib-invalid-input.js +++ b/test/parallel/test-zlib-invalid-input.js @@ -43,10 +43,10 @@ const unzips = [ ]; nonStringInputs.forEach(common.mustCall((input) => { - // zlib.gunzip should not throw an error when called with bad input. - zlib.gunzip(input, (err, buffer) => { - // zlib.gunzip should pass the error to the callback. - assert.ok(err); + assert.throws(() => { + zlib.gunzip(input); + }, { + name: 'TypeError' }); }, nonStringInputs.length)); diff --git a/test/parallel/test-zlib-object-write.js b/test/parallel/test-zlib-object-write.js index df533d77b3fcdd..9b9b329cfae9e6 100644 --- a/test/parallel/test-zlib-object-write.js +++ b/test/parallel/test-zlib-object-write.js @@ -1,12 +1,13 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); const { Gunzip } = require('zlib'); const gunzip = new Gunzip({ objectMode: true }); -gunzip.write({}, common.expectsError({ +gunzip.on('error', common.mustNotCall()); +assert.throws(() => { + gunzip.write({}); +}, { name: 'TypeError' -})); -gunzip.on('error', common.expectsError({ - name: 'TypeError' -})); +});