Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
lib,test: disable pretty error messages for chakracore
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhorton committed Feb 3, 2018
1 parent b2f3964 commit c5a23c4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function innerOk(args, fn) {
throw new errors.TypeError('ERR_MISSING_ARGS', 'value');

if (!value) {
if (message == null) {
if (message == null && process.jsEngine !== 'chakracore') {
// Use the call as error message if possible.
// This does not work with e.g. the repl.
const err = new Error();
Expand Down Expand Up @@ -211,7 +211,7 @@ function innerOk(args, fn) {
expected: true,
message,
operator: '==',
stackStartFn: fn
stackStartFn: process.jsEngine === 'chakracore' ? ok : fn
});
}
}
Expand Down
59 changes: 40 additions & 19 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,18 @@ common.expectsError(
}
);

// https://github.com/nodejs/node/pull/17581 added functionality to
// lib/assert.js that made assert messages much nicer.
// However, it relies on non-standard/undocumented V8 error APIs.
// Thus, there is a modification to that file to fall back to the old
// path for ChakraCore
function engineSpecificAssert(v8, cc) {
return common.engineSpecificMessage({
v8: `The expression evaluated to a falsy value:${EOL}${EOL} ${v8}`,
chakracore: cc
});
}

// Test strict assert
{
const a = require('assert');
Expand Down Expand Up @@ -781,8 +793,10 @@ 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: engineSpecificAssert(
`assert.ok(typeof 123 === 'string')${EOL}`,
'false == true'
)
}
);
Error.stackTraceLimit = tmpLimit;
Expand All @@ -793,25 +807,26 @@ common.expectsError(
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert.ok(null)${EOL}`
message: engineSpecificAssert(`assert.ok(null)${EOL}`, 'null == true')
}
);
common.expectsError(
() => assert(typeof 123 === 'string'),
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert(typeof 123 === 'string')${EOL}`
message: engineSpecificAssert(
`assert(typeof 123 === 'string')${EOL}`,
'false == true'
)
}
);

{
// Test caching
const fs = process.binding('fs');
const tmp = fs.close;
fs.close = common.mustCall(tmp, 1);
fs.close = common.mustCall(tmp, process.jsEngine === 'chakracore' ? 0 : 1);
function throwErr() {
// eslint-disable-next-line prefer-assert-methods
assert(
Expand All @@ -823,17 +838,21 @@ 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: engineSpecificAssert(
`assert(Buffer.from('test') instanceof Error)${EOL}`,
'false == true'
)
}
);
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: engineSpecificAssert(
`assert(Buffer.from('test') instanceof Error)${EOL}`,
'false == true'
)
}
);
fs.close = tmp;
Expand All @@ -852,12 +871,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: engineSpecificAssert(`assert((() => 'string')()${EOL}` +
` // eslint-disable-next-line${EOL}` +
` ===${EOL}` +
` 123 instanceof${EOL}` +
` Buffer)${EOL}`,
'false == true')
}
);

Expand All @@ -866,8 +885,10 @@ common.expectsError(
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: `The expression evaluated to a falsy value:${EOL}${EOL} ` +
`assert(null, undefined)${EOL}`
message: engineSpecificAssert(
`assert(null, undefined)${EOL}`,
'null == true'
)
}
);

Expand Down

0 comments on commit c5a23c4

Please sign in to comment.