From 636b82f91aa20adfcca5ef9c1d22a61c6213c7fa Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Thu, 2 Jun 2016 19:39:34 +0100 Subject: [PATCH] Fixed "ReferenceError: dbg is not defined" error when 'dbg' global variable doesn't exist. Remove dependancy on --expose_debug_as=dbg switch and 'dbg' global variable. Instead use: vm.runInDebugContext('Debug'). Return 1 based column number for VS editor (findFunctionSourceLocation returns 0 based column number of function's parameters). --- .../ExportRunner/exportrunner.js | 20 +++++++++++++------ .../TestFrameworks/TestFramework.cs | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Nodejs/Product/Nodejs/TestFrameworks/ExportRunner/exportrunner.js b/Nodejs/Product/Nodejs/TestFrameworks/ExportRunner/exportrunner.js index 6f941e82b..42a8b71e5 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/ExportRunner/exportrunner.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/ExportRunner/exportrunner.js @@ -1,7 +1,15 @@ var fs = require('fs'); var path = require('path'); +var vm = require('vm'); var find_tests = function (testFileList, discoverResultFile) { + var debug; + try { + debug = vm.runInDebugContext('Debug'); + } catch (ex) { + console.error("NTVS_ERROR:", ex); + } + var testList = []; testFileList.split(';').forEach(function (testFile) { var testCases; @@ -13,16 +21,16 @@ var find_tests = function (testFileList, discoverResultFile) { return; } for (var test in testCases) { - var line = 0; - var column = 0; - if (dbg != undefined) { + var line = 1; // line 0 doesn't exist in editor + var column = 1; + if (debug !== undefined) { try { - var funcDetails = dbg.Debug.findFunctionSourceLocation(testCases[test]); + var funcDetails = debug.findFunctionSourceLocation(testCases[test]); if (funcDetails != undefined) { //v8 is 0 based line numbers, editor is 1 based line = parseInt(funcDetails.line) + 1; - //v8 and editor are both 1 based column numbers, no adjustment necessary - column = parseInt(funcDetails.column); + //v8 is 0 based column numbers, editor is 1 based + column = parseInt(funcDetails.column) + 1; } } catch (e) { //If we take an exception mapping the source line, simply fallback to unknown source map diff --git a/Nodejs/Product/TestAdapter/TestFrameworks/TestFramework.cs b/Nodejs/Product/TestAdapter/TestFrameworks/TestFramework.cs index 6b9c663a8..c5220059c 100644 --- a/Nodejs/Product/TestAdapter/TestFrameworks/TestFramework.cs +++ b/Nodejs/Product/TestAdapter/TestFrameworks/TestFramework.cs @@ -122,7 +122,7 @@ private string WrapTestNameWithQuotes(string testName) { private string EvaluateJavaScript(string nodeExePath, string testFile, string discoverResultFile, IMessageLogger logger, string workingDirectory) { workingDirectory = workingDirectory.TrimEnd(new char['\\']); - string arguments = "--expose_debug_as=dbg " + WrapWithQuotes(_findTestsScriptFile) + string arguments = WrapWithQuotes(_findTestsScriptFile) + " " + Name + " " + WrapWithQuotes(testFile) + " " + WrapWithQuotes(discoverResultFile) +