Skip to content

Commit 2c33819

Browse files
cjihrigsilverwind
authored andcommitted
test: fix tests that check error messages
20285ad changed the format of error messages throughout lib. However, the tests were not updated to reflect these changes. This commit makes those changes. PR-URL: #3727 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7b89a3d commit 2c33819

27 files changed

+63
-63
lines changed

lib/path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ posix.extname = function(path) {
566566
posix.format = function(pathObject) {
567567
if (pathObject === null || typeof pathObject !== 'object') {
568568
throw new TypeError(
569-
"Parameter 'pathObject' must be an object, not " + typeof pathObject
569+
'Parameter "pathObject" must be an object, not ' + typeof pathObject
570570
);
571571
}
572572

test/parallel/test-assert.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ function testBlockTypeError(method, block) {
438438
method(block);
439439
threw = false;
440440
} catch (e) {
441-
assert.equal(e.toString(), 'TypeError: block must be a function');
441+
assert.equal(e.toString(),
442+
'TypeError: "block" argument must be a function');
442443
}
443444

444445
assert.ok(threw);

test/parallel/test-buffer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1222,11 +1222,11 @@ assert.throws(function() {
12221222

12231223
assert.throws(function() {
12241224
new Buffer();
1225-
}, /must start with number, buffer, array or string/);
1225+
}, /Must start with number, buffer, array or string/);
12261226

12271227
assert.throws(function() {
12281228
new Buffer(null);
1229-
}, /must start with number, buffer, array or string/);
1229+
}, /Must start with number, buffer, array or string/);
12301230

12311231

12321232
// Test prototype getters don't throw

test/parallel/test-child-process-spawn-typeerror.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const common = require('../common');
88
const cmd = common.isWindows ? 'rundll32' : 'ls';
99
const invalidcmd = 'hopefully_you_dont_have_this_on_your_machine';
1010
const invalidArgsMsg = /Incorrect value of args option/;
11-
const invalidOptionsMsg = /options argument must be an object/;
11+
const invalidOptionsMsg = /"options" argument must be an object/;
1212
const empty = common.fixturesDir + '/empty.js';
1313

1414
assert.throws(function() {

test/parallel/test-file-write-stream3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function run_test_4() {
178178
function() {
179179
file = fs.createWriteStream(filepath, options);
180180
},
181-
/start must be/
181+
/"start" must be/
182182
);
183183

184184
}

test/parallel/test-fs-access.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ assert.throws(function() {
9696

9797
assert.throws(function() {
9898
fs.access(__filename, fs.F_OK);
99-
}, /callback must be a function/);
99+
}, /"callback" argument must be a function/);
100100

101101
assert.throws(function() {
102102
fs.access(__filename, fs.F_OK, {});
103-
}, /callback must be a function/);
103+
}, /"callback" argument must be a function/);
104104

105105
assert.doesNotThrow(function() {
106106
fs.accessSync(__filename);

test/parallel/test-fs-null-bytes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var assert = require('assert');
44
var fs = require('fs');
55

66
function check(async, sync) {
7-
var expected = /Path must be a string without null bytes./;
7+
var expected = /Path must be a string without null bytes/;
88
var argsSync = Array.prototype.slice.call(arguments, 2);
99
var argsAsync = argsSync.concat(function(er) {
1010
assert(er && er.message.match(expected));

test/parallel/test-fs-read-buffer-tostring-fail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ stream.on('finish', common.mustCall(function() {
2929
fd = fs.openSync(file, 'r');
3030
fs.read(fd, kStringMaxLength + 1, 0, 'utf8', common.mustCall(function(err) {
3131
assert.ok(err instanceof Error);
32-
assert.strictEqual('toString failed', err.message);
32+
assert.strictEqual('"toString()" failed', err.message);
3333
}));
3434
}));
3535

test/parallel/test-fs-read-stream-inherit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ file6.on('end', function() {
114114

115115
assert.throws(function() {
116116
fs.createReadStream(rangeFile, Object.create({start: 10, end: 2}));
117-
}, /start must be <= end/);
117+
}, /"start" option must be <= "end" option/);
118118

119119
var stream = fs.createReadStream(rangeFile, Object.create({ start: 0,
120120
end: 0 }));

test/parallel/test-fs-read-stream-throw-type-error.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ assert.doesNotThrow(function() {
1818

1919
assert.throws(function() {
2020
fs.createReadStream(example, null);
21-
}, /options must be a string or an object/);
21+
}, /"options" argument must be a string or an object/);
2222
assert.throws(function() {
2323
fs.createReadStream(example, 123);
24-
}, /options must be a string or an object/);
24+
}, /"options" argument must be a string or an object/);
2525
assert.throws(function() {
2626
fs.createReadStream(example, 0);
27-
}, /options must be a string or an object/);
27+
}, /"options" argument must be a string or an object/);
2828
assert.throws(function() {
2929
fs.createReadStream(example, true);
30-
}, /options must be a string or an object/);
30+
}, /"options" argument must be a string or an object/);
3131
assert.throws(function() {
3232
fs.createReadStream(example, false);
33-
}, /options must be a string or an object/);
33+
}, /"options" argument must be a string or an object/);

