0
votes

I'm trying to get VSTS to run my Mocha unit tests, similar to how I've got them running in VS 2017.

I'm installed the Node JS Tools for Visual Studio and VS Test Explorer (after a restart) picks up the tests, and runs them.

But I can't get a VSTS build task to run them ???

Tried going through the notes on NTVS about running tests in VSTS but no joy getting it to work.

Moved onto the section about troubleshooting, and seeing if I can run the tests using my local vstest.console.exe ...

So far trying to run vstest ...

  • Error: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\Node.js Tools\Microsoft.NodejsTools.targets" was not found
  • quick fix ... added a copy of directory ... C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Node.js Tools ... to ... C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0
  • Error: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found
  • quick fix ... added a copy of directory ... C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets ... to ... C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0
  • Error: Could not find a part of the path C:\Repos\smc\BasicAzureExpress\BasicAzureExpress\ntvs\TestFrameworks
  • quick fix ... amend .nsproj to VS 2017 ... <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion> and a directory \TestFrameworks under \ntvs

... and then have the error ... Error: Missing generic test framework

So I'm left puzzled as to why VS 2017 can run the tests, but vstest.console.exe won't

1
Do you use Hosted VS 2017 agent? Try to specify vstest.console.exe path in Visual Studio Test task. (C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform)starian chen-MSFT
Note: You need to install test agent 2017.starian chen-MSFT
What's the result after trying my solution?starian chen-MSFT
@starain-MSFT Sorry, dragged off on urgent fix, so had to shelf investigation. Hope to get back to it next week.SteveC

1 Answers

0
votes

First, the VSToolsPath value is empty if running in command line, then uses $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) path, but there aren’t necessary files of nodejs tool.

You can modify it like this (change Community to Professional if you are using vs2017 Professional):

<!--<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>-->
    <VSToolsPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0</VSToolsPath>

Secondly, refer to these steps to run test on Hosted VS 2017 agent.

  1. Modify project file (njsproj)

<!--<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>-->
    <VSToolsPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0</VSToolsPath>
  1. Copy NodeJsTools content in C:\Program Files (x86)\Microsoft Visual Studio\2017[Community, professional or enterprise]\Common7\IDE\Extensions\Microsoft to your ntvs folder
  2. Add these files to source control and check in changes
  3. Queue build with Hosted VS 2017 agent.