Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const {
const { openSync, closeSync, readSync } = require('fs');
const { parseExpressionAt } = require('internal/deps/acorn/dist/acorn');
const { inspect } = require('util');
const { EOL } = require('os');
const { NativeModule } = require('internal/bootstrap_loaders');

// Escape control characters but not \n and \t to keep the line breaks and
Expand Down Expand Up @@ -189,7 +188,7 @@ function getErrMessage(call) {
.slice(args[0].start, args[args.length - 1].end)
.replace(escapeSequencesRegExp, escapeFn);
message = 'The expression evaluated to a falsy value:' +
`${EOL}${EOL} assert${ok}(${message})${EOL}`;
`\n\n assert${ok}(${message})\n`;
}
// Make sure to always set the cache! No matter if the message is
// undefined or not
Expand Down
37 changes: 18 additions & 19 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

const common = require('../common');
const assert = require('assert');
const { EOL } = require('os');
const EventEmitter = require('events');
const { errorCache } = require('internal/errors');
const { writeFileSync, unlinkSync } = require('fs');
Expand Down Expand Up @@ -422,8 +421,8 @@ common.expectsError(
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert.ok(typeof 123 === 'string')${EOL}`
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert.ok(typeof 123 === \'string\')\n'
}
);
Error.stackTraceLimit = tmpLimit;
Expand Down Expand Up @@ -592,8 +591,8 @@ common.expectsError(
code: 'ERR_ASSERTION',
type: assert.AssertionError,
generatedMessage: true,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert.ok(null)${EOL}`
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert.ok(null)\n'
}
);
common.expectsError(
Expand All @@ -602,8 +601,8 @@ common.expectsError(
code: 'ERR_ASSERTION',
type: assert.AssertionError,
generatedMessage: true,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert(typeof 123 === 'string')${EOL}`
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert(typeof 123 === \'string\')\n'
}
);

Expand All @@ -623,17 +622,17 @@ common.expectsError(
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert(Buffer.from('test') instanceof Error)${EOL}`
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert(Buffer.from(\'test\') instanceof Error)\n'
}
);
common.expectsError(
() => throwErr(),
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert(Buffer.from('test') instanceof Error)${EOL}`
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert(Buffer.from(\'test\') instanceof Error)\n'
}
);
fs.close = tmp;
Expand All @@ -652,12 +651,12 @@ common.expectsError(
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert((() => 'string')()${EOL}` +
` // eslint-disable-next-line${EOL}` +
` ===${EOL}` +
` 123 instanceof${EOL}` +
` Buffer)${EOL}`
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert((() => \'string\')()\n' +
' // eslint-disable-next-line\n' +
' ===\n' +
' 123 instanceof\n' +
' Buffer)\n'
}
);

Expand All @@ -666,8 +665,8 @@ common.expectsError(
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert(null, undefined)${EOL}`
message: 'The expression evaluated to a falsy value:\n\n ' +
'assert(null, undefined)\n'
}
);

Expand Down