3

我们目前正在开发需要在Internet Explorer 11上运行的Aurelia应用程序。一切都很好,直到我们尝试使用karma-ie对IE11运行我们的Karma/Tape测试-launcher。使用WaitForElement进行aurelia测试,同时在Internet Explorer中运行Karma

Karma正常启动,一些测试正在执行,直到遇到使用waitForDocumentElement的测试。由于waitForDocumentElement使用承诺,我告诉自己,很好,我只需要加载一些Promise polyfills到Karma,一切都将开始工作,就像使用Chrome时一样。但是,它显然没有。

所以,最后的问题。有没有办法让我的测试在Karma上运行,使用karma-ie-launcher针对IE11,并且有能力在我的测试中使用waitForDocumentElement。它似乎是罪魁祸首,因为它使用承诺。

如果需要的话,我可以在我的项目旁边建立一个示例回购。

谢谢!

编辑: 以下是'超出堆栈空间'错误的堆栈跟踪。对于记录,rawValue是一个可绑定的属性,我试图在waitForDocumentelement内部声明,所以绑定和所有都有时间去做他们的东西。

WARN: 'Unhandled rejection TypeError: Unable to get property 'rawValue' of undefined or null reference 
    at Anonymous function (http://localhost:9876/base/dist/_test/components/aurelia-numeric-input/aurelia-numeric-input.spec.js?ea0d4f3a76b6b818e30e08a7cbbc07dc5c11e02a:31:17) 
    at r (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:31:9351) 
    at i.prototype._settlePromiseFromHandler (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:14559) 
    at i.prototype._settlePromise (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:15364) 
    at i.prototype._settlePromise0 (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:16065) 
    at i.prototype._settlePromises (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:17395) 
    at r.prototype._drainQueue (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3054) 
    at r.prototype._drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3112) 
    at drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:1236) 
    at Anonymous function (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:31140)' 
WARN: 'Unhandled rejection TypeError: Unable to get property 'rawValue' of undefined or null reference 
    at Anonymous function (http://localhost:9876/base/dist/_test/components/aurelia-numeric-input/aurelia-numeric-input.spec.js?ea0d4f3a76b6b818e30e08a7cbbc07dc5c11e02a:36:17) 
    at r (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:31:9351) 
    at i.prototype._settlePromiseFromHandler (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:14559) 
    at i.prototype._settlePromise (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:15364) 
    at i.prototype._settlePromise0 (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:16065) 
    at i.prototype._settlePromises (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:17395) 
    at r.prototype._drainQueue (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3054) 
    at r.prototype._drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3112) 
    at drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:1236) 
    at Anonymous function (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:31140)' 
WARN: 'Unhandled rejection Error: Out of stack space 
    at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2691:7) 
    at _compileNode (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2547:11) 
    at compile (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2516:7) 
    at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2721:9) 
    at _compileNode (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2547:11) 
    at compile (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2516:7) 
    at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2721:9) 
    at _compileNode (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2547:11) 
    at compile (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2516:7) 
    at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2721:9)' 

回答

1

噶创建一个名为__karma__的窗口,列出您karma.conf.js模式匹配的文件上的属性。通常在你的测试入口点模块中有一些代码将这个文件名列表细化并去掉扩展名等,以便它们成为适合你的加载程序的模块名称列表...在你的情况下需要;

这个数组然后将模块名称分配给requirejs config的deps属性,这会导致requirejs在调用分配给requirejs config的callback属性的函数之前加载所有这些属性。

我一直在手动添加蓝鸟作为第一个依赖项。然后在回调中,我做了一些功能检测,如果Promise不受浏览器支持,请将其分配给window.Promise。

下面是一个应该非常干净地映射到您的设置的示例。相关的行标有注释。

const testModules = Object.keys(window.__karma__.files) 
    .filter(filename => /\.spec\.js$/.test(filename)) 
    .map(filename => filename.replace(/^\/base\/dist\/|\.js$/g, '')); 

testModules.unshift('bluebird'); // make bluebird the first dependency in the array... this means it will be the first argument to the callback function (see below) 

let karmaStarted = false; 

require.config({ 
    baseUrl: '/base/global/output', 
    paths: { 
     'bluebird': '../some/path/to/bluebird.min' // ensure the loader can find bluebird 
    }, 
    deps: testModules, // bluebird is the first item in this array of modules 
    callback: (bluebird: any) => { // bluebird is the first arg... there are many other args but we don't care about the rest 
     if (karmaStarted) { 
      return; 
     } 

     // polyfill Promise on an as-needed basis. 
     if (!('Promise' in window && 'resolve' in window.Promise && 'reject' in window.Promise && 'all' in window.Promise && 'race' in window.Promise)) { 
      window.Promise = bluebird.Promise; 
     } 

     karmaStarted = true; 
     window.__karma__.start(); 
    } 
}); 
+0

谢谢JD我午饭后就看看吧! –

+0

这有点帮助,但是后来我在'aurelia-templating'中得到了一些'未处理的拒绝错误:堆栈空间不足错误'。同样,使用waitForDocumentElement的测试仍然失败,但至少我没有承诺被拒绝的错误了。我开始使用waitForDocumentElement来测试自定义元素的可绑定属性的更改。 –

+0

需要获取polyfill吗?相同的技术 –

相关问题