Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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 如何在react应用程序中配置e2e测试的代码覆盖率?_Reactjs_Jestjs_Nightwatch.js - Fatal编程技术网

Reactjs 如何在react应用程序中配置e2e测试的代码覆盖率?

Reactjs 如何在react应用程序中配置e2e测试的代码覆盖率?,reactjs,jestjs,nightwatch.js,Reactjs,Jestjs,Nightwatch.js,我试图为我的e2e测试生成代码覆盖率。下面是我在package.json文件中的scripts部分 package.json "scripts": { ... "start": "cross-env REACT_APP_Region=dev npm-run-all -p watch-css start-js", "test": "yarn test:jest --config tests/jest.unit.config.js", "test:coverage"

我试图为我的e2e测试生成代码覆盖率。下面是我在
package.json
文件中的
scripts
部分

package.json

"scripts": {
    ...
    "start": "cross-env REACT_APP_Region=dev  npm-run-all -p watch-css start-js",
    "test": "yarn test:jest --config tests/jest.unit.config.js",
    "test:coverage": "yarn test:jest --config tests/jest.unit.config.js --coverage",
    "test:e2e": "nightwatch -c tests/nightwatch.conf.js -e chrome",
    "test:jest": "jest --no-cache",
  },   
我的文件夹结构如下所示:

<root>
    src
    tests
        e2e
            page_objects
            views
        jest.unit.config.js
        nightwatch.conf.js
// Get Selenium and the drivers
var seleniumServer = require('selenium-server');
var chromedriver = require('chromedriver');
var geckodriver = require('geckodriver');

var config = {
  src_folders: [
    // Folders with tests
    'tests/e2e'
  ],
  output_folder: 'tests/e2e/report', // Where to output the test reports
  page_objects_path: "tests/e2e/page_objects",
  selenium: {
    // Information for selenium, such as the location of the drivers ect.
    start_process: true,
    server_path: seleniumServer.path,
    port: 4444, // Standard selenium port
    cli_args: {
      'webdriver.chrome.driver': chromedriver.path,
      'webdriver.gecko.driver': geckodriver.path,
      'webdriver.edge.driver': "C:/Drivers/MicrosoftWebDriver.exe"
    }
  },
  test_workers: {
    // This allows more then one browser to be opened and tested in at once
    enabled: true,
    workers: 'auto'
  },
  parallel_process_delay : 500,
  test_settings: {
    default: {
      screenshots: {
        enabled: false,
        path: "tests/e2e/report",
        on_failure: true,
        on_error: false
      },
      detailed_output: true,
      skip_testcases_on_fail: false,
      end_session_on_fail: false,
      selenium_host: "localhost",
      selenium_port: 4444,
      launch_url: "http://localhost:4000",
      globals: {
        // How long to wait (in milliseconds) before the test times out
        waitForConditionTimeout: 5000
      },
      desiredCapabilities: {
        // The default test
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        nativeEvents: true
      }
    },
    // Here, we give each of the browsers we want to test in, and their driver configuration
    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        nativeEvents: true,
        os_version: "10",
        os: "Windows"
      }
    },
  }
};

module.exports = config;
module.exports = {
  name: 'unit',
  displayName: 'unit',
  rootDir: '../',
  "collectCoverageFrom": [
    "<rootDir>/src/**/*.{js,jsx,mjs}"
  ],
  "testMatch": [
    "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
  ],
  "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",
  "testEnvironment": "jsdom",
  "testURL": "http://localhost",
  "transform": {
    "^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
    "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
    "^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
  },
  "transformIgnorePatterns": [
    "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
  ],
  "moduleNameMapper": {
    "^react-native$": "react-native-web"
  },
  "moduleFileExtensions": [
    "web.js",
    "js",
    "json",
    "web.jsx",
    "jsx",
    "node",
    "mjs"
  ]
};
我能够正确运行我的所有单元测试和e2e测试,并且能够获得单元测试的覆盖率。下面是来自
package.json
文件的
jest
部分

"jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,mjs}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "projects": [
      "tests/jest.unit.config.js",
    ]
  },
现在,我想为我的e2e测试生成
代码覆盖率
。有人能在这方面指导我吗?谢谢