Cypress 任务:插件文件丢失或无效

问题描述 投票:0回答:3

当我添加自定义任务时,我开始遇到一些错误,但我不知道如何解决它。我正在遵循 RWA 的示例:https://github.com/cypress-io/cypress-realworld-app/blob/develop/cypress/plugins/index.ts

cypress/plugins/index.js

import axios from "axios";
import { percyHealthCheck } from "@percy/cypress/task";
import { bookingCancel } from "../../server/api/booking-controller";

export default (on, config) => {
  on("task", {
    percyHealthCheck,
    async "booking:cancel"(user, bookingId, options) {
      const response = await axios({
        baseURL: Cypress.env("apiUrl"),
        ...bookingCancel(user, bookingId, options),
      });
      return response;
    },
  });
  return config;
};

我的错误:

Error: The plugins file is missing or invalid.

Your `pluginsFile` is set to `/cypress/plugins/index.js`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js`, `.ts`, or `.coffee` file.

Or you might have renamed the extension of your `pluginsFile`. If that's the case, restart the test runner.

Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.
    at Object.get (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/errors.js:968:15)
    at EventEmitter.<anonymous> (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/index.js:144:21)
    at EventEmitter.emit (events.js:310:20)
    at ChildProcess.<anonymous> (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:19:22)
    at ChildProcess.emit (events.js:310:20)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:85:21)

/cypress/plugins/index.js:1
import { percyHealthCheck } from "@percy/cypress/task";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1051:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
    at Module.load (internal/modules/cjs/loader.js:981:32)
    at Module._load (internal/modules/cjs/loader.js:881:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at runPlugins (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:213:15)
    at Object.<anonymous> (/Users/nikomel/Library/Caches/Cypress/5.5.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/index.js:8:25)
    at Module._compile (internal/modules/cjs/loader.js:1145:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
    at Module.load (internal/modules/cjs/loader.js:981:32)
    at Module._load (internal/modules/cjs/loader.js:881:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)

注意:我验证了

pluginsFile
具有正确的路径,我什至尝试显式提供文件的路径,但它没有解决问题。

javascript testing automated-tests cypress
3个回答
3
投票

看起来倒数第四行中可能有一个逗号

      });
      return response;
    },  <------------------ here
  });
  return config;
};

0
投票

这对我有用!

(Particularly for older cypress version i.e. 9.7.0)

即使安装了cypress

奔跑

npm install [email protected] --save-dev

-1
投票

我遇到了同样的错误,我忘记执行以下代码: npm install --save-dev cypress-cucumber-预处理器

© www.soinside.com 2019 - 2024. All rights reserved.