我有一個通過Visual Studio團隊服務持續集成的Web應用程序,我想爲我的腳本代碼添加單元測試。在CTS Web應用程序中持續集成VSTS上的TypeScript單元測試
首先嚐試
起初,我試圖在我的解決方案來創建一個空白Node.js的控制檯應用程序。我寫了一些測試(用'摩卡'等等),在當地很好地工作。但正如我COMMITED解決方案,我注意到不能夠...好...構建構建服務器:
Error : web.config not found in project, to create a project to deploy to Microsoft Azure you must create an Azure Node.js project.
此消息表明的MSBuild想創造我的項目的NodeJS的部署包,即使只有我用於測試目的。浮現在腦海的第一件事是添加一個最小的web.config即使我沒有要發佈的項目的NodeJS:
Error MSB4062: The "TypeScript.Tasks.FormatLocalizedString" task could not be loaded from the assembly C:\xxx\Microsoft.TypeScript.MSBuild.2.3.3\build\\..\tools\net45\TypeScript.Tasks.dll. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
我真的沒有看到任何出路的這...
第二次嘗試
然後我試圖使用單元測試項目,而不是項目的NodeJS的。這肯定會起作用,或者我想。通過這種方法,我遇到了VS Test無法識別我的單元測試(在我的NodeJS項目中工作正常)的問題,因爲沒有選項可以使用文件屬性中存在的相應「測試框架」屬性來標記我的文件在NodeJS項目中。相反,還有的「自定義工具」默認文件選項等:
沒問題!我將直接調整.csproj文件!
<TypeScriptCompile Include="main.test.ts">
<SubType>Code</SubType>
<TestFramework>Mocha</TestFramework>
<Publish>False</Publish>
</TypeScriptCompile>
但是,唉,沒有骰子......仍然無法VS測試
問題中找到測試
什麼是最好的做法在這裏進場?有沒有我沒有想到的東西?是「第一次嘗試」是正確的,我只是沒有找到正確的選項來禁止發佈我的NodeJS應用程序?
PS
我覺得現在我的第一種方法是正確的。只是要清楚:很多東西已經工作:
- 安裝的節點工具Visual Studio中的生成服務器
- 通過VSTS中VS本地測試
- 列表項 編譯打字稿
- 運行測試上
- 運行在構建(在VSTS)
npm install
現在,所有我需要的是構建經歷:/ 我現在發現,我沒有寫完整的錯誤消息,在第一種方法的最後一個錯誤:
##[error]C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(60,5): Error MSB4062: The "TypeScript.Tasks.FormatLocalizedString" task could not be loaded from the assembly C:\Agent-PaketBuildIntern1\_work\54\s\packages\Microsoft.TypeScript.MSBuild.2.3.3\build\\..\tools\net45\TypeScript.Tasks.dll. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
所以我們在這裏看到它使用了.targets下的C文件:\程序文件(x86)\ MSBuild \ Microsoft \ VisualStudio \ v14.0 \ TypeScript \而不是...... \ packages \ Microsoft.TypeScript.MSBuild.2.3.3 \ tools下的那個工具
難道這是問題嗎?我該如何着手解決這個問題?
.njsproj文件:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<VisualStudioVersion>14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<Name>MyProjectName</Name>
<RootNamespace>MyProjectName</RootNamespace>
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>5697a590-d15f-401b-b8d8-138bbd5d3330</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>
</StartupFile>
<StartWebBrowser>False</StartWebBrowser>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
<TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
<EnableTypeScript>true</EnableTypeScript>
<StartWebBrowser>false</StartWebBrowser>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Content Include="tsconfig.json">
<SubType>Code</SubType>
</Content>
<Content Include="package.json" />
<Content Include="README.md" />
<Content Include="Web.config" />
<TypeScriptCompile Include="Scripts\typings\node\node.d.ts" />
<TypeScriptCompile Include="bootstrap.test.ts">
<SubType>Code</SubType>
<TestFramework>Mocha</TestFramework>
<Publish>False</Publish>
</TypeScriptCompile>
<TypeScriptCompile Include="util\templates.ts">
<SubType>Code</SubType>
</TypeScriptCompile>
</ItemGroup>
<ItemGroup>
<Folder Include="util\" />
<Folder Include="Scripts\" />
<Folder Include="Scripts\typings\" />
<Folder Include="Scripts\typings\node\" />
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>cd $(ProjectDir)
call npm install
</PreBuildEvent>
</PropertyGroup>
<Import Project="..\..\..\packages\Microsoft.TypeScript.MSBuild.2.3.3\build\Microsoft.TypeScript.MSBuild.targets" Condition="Exists('..\..\..\packages\Microsoft.TypeScript.MSBuild.2.3.3\build\Microsoft.TypeScript.MSBuild.targets')" />
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
</Project>
您的構建定義的任務是什麼?您可以使用託管代理,它也可以運行摩卡測試。 –
我的njsproj文件:https://1drv.ms/t/s!AresBGZVYryjhTG8KyErCnUSe9Fe –
你解決了這個問題嗎? –