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嗎?相同的技術 –

相關問題