From 79e183186c1d18aab6911f9c5e4d187f371952e5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 17 Oct 2017 16:11:17 -0700 Subject: [PATCH] test: make error stack test engine agnostic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revise test-internal-util-decorate-error-stack so that it does not depend on behavior specific to V8. PR-URL: https://github.com/nodejs/node/pull/16272 Reviewed-By: Michaël Zasso Reviewed-By: Refael Ackermann Reviewed-By: Yuta Hiroto Reviewed-By: Joyee Cheung Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Tobias Nießen --- .../test-internal-util-decorate-error-stack.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-internal-util-decorate-error-stack.js b/test/parallel/test-internal-util-decorate-error-stack.js index d428e3c7ee2a7b..b5670135a028ad 100644 --- a/test/parallel/test-internal-util-decorate-error-stack.js +++ b/test/parallel/test-internal-util-decorate-error-stack.js @@ -24,11 +24,16 @@ const obj = {}; decorateErrorStack(obj); assert.strictEqual(obj.stack, undefined); -// Verify that the stack is decorated when possible +// Verify that the stack is decorated when possible. function checkStack(stack) { - const matches = stack.match(/var foo bar;/g); - assert.strictEqual(Array.isArray(matches), true); - assert.strictEqual(matches.length, 1); + // Matching only on a minimal piece of the stack because the string will vary + // greatly depending on the JavaScript engine. V8 includes `;` because it + // displays the line of code (`var foo bar;`) that is causing a problem. + // ChakraCore does not display the line of code but includes `;` in the phrase + // `Expected ';' `. + assert.ok(/;/g.test(stack)); + // Test that it's a multiline string. + assert.ok(/\n/g.test(stack)); } let err; const badSyntaxPath =