test/parallel/test-fs-read-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ file6.on('end', function() {
107107

108108
assert.throws(function() {
109109
fs.createReadStream(rangeFile, {start: 10, end: 2});
110-
}, /start must be <= end/);
110+
}, /"start" option must be <= "end" option/);
111111

112112
var stream = fs.createReadStream(rangeFile, { start: 0, end: 0 });
113113
stream.data = '';

test/parallel/test-fs-readfile-tostring-fail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ stream.on('finish', common.mustCall(function() {
2525
// make sure that the toString does not throw an error
2626
fs.readFile(file, 'utf8', common.mustCall(function(err, buf) {
2727
assert.ok(err instanceof Error);
28-
assert.strictEqual('toString failed', err.message);
28+
assert.strictEqual('"toString()" failed', err.message);
2929
}));
3030
}));
3131

test/parallel/test-fs-watchfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const assert = require('assert');
88
// Basic usage tests.
99
assert.throws(function() {
1010
fs.watchFile('./some-file');
11-
}, /watchFile requires a listener function/);
11+
}, /"watchFile\(\)" requires a listener function/);
1212

1313
assert.throws(function() {
1414
fs.watchFile('./another-file', {}, 'bad listener');
15-
}, /watchFile requires a listener function/);
15+
}, /"watchFile\(\)" requires a listener function/);
1616

1717
assert.throws(function() {
1818
fs.watchFile(new Object(), function() {});

test/parallel/test-fs-write-stream-throw-type-error.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ assert.doesNotThrow(function() {
2020

2121
assert.throws(function() {
2222
fs.createWriteStream(example, null);
23-
}, /options must be a string or an object/);
23+
}, /"options" argument must be a string or an object/);
2424
assert.throws(function() {
2525
fs.createWriteStream(example, 123);
26-
}, /options must be a string or an object/);
26+
}, /"options" argument must be a string or an object/);
2727
assert.throws(function() {
2828
fs.createWriteStream(example, 0);
29-
}, /options must be a string or an object/);
29+
}, /"options" argument must be a string or an object/);
3030
assert.throws(function() {
3131
fs.createWriteStream(example, true);
32-
}, /options must be a string or an object/);
32+
}, /"options" argument must be a string or an object/);
3333
assert.throws(function() {
3434
fs.createWriteStream(example, false);
35-
}, /options must be a string or an object/);
35+
}, /"options" argument must be a string or an object/);

