首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用React js的Phantom js无法找到更少的js文件

使用React js的Phantom js无法找到更少的js文件
EN

Stack Overflow用户
提问于 2015-07-26 11:49:17
回答 1查看 836关注 0票数 0

中使用的单元测试框架来对react项目进行单元测试。

https://github.com/pheuter/essential-react

我的项目的单元测试的设置与此完全相同。我的问题是它似乎不支持更少的js文件。每次我尝试运行一个文件中包含较少内容的测试时,都会收到来自phantom js的这个错误。

PhantomJS 1.9.8 (Mac 0.0.0)错误:无法在/Unit_Tests/main.js:26577找到模块"./Dashboard.less“

我的main.js文件外观

代码语言:javascript
复制
/**
 * Test suite entry point
 */

// Babel Polyfill
import 'babel-core/polyfill';

import './routes/Home_Test';
//import './routes/Dashboard.less';

还有我的karma.config.js

代码语言:javascript
复制
/**
 * This is the Karma configuration file. It contains information about this skeleton
 * that provides the test runner with instructions on how to run the tests and
 * generate the code coverage report.
 *
 * For more info, see: http://karma-runner.github.io/0.12/config/configuration-file.html
 */
module.exports = function(config) {
  config.set({

    /**
     * These are the files required to run the tests.
     *
     * The `Function.prototype.bind` polyfill is required by PhantomJS
     * because it uses an older version of JavaScript.
     */
    files: [
      './Unit_Tests/polyfill.js',
      './Unit_Tests/main.js'
    ],

    /**
     * The actual tests are preprocessed by the karma-webpack plugin, so that
     * their source can be properly transpiled.
     */
    preprocessors: {
      './Unit_Tests/main.js': ['webpack']
    },

    /**
     * We want to run the tests using the PhantomJS headless browser.
     * This is especially useful for continuous integration.
     */
    browsers: ['PhantomJS'],

    /**
     * Use Mocha as the test framework, Sinon for mocking, and
     * Chai for assertions.
     */
    frameworks: ['mocha', 'sinon-chai'],

    /**
     * After running the tests, return the results and generate a
     * code coverage report.
     */
    reporters: ['progress', 'coverage'],

    /**
     * When generating a code coverage report, use `lcov` format and
     * place the result in coverage/lcov.info
     *
     * This file will be sent to Coveralls by the `coveralls` npm script.
     */
    coverageReporter: {
      dir: 'coverage/',
      reporters: [
        { type: 'lcovonly', subdir: '.', file: 'lcov.info' },
        { type: 'html', subdir: 'html' }
      ]
    },

    /**
     * The configuration for the karma-webpack plugin.
     *
     * This is very similar to the main webpack.local.config.js, with the
     * exception of specifying an istanbul-transformer post loader so
     * that we can generate an accurate code coverage report.
     */
    webpack: {
      module: {
        loaders: [
          { test: /\.jsx?$/, exclude: /node_modules/, loader: "babel-loader?stage=0"}
        ],
        postLoaders: [{
          test: /\.jsx?$/,
          exclude: /(test|node_modules)\//,
          loader: 'istanbul-instrumenter'
        }]
      },
      resolve: {
        extensions: ['', '.js', '.jsx']
      }
    },

    /**
     * Configuration option to turn off verbose logging of webpack compilation.
     */
    webpackMiddleware: {
      noInfo: true
    },

    /**
     * Once the mocha test suite returns, we want to exit from the test runner as well.
     */
    singleRun: true,

    /**
     * List of plugins
     */
    plugins: [
      'karma-mocha',
      'karma-webpack',
      'karma-coverage',
      'karma-sinon-chai',
      'karma-phantomjs-launcher'
    ],
  });
}

我一直在寻找一个关于如何对包含较少但找不到的文件进行单元测试的好答案。我并不真正关心css的单元测试,只关心jsx文件。

EN

回答 1

Stack Overflow用户

发布于 2015-07-27 03:37:14

弄清楚了

代码语言:javascript
复制
    preprocessors: {
        './Unit_Tests/main.js': ['webpack'],
        '**/*.less': ['less']
    },

    webpack: {
        module: {
            loaders: [
                {test: /\.jsx?$/, exclude: /node_modules/, loader: "babel-loader?stage=0"},
                {test: /\.less$/, loader: "style!css!less"}
            ],
            postLoaders: [{
                test: /\.jsx?$/,
                exclude: /(test|node_modules)\//,
                loader: 'istanbul-instrumenter'
            }]
        },
        resolve: {
            extensions: ['', '.js', '.jsx', '.css', '.less']
        }
    },

更改您的karma.config.js以包含以下内容

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31633447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档