2015-10-07 81 views
6

當運行測試因緣好像最後一次測試多次被重複,次的試驗是重複的量似乎取決於試驗和用於運行瀏覽器的數量。噶輸出複製測試結果

如果僅使用一個瀏覽器(PhantomJS或鉻)用於一個測試,測試中示出了兩次,同時使用瀏覽器時相同的單個測試示出多達6次。

我已經添加日誌到測試,日誌出現每瀏覽器測試一次,所以想必測試正在運行的正確的次數,但只複製中所示的結果。

karma.conf.js

module.exports = function(config) { 
    config.set({ 

    // base path that will be used to resolve all patterns (eg. files, exclude) 
    basePath: '', 


    // frameworks to use 
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
    frameworks: ['jasmine'], 


    // list of files/patterns to load in the browser 
    files: [ 
     '_test/test.js' 
    ], 


    // list of files to exclude 
    exclude: [ 
    ], 


    // preprocess matching files before serving them to the browser 
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
    preprocessors: { 
    }, 


    // test results reporter to use 
    // possible values: 'dots', 'progress' 
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter 
    reporters: ['progress'], 


    // web server port 
    port: 9876, 


    // enable/disable colors in the output (reporters and logs) 
    colors: true, 


    // level of logging 
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 
    logLevel: config.LOG_INFO, 


    // enable/disable watching file and executing tests whenever any file changes 
    autoWatch: true, 


    // start these browsers 
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
    browsers: ['PhantomJS', 'Chrome'], 


    // Continuous Integration mode 
    // if true, Karma captures browsers, runs the tests and exits 
    singleRun: false 
    }) 
} 

test.js

describe('karma testing', function() { 
    it('tests karma is working', function() { 
     expect(true).toBe(true); 
     console.log('test1'); 
    }); 
}); 

輸出1個瀏覽器(Chrome)

07 10 2015 16:41:14.890:INFO [karma]: Karma v0.13.10 server started at http://localhost:9876/ 
07 10 2015 16:41:14.897:INFO [launcher]: Starting browser Chrome 
07 10 2015 16:41:16.364:INFO [Chrome 45.0.2454 (Windows 7 0.0.0)]: Connected on socket 0uvPocfSI0prGxwdAAAA with id 29520633 
LOG: 'test1' 
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0 secs/0.003 secs 
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.011 secs/0.003 secs) 

輸出2的瀏覽器(PhantomJS,鉻)

07 10 2015 16:27:31.399:INFO [karma]: Karma v0.13.10 server started at http://localhost:9876/ 
07 10 2015 16:27:31.407:INFO [launcher]: Starting browser PhantomJS 
07 10 2015 16:27:31.420:INFO [launcher]: Starting browser Chrome 
07 10 2015 16:27:32.886:INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket P5focoe7004aPX1rAAAA with id 49258591 
07 10 2015 16:27:33.077:INFO [Chrome 45.0.2454 (Windows 7 0.0.0)]: Connected on socket BGtRdqevRGGXZTA-AAAB with id 42323971 
LOG: 'test1' 
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0 secs/0.003 secs) 
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs/0.003 s 
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs/0.003 s 
Chrome 45.0.2454 (Windows 7 0.0.0) LOG: 'test1' 
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs/0.003 s 
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs/0.003 secs) 
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs/0.003 secs) 
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.028 secs/0.002 secs) 
TOTAL: 2 SUCCESS 

我已經測試過,沒有安裝karma-cli,結果是一樣的。

我身邊有棧溢出和谷歌的幾個人看着似乎已經遇到過類似的問題,但目前還沒有意義的答案。

+0

任何運氣找出這一個?我們遇到同樣的問題。 –

+0

不幸的是,我現在剛剛一直在用它,你是否運行相同的配置? – ndonohoe

回答

0

我試圖讓prettifier工作時,也有類似的問題。

karma.conf需要幾個選項,比如autoWatch,瀏覽器,singleRun - 對不對?所有這些都是一個叫做客戶端的屬性。

客戶端屬性是一個具有自己的幾個屬性的對象。其目的是配置與測試客戶端相關的設置,例如Chrome。

客戶端有一個名爲captureConsole的屬性。這默認爲true,這意味着瀏覽器中的任何控制檯日誌記錄都會發送回您的bash。所以,默認情況下打開了,我看到了Chrome的控制檯日誌記錄和美化的tap輸出。

嘗試在您的設置,看看它是否有幫助!

client: { 
    captureConsole: false 
}, 
0

我知道這是幾年前問過的,但是有沒有機會從Windows命令行運行業務?我有同樣的問題,浪費了幾個小時的搜索引擎優化,然後在一個奇思妙想從PowerShell中運行它,它運行良好。也使用git bash。