赛普拉斯任务:插件文件丢失或无效

Posted

技术标签:

【中文标题】赛普拉斯任务:插件文件丢失或无效【英文标题】:Cypress Task: The plugins file is missing or invalid 【发布时间】:2021-02-10 09:17:42 【问题描述】:

当我添加我的自定义任务时,我开始遇到一些错误,我不知道如何解决它。我正在遵循 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 具有正确的路径,我什至尝试明确提供文件的路径,但没有解决问题。

【问题讨论】:

【参考方案1】:

看起来你的第四行到最后一行可能有一个杂散的逗号

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

【讨论】:

【参考方案2】:

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

【讨论】:

以上是关于赛普拉斯任务:插件文件丢失或无效的主要内容,如果未能解决你的问题,请参考以下文章

赛普拉斯 - 如何按顺序运行测试文件

如何将赛普拉斯的测试运行程序的“控制台日志”(左侧)保存到文件中

赛普拉斯 - 如何验证文件是不是已下载?

赛普拉斯报告者结果文件名

硬盘重要资料丢失,用软件恢复无效,要抓狂了!

如何使用赛普拉斯测试文件输入?