为什么Karma启动一个空的浏览器窗口?

时间:2016-08-06 02:27:30

标签: karma-runner

Karma应该启动一个加载了我的前端应用程序的浏览器吗?

如果正确加载了Karma,我应该会看到我的应用的目标网页,这是正确的吗?

如果没有加载我的应用登录页面,为什么Karma会启动可见的浏览器?

这是我的karma.config.js 我正在学习Karma,不确定我是否做得很好。

var webpackConfig = require('./webpack.config.js');
webpackConfig.entry = {};
/*
The entry point from the referenced Webpack configuration 
has to be removed or tests will fail in weird and inscrutable 
ways. Easy enough, just define an empty entry object.
*/

module.exports = function(config) {
  config.set({
    bathPath: './dist/',
    webpack: webpackConfig,
    /* reference the Webpack configuration in the Karma configuration */
    preprocessors: {
        // './dist/bundle.js': ['webpack'],
        './test/*.js': ['webpack']
        /* application’s entry point, karama-webpack plugin requires this */
        /* you have to tell Karma that you want the karma-webpack plugin 
           to process these files. That’s what ['webpack'] does.
        */
    },
    /* 
            The plugins section is missing from my karma.config.js file. 
            When missing, Karma will load any plugins it can find in the 
            node-modules folder. Much simpler in my opinion.
    */
    frameworks: ['jasmine'],
    files: [ {pattern: 'index.html', }, './test/*.js'],
    /* The files array determines which files are included in the 
       browser and which files are watched and served by Karma 
    */
    browsers: ['Chrome'],
    reporters: ['progress'],
    port: 9876
  });
};

enter image description here

1 个答案:

答案 0 :(得分:1)

这是对的。 Karma加载一个页面,其中包含您的所有JavaScript和所有规范。然后运行可能存在的任何规格。这不是完全集成测试。这是javascript单元测试。

如果您想在浏览器中进行调试,可以单击debug按钮,然后您将看到它运行的页面。点击该页面并查看控制台,您将看到您的规格输出。

您需要更多资源才能进行完整的整合测试,例如protractorcapybara或......

可能取决于您用于构建网站的内容。