在 WebStorm 中通过 Mocha 运行 WebdriverIO 测试

Igo*_*bin 3 mocha.js webstorm webdriver-io

我想从 WebStorm 装订线(左侧的绿色三角形图标,按行号)运行 WebdriverIO + Mocha 测试。

\n\n

在此输入图像描述

\n\n

但是当我按运行三角形时 - 发生错误:

\n\n
/Users/ilyubin/.nvm/versions/node/v10.15.0/bin/node /Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/bin/_mocha --ui bdd --reporter /Applications/WebStorm.app/Contents/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js /Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/test/specs/catalog/not.found.page.spec.js --grep "^\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd1\x8b \xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x86\xd1\x8b \xd0\xbe\xd1\x88\xd0\xb8\xd0\xb1\xd0\xbe\xd0\xba \xd0\x9f\xd0\xbe\xd0\xb8\xd1\x81\xd0\xba \xd0\xbd\xd0\xb5\xd1\x81\xd1\x83\xd1\x89\xd0\xb5\xd1\x81\xd1\x82\xd0\xb2\xd1\x83\xd1\x8e\xd1\x89\xd0\xb5\xd0\xb3\xd0\xbe \xd0\xb7\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81\xd0\xb0$"\n/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/test/specs/catalog/not.found.page.spec.js:1\n(function (exports, require, module, __filename, __dirname) { import {expect} from \'chai\';\n                                                                     ^\n\nSyntaxError: Unexpected token {\n    at new Script (vm.js:79:7)\n    at createScript (vm.js:251:10)\n    at Object.runInThisContext (vm.js:303:10)\n    at Module._compile (internal/modules/cjs/loader.js:657:28)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)\n    at Module.load (internal/modules/cjs/loader.js:599:32)\n    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)\n    at Function.Module._load (internal/modules/cjs/loader.js:530:3)\n    at Module.require (internal/modules/cjs/loader.js:637:17)\n    at require (internal/modules/cjs/helpers.js:22:18)\n    at /Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/mocha.js:324:27\n    at Array.forEach (<anonymous>)\n    at Mocha.loadFiles (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/mocha.js:321:14)\n    at Mocha.run (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/mocha.js:763:10)\n    at Object.exports.singleRun (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/run-helpers.js:196:16)\n    at exports.runMocha (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/run-helpers.js:291:13)\n    at Object.exports.handler.argv [as handler] (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/run.js:292:3)\n    at Object.runCommand (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/node_modules/yargs/lib/command.js:238:44)\n    at Object.parseArgs [as _parseArgs] (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/node_modules/yargs/yargs.js:1072:28)\n    at Object.parse (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/node_modules/yargs/yargs.js:566:25)\n    at Object.exports.main (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/lib/cli/cli.js:62:6)\n    at Object.<anonymous> (/Users/ilyubin/git/ozon.ru/packages/ozon.ru-ui-tests/node_modules/mocha/bin/_mocha:10:23)\n    at Module._compile (internal/modules/cjs/loader.js:689:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)\n    at Module.load (internal/modules/cjs/loader.js:599:32)\n    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)\n    at Function.Module._load (internal/modules/cjs/loader.js:530:3)\n    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)\n    at startup (internal/bootstrap/node.js:283:19)\n    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)\n
Run Code Online (Sandbox Code Playgroud)\n\n

如何从 WebStorm 运行 WebdriverIO 测试?

\n\n

我的版本:

\n\n
WebStorm 2018.3.3\nBuild #WS-183.5153.33, built on January 9, 2019\nJRE: 1.8.0_152-release-1343-b26 x86_64\nJVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o\nmacOS 10.14.2\n\n\xe2\x9e\x9c ~ node -v\nv10.15.0\n\n\xe2\x9e\x9c ~ mocha --version\n5.2.0\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的依赖项:

\n\n
  "dependencies": {\n    "@wdio/allure-reporter": "^5.4.9",\n    "@wdio/cli": "^5.4.13",\n    "@wdio/local-runner": "^5.4.13",\n    "@wdio/mocha-framework": "^5.4.13",\n    "@wdio/spec-reporter": "^5.4.3",\n    "@wdio/sync": "^5.4.13",\n    ...\n  },\n
Run Code Online (Sandbox Code Playgroud)\n

len*_*ena 5

您无法使用 mocha 测试运行程序运行 wdio 规范,因此此处不能使用Mocha运行配置。您需要使用Node.js运行配置:

在此输入图像描述

另外,由于您在测试中使用 ES6 语法,因此必须配置 wdio 才能使用 babel。请参阅https://webdriver.io/docs/babel.html了解说明:

  • npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/register
  • 在项目根文件夹中,创建一个文件babel.config.js
module.exports = {
  presets: [
    ['@babel/preset-env', {
      targets: {
        node: 8
      }
    }]
  ]
}
Run Code Online (Sandbox Code Playgroud)
  • 在 wdio.conf.js 中,按如下方式设置 mocha;
mochaOpts: {
        ui: 'bdd',
        timeout: 60000,
        compilers: ['js:@babel/register']
    },
Run Code Online (Sandbox Code Playgroud)