test/parallel/test-http-url.parse-only-support-http-https-protocol.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ assert.throws(function() {
1010
}, function(err) {
1111
if (err instanceof Error) {
1212
assert.strictEqual(err.message, 'Protocol "file:" not supported.' +
13-
' Expected "http:".');
13+
' Expected "http:"');
1414
return true;
1515
}
1616
});
@@ -20,7 +20,7 @@ assert.throws(function() {
2020
}, function(err) {
2121
if (err instanceof Error) {
2222
assert.strictEqual(err.message, 'Protocol "mailto:" not supported.' +
23-
' Expected "http:".');
23+
' Expected "http:"');
2424
return true;
2525
}
2626
});
@@ -30,7 +30,7 @@ assert.throws(function() {
3030
}, function(err) {
3131
if (err instanceof Error) {
3232
assert.strictEqual(err.message, 'Protocol "ftp:" not supported.' +
33-
' Expected "http:".');
33+
' Expected "http:"');
3434
return true;
3535
}
3636
});
@@ -40,7 +40,7 @@ assert.throws(function() {
4040
}, function(err) {
4141
if (err instanceof Error) {
4242
assert.strictEqual(err.message, 'Protocol "javascript:" not supported.' +
43-
' Expected "http:".');
43+
' Expected "http:"');
4444
return true;
4545
}
4646
});
@@ -50,7 +50,7 @@ assert.throws(function() {
5050
}, function(err) {
5151
if (err instanceof Error) {
5252
assert.strictEqual(err.message, 'Protocol "xmpp:" not supported.' +
53-
' Expected "http:".');
53+
' Expected "http:"');
5454
return true;
5555
}
5656
});
@@ -60,7 +60,7 @@ assert.throws(function() {
6060
}, function(err) {
6161
if (err instanceof Error) {
6262
assert.strictEqual(err.message, 'Protocol "f:" not supported.' +
63-
' Expected "http:".');
63+
' Expected "http:"');
6464
return true;
6565
}
6666
});

test/parallel/test-http-write-head.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var s = http.createServer(function(req, res) {
2525
res.setHeader('foo', undefined);
2626
} catch (e) {
2727
assert.ok(e instanceof Error);
28-
assert.equal(e.message, '`value` required in setHeader("foo", value).');
28+
assert.equal(e.message, '"value" required in setHeader("foo", value)');
2929
threw = true;
3030
}
3131
assert.ok(threw, 'Undefined value should throw');

test/parallel/test-net-create-connection.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -38,55 +38,55 @@ server.listen(tcpPort, 'localhost', function() {
3838

3939
fail({
4040
port: true
41-
}, TypeError, 'port should be a number or string: true');
41+
}, TypeError, '"port" option should be a number or string: true');
4242

4343
fail({
4444
port: false
45-
}, TypeError, 'port should be a number or string: false');
45+
}, TypeError, '"port" option should be a number or string: false');
4646

4747
fail({
4848
port: []
49-
}, TypeError, 'port should be a number or string: ');
49+
}, TypeError, '"port" option should be a number or string: ');
5050

5151
fail({
5252
port: {}
53-
}, TypeError, 'port should be a number or string: [object Object]');
53+
}, TypeError, '"port" option should be a number or string: [object Object]');
5454

5555
fail({
5656
port: null
57-
}, TypeError, 'port should be a number or string: null');
57+
}, TypeError, '"port" option should be a number or string: null');
5858

5959
fail({
6060
port: ''
61-
}, RangeError, 'port should be >= 0 and < 65536: ');
61+
}, RangeError, '"port" option should be >= 0 and < 65536: ');
6262

6363
fail({
6464
port: ' '
65-
}, RangeError, 'port should be >= 0 and < 65536: ');
65+
}, RangeError, '"port" option should be >= 0 and < 65536: ');
6666

6767
fail({
6868
port: '0x'
69-
}, RangeError, 'port should be >= 0 and < 65536: 0x');
69+
}, RangeError, '"port" option should be >= 0 and < 65536: 0x');
7070

7171
fail({
7272
port: '-0x1'
73-
}, RangeError, 'port should be >= 0 and < 65536: -0x1');
73+
}, RangeError, '"port" option should be >= 0 and < 65536: -0x1');
7474

7575
fail({
7676
port: NaN
77-
}, RangeError, 'port should be >= 0 and < 65536: NaN');
77+
}, RangeError, '"port" option should be >= 0 and < 65536: NaN');
7878

7979
fail({
8080
port: Infinity
81-
}, RangeError, 'port should be >= 0 and < 65536: Infinity');
81+
}, RangeError, '"port" option should be >= 0 and < 65536: Infinity');
8282

8383
fail({
8484
port: -1
85-
}, RangeError, 'port should be >= 0 and < 65536: -1');
85+
}, RangeError, '"port" option should be >= 0 and < 65536: -1');
8686

8787
fail({
8888
port: 65536
89-
}, RangeError, 'port should be >= 0 and < 65536: 65536');
89+
}, RangeError, '"port" option should be >= 0 and < 65536: 65536');
9090
});
9191

9292
// Try connecting to random ports, but do so once the server is closed

