是否可以将 Testacular (Karma) 与 angular-scenario 混合使用? [英] Is it possible to mix Testacular (Karma) with angular-scenario?

查看:20
本文介绍了是否可以将 Testacular (Karma) 与 angular-scenario 混合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Testacular(现在的 Karma)很棒,angular-scenario 也很棒.然而,事实证明将它们一起使用是一个挑战.Testacular 中有一个 ANGULAR-SCENARIO-ADAPTER,但这会破坏简单的测试.如果您自己包含 angular-scenario.js,Testacular 将根本不运行任何测试.有没有人让它正常运行?

Testacular (now Karma) is awesome, so is angular-scenario. Using them together is proving a challenge however. There is an ANGULAR-SCENARIO-ADAPTER in Testacular, but that breaks simple tests. If you include angular-scenario.js yourself Testacular will run no tests at all. Has anyone got this running properly?

我尝试在一个简单的测试中使用它,但我看到了一些奇怪的行为:

I've tried to use this with a trivial test, but I saw some weird behavior:

测试:

describe('Simple', function(){
    it('should compare strings', function(){
        expect('foo').toBe('foo');
    });
});

使用配置的正常行为:

files = [
  JASMINE,
  JASMINE_ADAPTER,
//    ANGULAR_SCENARIO,
//    ANGULAR_SCENARIO_ADAPTER,
    'tests/lib/angular/angular.js',

    'tests/sample.js'
];

输出:

$ testacular start
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser ChromeCanary
info (Chrome 25.0): Connected on socket id KRwEUtKtiaJs3MoiEsNg
Chrome 25.0: Executed 1 of 1 SUCCESS (0.061 secs / 0.003 secs)

添加 ANGULAR 适配器配置时:

When adding the ANGULAR adapter config:

files = [
  JASMINE,
  JASMINE_ADAPTER,
    ANGULAR_SCENARIO,
    ANGULAR_SCENARIO_ADAPTER,
    'tests/lib/angular/angular.js',

    'tests/sample.js'
];

输出为:

$ testacular start
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser ChromeCanary
info (Chrome 25.0): Connected on socket id 5YZA2fSuNXjmI-yRFGF6
Chrome 25.0 Simple should compare strings FAILED
        expect undefined toBe "foo"
        /Users/iwein/projects/epec/spa/tests/sample.js:3:9: expected "foo" but was undefined
Chrome 25.0: Executed 1 of 1 (1 FAILED) (0.195 secs / 0.018 secs)

添加angular-scenario.js,希望JASMINE-ADAPTER可以处理.

我也尝试过包含 angular-scenario.js 自己,但这是一个死胡同.

Adding angular-scenario.js and hoping JASMINE-ADAPTER can handle it.

I've also tried to include angular-scenario.js myself, but that's a dead end.

//inside testacular.conf.js
files = [
   JASMINE,
   JASMINE_ADAPTER,
   'tests/lib/angular/angular.js',
   'tests/sample.js'
];

我得到输出:

$ testacular start
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser ChromeCanary
info (Chrome 24.0): Connected on socket id uEzVQ6tqSu7M7tak4F6v
Chrome 24.0 Array #indexOf() should return -1 when the value is not present FAILED
    Expected true to be false.
    Error: Expected true to be false.
        at null.<anonymous> (/..../tests/sample.js:4:17)
Chrome 24.0: Executed 1 of 1 (1 FAILED) (0.07 secs / 0.004 secs)

如果我在混合中添加角度场景:

If I add angular-scenario in the mix:

//inside testacular.conf.js
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'tests/lib/angular/angular.js',
  'tests/lib/angular/angular-scenario.js',
  'tests/sample.js'
];

测试根本没有运行:

 $ testacular start
 info: Testacular server started at http://localhost:9876/
 info (launcher): Starting browser ChromeCanary
 info (Chrome 24.0): Connected on socket id GcyCTxuvhyFcCaE14BEP
 Chrome 24.0: Executed 0 of 0 SUCCESS (0.116 secs / 0 secs)

有没有人让它正常运行?true 变成 undefined 是怎么回事?

Has anyone got this running properly? What's with the true becoming undefined?

推荐答案

您不能将两者混合在一个睾丸配置中.您应该做的是准备 2 种不同的睾丸配置:一种用于运行单元测试,另一种用于运行 e2e 测试.

You can't mix the 2 in one testacular configuration. What you should do is to prepare 2 distinct testacular configurations: one for running unit tests and another one for running e2e tests.

然后,您将运行 testacular 两次:首先执行单元测试,然后执行 e2e 测试.通常我会非常非常频繁地运行单元测试(在每次保存时!)而 e2e 测试就在提交之前(因为这些测试运行时间更长).我们希望从单元测试中获得尽可能快的反馈,同时 e2e 测试提供最终的安全网,并确保单元测试难以覆盖的应用程序部分(导航、UI 等)仍然正常工作.

Then, you would run testacular twice: firstly to execute unit tests and then e2e tests. Usually I'm running unit tests very, very frequently (on each save!) while e2e tests just before a commmit (since those test run longer). We want to have the fastest possible feedback from unit tests while e2e tests are providing the ultimate safety net and assuring that parts of applications hard to cover with unit tests (navigation, UI etc.) are still working correctly.

这是 AngularJS 种子使用的技术,你可以在这里看到相应的定义:https://github.com/angular/angular-seed/tree/master/config

This is the technique that AngularJS seed is using, you can see the corresponding definitions here: https://github.com/angular/angular-seed/tree/master/config

这篇关于是否可以将 Testacular (Karma) 与 angular-scenario 混合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