2016-03-24 41 views
4

在Ember應用程序中運行我的測試時出現此錯誤。顯然,語法錯誤(Unexpected token ',')以某種方式發生,導致測試環境的非常負載失敗,因此它使每個測試都失敗。由於PhantomJS語法錯誤,Ember.js測試失敗

$ ember test 
version: 1.13.13 
Built project successfully. Stored in "/Users/ernesto/code/projects/my-app/frontend/tmp/class-tests_dist-cqvfx9XF.tmp". 
not ok 1 PhantomJS 2.0 - global failure 
    --- 
     actual: > 
      null 
     message: > 
      SyntaxError: Unexpected token ',' 
     Log: | 
    ... 
not ok 2 PhantomJS 2.0 - global failure 
    --- 
     actual: > 
      null 
     message: > 
      Error: Could not find module `frontend/config/environment` imported from `frontend/tests/helpers/resolver` 
     Log: | 
    ... 
not ok 3 PhantomJS 2.0 - global failure 
    --- 
     actual: > 
      null 
     message: > 
      Error: Assertion Failed: The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js". 
     Log: | 
    ... 
not ok 4 PhantomJS 2.0 - Integration | Component | dropdown filter: it renders all given options and the empty option 
    --- 
     actual: > 
      null 
     message: > 
      Promise rejected before it renders all given options and the empty option: you must set a resolver with `testResolver.set(resolver)` 
     Log: | 
    ... 

注意上面的第一個錯誤,即認爲global failure然後報告意外逗號令牌。之後,所有剩餘的測試失敗,或者是因爲他們無法導入存在的文件,或者因爲沒有設置testResolver或其他東西。

事情就是一切在瀏覽器中正常運行。看起來這與PhantomJS在某些地方對某些語法更加嚴格有關。但是在錯誤消息中沒有說明這個流氓逗號的位置。

有人可以給我一些關於如何找到這個逗號或解決這個錯誤的提示嗎?提前致謝。

+0

您可能會認爲我可以看看引入錯誤的提交的差異。那麼,它會導致合併提交。合併前兩個合併分支中的任何一個都不會發生錯誤。它只發生在其中一個分支合併到另一個之後。合併過程中根本沒有任何衝突,因此可能會引入語法錯誤。即使是這樣,錯誤也不會在開發模式下的瀏覽器中體現出來,就在運行測試時。 – Ernesto

+0

運行一些ES5語法檢查器來查找錯誤。 –

+0

恐怕我使用了太多的ES6功能,所以ES5語法檢查程序會跟我的代碼搞得一團糟。或不?我錯過了什麼嗎? – Ernesto

回答

6

PhantomJS拋出當一個對象有重複的屬性名稱語法錯誤,如:

var object = { foo: 1, foo: 2 }; 

大多數瀏覽器不認爲這是一個語法錯誤,只是使用的最後一個屬性定義。

相關問題