test/parallel/test-net-listen-port-option.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ net.Server().listen({ port: '' + common.PORT }, close);
1717
'-Infinity' ].forEach(function(port) {
1818
assert.throws(function() {
1919
net.Server().listen({ port: port }, assert.fail);
20-
}, /port should be >= 0 and < 65536/i);
20+
}, /"port" option should be >= 0 and < 65536/i);
2121
});
2222

2323
[null, true, false].forEach(function(port) {

test/parallel/test-path-parse-format.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ var errors = [
5656
{method: 'parse', input: [],
5757
message: /Path must be a string. Received undefined/},
5858
{method: 'format', input: [null],
59-
message: /Parameter 'pathObject' must be an object, not/},
59+
message: /Parameter "pathObject" must be an object, not/},
6060
{method: 'format', input: [''],
61-
message: /Parameter 'pathObject' must be an object, not string/},
61+
message: /Parameter "pathObject" must be an object, not string/},
6262
{method: 'format', input: [true],
63-
message: /Parameter 'pathObject' must be an object, not boolean/},
63+
message: /Parameter "pathObject" must be an object, not boolean/},
6464
{method: 'format', input: [1],
65-
message: /Parameter 'pathObject' must be an object, not number/},
65+
message: /Parameter "pathObject" must be an object, not number/},
6666
{method: 'format', input: [{root: true}],
67-
message: /'pathObject.root' must be a string or undefined, not boolean/},
67+
message: /"pathObject\.root" must be a string or undefined, not boolean/},
6868
{method: 'format', input: [{root: 12}],
69-
message: /'pathObject.root' must be a string or undefined, not number/},
69+
message: /"pathObject\.root" must be a string or undefined, not number/},
7070
];
7171

7272
checkParseFormat(path.win32, winPaths);

test/parallel/test-readline-interface.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function isWarned(emitter) {
222222
});
223223
}, function(err) {
224224
if (err instanceof TypeError) {
225-
if (/Argument \'completer\' must be a function/.test(err)) {
225+
if (/Argument "completer" must be a function/.test(err)) {
226226
return true;
227227
}
228228
}
@@ -380,4 +380,3 @@ function isWarned(emitter) {
380380
});
381381

382382
});
383-

test/parallel/test-stringbytes-external-exceed-max-by-1-ascii.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ const buf = new Buffer(kStringMaxLength + 1);
2020

2121
assert.throws(function() {
2222
buf.toString('ascii');
23-
}, /toString failed/);
23+
}, /"toString\(\)" failed/);

test/parallel/test-stringbytes-external-exceed-max-by-1-base64.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ const buf = new Buffer(kStringMaxLength + 1);
2020

2121
assert.throws(function() {
2222
buf.toString('base64');
23-
}, /toString failed/);
23+
}, /"toString\(\)" failed/);

test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const buf = new Buffer(kStringMaxLength + 1);
2020

2121
assert.throws(function() {
2222
buf.toString('binary');
23-
}, /toString failed/);
23+
}, /"toString\(\)" failed/);
2424

2525
var maxString = buf.toString('binary', 1);
2626
assert.equal(maxString.length, kStringMaxLength);

test/parallel/test-stringbytes-external-exceed-max-by-1-hex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ const buf = new Buffer(kStringMaxLength + 1);
2020

2121
assert.throws(function() {
2222
buf.toString('hex');
23-
}, /toString failed/);
23+
}, /"toString\(\)" failed/);

test/parallel/test-stringbytes-external-exceed-max-by-1-utf8.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const buf = new Buffer(kStringMaxLength + 1);
2020

2121
assert.throws(function() {
2222
buf.toString();
23-
}, /toString failed|Invalid array buffer length/);
23+
}, /"toString\(\)" failed|Invalid array buffer length/);
2424

2525
assert.throws(function() {
2626
buf.toString('utf8');
27-
}, /toString failed/);
27+
}, /"toString\(\)" failed/);

test/parallel/test-stringbytes-external-exceed-max.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ const buf0 = new Buffer(kStringMaxLength * 2 + 2);
2020

2121
assert.throws(function() {
2222
buf0.toString('utf16le');
23-
}, /toString failed/);
23+
}, /"toString\(\)" failed/);

0 commit comments

Comments
 (0)