简体   繁体   English

使用Chutzpah运行QUnit(TypeScript)测试,在已经启动的情况下在测试上下文之外提供“Called start()”

[英]Running QUnit (TypeScript) tests with Chutzpah gives “Called start() outside of a test context while already started”

I've got a fairly simple repro with an outcome I don't understand. 我有一个相当简单的复制品,结果我不明白。

Make sure you have the Chutpah Test Adapter 4.0.3 installed. 确保安装了Chutpah Test Adapter 4.0.3。 Using Visual Studio 2013 take the following steps: 使用Visual Studio 2013执行以下步骤:

  1. Create a new .NET 4.5.1 class library project; 创建一个新的.NET 4.5.1类库项目;
  2. Add the NuGet package qunit.TypeScript.DefinitelyTyped 0.1.7; 添加NuGet包qunit.TypeScript.DefinitelyTyped ;
  3. Add a TypeScript file file1.ts to the project with this content: 使用以下内容将TypeScript文件file1.ts添加到项目中:

     /// <reference path="./Scripts/typings/qunit/qunit.d.ts"/> QUnit.test("QUnit is working", assert => assert.ok(true)); 
  4. Right-click inside that file and pick "Run JS Tests" from the context menu. 在该文件中单击鼠标右键,然后从上下文菜单中选择“运行JS测试”。

I can confirm that file1.js is generated as expected. 我可以确认file1.js是按预期生成的。

The result is that no tests are run, the test explorer shows no tests, and the Test output shows: 结果是没有运行测试,测试资源管理器显示没有测试,测试输出显示:

Error: Error: Called start() outside of a test context while already started
at start in file:///C:/Users/username/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/abcxyz/TestFiles/QUnit/qunit.js (line 287)
at startQUnit in phantomjs://webpage.evaluate() (line 12)
at onPageLoaded in phantomjs://webpage.evaluate() (line 16)
in phantomjs://webpage.evaluate() (line 18)
While Running:c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts
------ Test started: File: c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts ------
Error: Error: Called start() outside of a test context while already started
While Running:c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts
0 passed, 0 failed, 0 total (chutzpah).

========== Total Tests: 0 passed, 0 failed, 0 total ==========

If I choose the "Open In Browser" Chutzpah context menu item I get a regular QUnit test page, nicely formatted, showing zero tests run. 如果我选择“在浏览器中打开”Chutzpah上下文菜单项,我会得到一个常规的QUnit测试页面,格式很好,显示零测试运行。

Obviously the expected result was that one test was successfully run. 显然,预期结果是一次测试成功运行。

What am I missing here? 我在这里错过了什么?

D'oh! D'哦! The Chutzpah + TypeScript documentation is actually pretty clear about this: Chutzpah + TypeScript文档实际上非常清楚:

You need to tell Chutzpah how to compile your files into JavaScript using the compile setting in the chutzpah.json file. 您需要告诉Chutzpah如何使用chutzpah.json文件中的编译设置将文件编译为JavaScript。

For the scenario from the question take eg these steps to get it to work: 对于问题的场景,例如以下步骤使其工作:

  1. Add a chutzpah.json file to the root of your project. chutzpah.json文件添加到项目的根目录。
  2. Enter the following code: 输入以下代码:

     { "Compile": { "Mode": "External", "Extensions": [".ts"], "ExtensionsWithNoOutput": [".d.ts"] } } 

    After this the right-click run will already improve, showing: 在此之后,右键单击运行已经改善,显示:

    ========== Total Tests: 1 passed, 0 failed, 1 total ==========

    If this doesn't work right away close and re-open the solution . 如果这不能立即关闭并重新打开解决方案

  3. To get the tests to show up in the Test Explorer you need to group them into modules, eg by adding this to file1.ts : 要使测试显示在测试资源管理器中,您需要将它们分组到模块中,例如将其添加到file1.ts

     QUnit.module("Qu.Testing"); 

For more info, see the Compile Setting documentation . 有关详细信息,请参阅“ 编译设置”文档

Leaving this up here should others fall in the same trap I did. 把它放在这里应该让其他人陷入我所做的同一个陷阱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM