4
respostas

[Bug] Erro configFile ao executar o run com reporter.

Ao executar o código: npx cypress run --reporter mochawesome

Ocorre o erro abaixo:

DevTools listening on ws://127.0.0.1:51070/devtools/browser/fad884d4-3575-4eeb-8037-ed0d40605548 Your configFile threw an error from: C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress\cypress.config.js

The error was thrown while executing your e2e.setupNodeEvents() function:

ReferenceError: defineConfig is not defined at setupNodeEvents (C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress\cypress.config.js:4:7) at C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_plugins.js:122:14 at tryCatcher (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules\bluebird\js\release\util.js:16:23) at Function.Promise.attempt.Promise.try (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules\bluebird\js\release\method.js:39:29) at RunPlugins.load (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_plugins.js:119:9) at RunPlugins.runSetupNodeEvents (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_plugins.js:59:17) at EventEmitter. (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_require_async_child.js:185:22) at EventEmitter.emit (node:events:390:28) at process. (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\util.js:33:22) at process.emit (node:events:390:28) at emit (node:internal/child_process:917:12) at processTicksAndRejections (node:internal/process/task_queues:84:21)

O meu arquivo cypress.config.js está configurado com o código abaixo:

module.exports = { e2e: { setupNodeEvents(on, config) { module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { { "reporter"; "mochawesome", "reporterOptions"; { "reportDir"; "cypress/report/mochawesome-report", "overwrite"; true, "html"; true, "json"; false, "timestamp"; "mmddyyyy_HHMMss" }} }, }, }); }, }, };

E o meu projeto está no diretório:

C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress\cypress

O que pode estar causando esse erro de execução?

Desde já agradeço a ajuda de todos.

4 respostas

Tente rodar o seguinte comando no terminal na pasta do seu projeto

"npm i"

Isso instala quaisquer coisas que estiver faltando.

Depois me diga se deu certo :)

Olá Giulia, executei o comando mencionado na pasta do projeto, porém, o erro ainda permanece.

PS C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress> npx cypress run --reporter mochawesome

DevTools listening on ws://127.0.0.1:63277/devtools/browser/5887af75-baa5-4ec5-a9f7-707fa02d027b Your configFile threw an error from: C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress\cypress.config.js

The error was thrown while executing your e2e.setupNodeEvents() function:

ReferenceError: defineConfig is not defined at setupNodeEvents (C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress\cypress.config.js:4:7) at C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_plugins.js:122:14 at tryCatcher (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules\bluebird\js\release\util.js:16:23) at Function.Promise.attempt.Promise.try (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules\bluebird\js\release\method.js:39:29) at RunPlugins.load (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_plugins.js:119:9) at RunPlugins.runSetupNodeEvents (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_plugins.js:59:17) at EventEmitter. (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\child\run_require_async_child.js:185:22) at EventEmitter.emit (node:events:390:28) at process. (C:\Users\rafa_\AppData\Local\Cypress\Cache\13.1.0\Cypress\resources\app\node_modules@packages\server\lib\plugins\util.js:33:22) at process.emit (node:events:390:28) at emit (node:internal/child_process:917:12) at processTicksAndRejections (node:internal/process/task_queues:84:21)

Inclusive verifiquei se o mochawesome foi instalado corretamente e apareceu na listagem:

PS C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress> npm list testes-cypress@ C:\Users\rafa_\Desktop\Estudo\Cypress\testes-cypress └── mochawesome@7.1.3

Estou executando a partir desse mesmo diretório onde executei todos os outros comandos do curso.

Olá, pessoal. Pelo que entendi, ela passou no vídeo que era pra colocar a configuração do mochawesome no arquivo de configuração que já tinha um comando de setupNodeEvents(on, config); Então, ficava repetido da forma que ela mostrou. Deixei apenas a configuração do mocha e funcionou.

const { defineConfig } = require ("cypress");

module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      { "reporter"; "mochawesome",
          "reporterOptions"; 
              { "reportDir"; "cypress/report/mochawesome-report",
              "overwrite"; true,
              "html"; true,
              "json"; false,
              "timestamp"; "mmddyyyy_HHMMss" }}
              },       
        },
        video: true
    };

a configuração de video é porque no meu não tinha.