我已经在测试项目中安装了 ESlint,它开始显示我需要解决的一些错误
错误之一是在 cy.request('someURL');
错误是 cy 未定义
所以我在这样的文件顶部添加了一个导入语句
import { cy } from 'cypress';
Run Code Online (Sandbox Code Playgroud)
添加此语句后,没有任何请求通过,当我尝试执行测试时出现此错误。
一旦我删除了导入语句,测试就会完美执行
我哪里错了
尝试执行任何测试都会导致出现此错误。
我正在使用赛普拉斯 6.5.0
真的不知道该怎么办。
对不起,图像,但以这种方式显示它要好得多。
还有 StackTrace。
at Object../node_modules/is-ci/node_modules/ci-info/index.js (webpack:///node_modules/is-ci/node_modules/ci-info/index.js:5:1)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
at Object../node_modules/is-ci/index.js (webpack:///node_modules/is-ci/index.js:3:18)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
at Object.eval (webpack:///node_modules/cypress/lib/util.js:21:14)
at Object../node_modules/cypress/lib/util.js (http://localhost:37869/__cypress/tests?p=test/e2e/support/index.js:87250:31)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
at Object.eval (webpack:///node_modules/cypress/index.js:9:14)
at Object../node_modules/cypress/index.js (http://localhost:37869/__cypress/tests?p=test/e2e/support/index.js:82972:31)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
From previous event:
at runScriptsFromUrls (http://localhost:37869/__cypress/runner/cypress_runner.js:177985:98)
at Object.runScripts (http://localhost:37869/__cypress/runner/cypress_runner.js:177999:11)
at $Cypress.onSpecWindow (http://localhost:37869/__cypress/runner/cypress_runner.js:167733:19)
Run Code Online (Sandbox Code Playgroud) 当在 中键入自定义命令时commands.js,WebStorm 的 linter 表示 和Cypress均未cy定义,并且不提供任何 IntelliSense。两者都在任何文件中完美定义integration。
命令.js
Cypress.Commands.add('command', () => {
cy.get('div');
});
// ESLint: 'Cypress' is not defined.(no-undef)
// ESLint: 'cy' is not defined.(no-undef)
Run Code Online (Sandbox Code Playgroud)
索引.js
import './commands.js'
Run Code Online (Sandbox Code Playgroud)
VSCode 中不会出现此错误。相反, 和Cypress都cy被定义为any。
然而,不管这个错误如何,测试都可以正常工作。
我该怎么做才能让 linter 在自己的文件中识别 Cypress?
我已将赛普拉斯从更新3.0.3为3.1.3。我正在使用必须与文档相关的ES6导入/导出模块。但是我undefined在终端中出现一行并且在GUI中出现以下错误:
<root_dir>/node_modules/@babel/runtime/helpers/esm/defineProperty.js:1
export default function _defineProperty(obj, key, value) {
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Run Code Online (Sandbox Code Playgroud)
我的测试使用的是普通JS,没有TS os CoffeeScript。我陷入困境,在3.0.3它工作正常。
cypress ×4
javascript ×2
babeljs ×1
browserify ×1
e2e-testing ×1
eslint ×1
testing ×1
webstorm ×1