Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 我如何用因果报应来纠正这个错误;反应16.2.0?_Reactjs_Karma Runner_Reactjs Testutils_React 16_Isparta - Fatal编程技术网

Reactjs 我如何用因果报应来纠正这个错误;反应16.2.0?

Reactjs 我如何用因果报应来纠正这个错误;反应16.2.0?,reactjs,karma-runner,reactjs-testutils,react-16,isparta,Reactjs,Karma Runner,Reactjs Testutils,React 16,Isparta,我有这个因果报应配置(使用React 16.2.0): 我收到以下控制台错误: { “消息”:“未捕获引用错误:加载项未定义\n在test/allTests.js:81672:8\n\n引用错误:加载项未定义\n at Object.defineProperty.value(test/allTests.js:84455:18)\n at webpack\u require(test/allTests.js:20:30)\n在test/allTests.js:81668:20\n在Object.d

我有这个因果报应配置(使用React 16.2.0):

我收到以下控制台错误:

{ “消息”:“未捕获引用错误:加载项未定义\n在test/allTests.js:81672:8\n\n引用错误:加载项未定义\n
at Object.defineProperty.value(test/allTests.js:84455:18)\n at webpack\u require(test/allTests.js:20:30)\n在test/allTests.js:81668:20\n在Object.defineProperty.value (test/allTests.js:81732:6)\n在需要的网页上 (test/allTests.js:20:30)\n位于对象。 (test/allTests.js:79742:21)\n位于对象。 (test/allTests.js:80112:31)\n在网页上 (test/allTests.js:20:30)\n位于对象。 (test/allTests.js:77771:15)\n在需要的网页上 (test/allTests.js:20:30)“, “str”:“未捕获引用错误:加载项未定义\n在test/allTests.js:81672:8\n\n引用错误:加载项未定义\n
at Object.defineProperty.value(test/allTests.js:84455:18)\n at webpack\u require(test/allTests.js:20:30)\n在test/allTests.js:81668:20\n在Object.defineProperty.value (test/allTests.js:81732:6)\n在需要的网页上 (test/allTests.js:20:30)\n位于对象。 (test/allTests.js:79742:21)\n位于对象。 (test/allTests.js:80112:31)\n在网页上 (test/allTests.js:20:30)\n位于对象。 (test/allTests.js:77771:15)\n在需要的网页上 (test/allTests.js:20:30)“}


此错误的来源是什么?

react插件测试utils与react 16不兼容。正如npm页面所说,TestUtils已经被移动到react dom/TestUtils。看

const isArray = require('lodash/lang/isArray');
const merge = require('lodash/object/merge');
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');

/**
* Base karma configuration.
* The properties stated here will be common for every other configuration. This will serve as a
* point of reuse for a local coverage configuration, and a different CI coverage configuration.
* @type {Object}
*/

const ALL_FILES = [
//    'test/react-throw-on-error.js',
    './node_modules/phantomjs-polyfill/bind-polyfill.js',
    './node_modules/jquery/dist/jquery.js',
    'test/allTests.js'
];

var baseConf = {
    plugins: [
        'karma-coverage',
        'karma-webpack',
        'sass-loader',
        'karma-chrome-launcher',
        'karma-phantomjs-launcher',
        'karma-mocha-reporter',
        'karma-mocha'
    ],

    // 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: ['mocha'],

    // list of files / patterns to load in the browser
    files: ALL_FILES,


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

    // preprocess matching files before serving them to the browser
    preprocessors: {
        'test/allTests.js': ['webpack']
    },

    client: {
        captureConsole: true
    },

    webpack: {
        plugins: [
            new CaseSensitivePathsPlugin(),
            new ExtractTextPlugin('style.css'),
            new webpack.DefinePlugin({
                '__ENVIRONMENT__': '"DEV"',
                '__DEBUG_MODE__': true,
                '__BASE_HOST__': JSON.stringify(process.env.BASE_HOST || '') ,
                '__MOCK_ALL_ENDPOINTS__': JSON.stringify(process.env.MOCK_ALL_ENDPOINTS || ''),
                '__MOCKED_ENDPOINTS__': JSON.stringify(process.env.MOCKED_ENDPOINTS || ''),
                '__PUBLIC_URL__': JSON.stringify(process.env.PUBLIC_URL || ''),
                '__REDIRECTED_ENDPOINTS__': JSON.stringify(process.env.REDIRECTED_ENDPOINTS || ''),
                '__LOG_API_ERRORS_REMOTELY__': JSON.stringify(process.env.LOG_API_ERRORS_REMOTELY || ''),
                '__SHOW_API_ERRORS__': JSON.stringify(process.env.SHOW_API_ERRORS || '')
            })
        ],
        module: {
            preLoaders: [
                {
                    test: /\.jsx?$/,
                    exclude: /(node_modules)/,
                    loader: 'babel',
                    query: {
                        presets: ['react', ["es2015", {"loose": true}]],
                        plugins: ['array-includes'],
                        cacheDirectory: true
                    }
                },
                {
                    test: /\.?css$/,
                    loader: ExtractTextPlugin.extract(
                        "style",
                        "css!sass")
                },
                {
                    test: /\.(png|jpg|gif)$/,
                    loader: 'url-loader?limit=8192'
                },
                {
                    test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
                    loader: 'file-loader'
                },
                {
                    test: /\.json$/,
                    loader: 'json'
                }

            ]
        },
        resolve: {
            root: [path.resolve('src'), path.resolve('test')],
            modulesDirectories: ['node_modules'],
            alias: {
                commonsComponents: 'commons-components/build',
                commonsUtilities: 'commons-components/src/lib/utilities',
                stylesOpenBank: 'styles-openbank/src/styles/_base.scss',
                stylesOpenBankApp: 'styles-openbank/src/styles/_app.scss',
                stylesOpenBankBootstrap: 'styles-openbank/src/styles/_bootstrap.scss',
                stylesOpenBankAssests: 'styles-openbank/src/assets'
            }
        },

        externals: {
            'react/addons': true,
            'react-addons-test-utils': true,
            'react/lib/ExecutionEnvironment': true,
            'react/lib/ReactContext': true,
        },

        babelPreprocessor: {
            options: {
                presets: ['airbnb']
            }
        }
    },

    webpackMiddleware: {
        noInfo: true,
    },

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

    // web server port
    port: 9876,

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

    // 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: ['Chrome'],

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

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity,

    // Increments how long will Karma wait for a message from a browser before disconnecting from it (in ms).
    browserNoActivityTimeout: 60000
};

/**
* Helper to provide lodash merge with deep array merging
*/
function customizer(objValue, srcValue) {
    if (isArray(objValue)) {
        return objValue.concat(srcValue);
    }
}

/**
* Base Karma configuration for running a coverage analysis.
* Based on the base config, this one is an extension to add all data is needed for a coverage
* instrumentation. It is also a base config, as it will be reused in a local and a CI coverage task.
* @type {Object}
*/
var coverageConf = merge({}, baseConf, {
    webpack: {
        isparta: {
            embedSource: true,
            noAutoWrap: true,
            babel: {
                presets: ['es2015', 'react']
            }
        },
        module: {
            preLoaders: [
                {
                    test: /\.js$/,
                    include: path.resolve('src'),
                    loader: 'isparta-loader'
                }
            ]
        }
    },
    coverageReporter: {
        type: 'lcov',
        dir: 'test/coverage/'
    },

    reporters: ['coverage']
}, customizer);

module.exports.baseConf = baseConf;
module.exports.coverageConf = coverageConf;