test: fix actual and expected order

In addition use the newer common.expectsError version.

PR-URL: https://github.com/nodejs/node/pull/14881
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Ruben Bridgewater 2017-09-13 14:32:50 -03:00
parent e3f4305c25
commit 8f52ccc828
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -26,8 +26,8 @@ const assert = require('assert');
assert.ok(process.stdout.writable); assert.ok(process.stdout.writable);
assert.ok(process.stderr.writable); assert.ok(process.stderr.writable);
// Support legacy API // Support legacy API
assert.strictEqual('number', typeof process.stdout.fd); assert.strictEqual(typeof process.stdout.fd, 'number');
assert.strictEqual('number', typeof process.stderr.fd); assert.strictEqual(typeof process.stderr.fd, 'number');
assert.doesNotThrow(function() { assert.doesNotThrow(function() {
process.once('warning', common.mustCall((warning) => { process.once('warning', common.mustCall((warning) => {
@ -143,19 +143,19 @@ const expectedStrings = [
]; ];
for (const expected of expectedStrings) { for (const expected of expectedStrings) {
assert.strictEqual(`${expected}\n`, strings.shift()); assert.strictEqual(strings.shift(), `${expected}\n`);
assert.strictEqual(`${expected}\n`, errStrings.shift()); assert.strictEqual(errStrings.shift(), `${expected}\n`);
} }
for (const expected of expectedStrings) { for (const expected of expectedStrings) {
assert.strictEqual(`${expected}\n`, strings.shift()); assert.strictEqual(strings.shift(), `${expected}\n`);
assert.strictEqual(`${expected}\n`, errStrings.shift()); assert.strictEqual(errStrings.shift(), `${expected}\n`);
} }
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n", assert.strictEqual(strings.shift(),
strings.shift()); "{ foo: 'bar', inspect: [Function: inspect] }\n");
assert.strictEqual("{ foo: 'bar', inspect: [Function: inspect] }\n", assert.strictEqual(strings.shift(),
strings.shift()); "{ foo: 'bar', inspect: [Function: inspect] }\n");
assert.ok(strings.shift().includes('foo: [Object]')); assert.ok(strings.shift().includes('foo: [Object]'));
assert.strictEqual(strings.shift().includes('baz'), false); assert.strictEqual(strings.shift().includes('baz'), false);
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim())); assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim()));
@ -163,15 +163,15 @@ assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim())); assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.ok(/^hasOwnProperty: \d+\.\d{3}ms$/.test(strings.shift().trim())); assert.ok(/^hasOwnProperty: \d+\.\d{3}ms$/.test(strings.shift().trim()));
assert.strictEqual('Trace: This is a {"formatted":"trace"} 10 foo', assert.strictEqual(errStrings.shift().split('\n').shift(),
errStrings.shift().split('\n').shift()); 'Trace: This is a {"formatted":"trace"} 10 foo');
assert.throws(() => { common.expectsError(() => {
console.assert(false, 'should throw'); console.assert(false, 'should throw');
}, common.expectsError({ }, {
code: 'ERR_ASSERTION', code: 'ERR_ASSERTION',
message: /^should throw$/ message: /^should throw$/
})); });
assert.doesNotThrow(() => { assert.doesNotThrow(() => {
console.assert(true, 'this should not throw'); console.assert(true, 'this should not throw');