Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
How to have more than one plugin in cypress/plugins/index.js file?

I have 2 two different functionalities in plugins.

const fs = require('fs-extra');
const path = require('path');
const service = require('../../src/services/index');

function getConfigurationByFile(file) {
  const pathToConfigFile = path.resolve(
    '..',
    'pnb_e2e_tests/cypress/config',
    `${file}.json`
  );

  return fs.readJson(pathToConfigFile);
}

module.exports = (on, config) => {

  on('task', {
    async getAllPosts() {
      return await service.getAllPosts()
    }
  });

  const file = config.env.fileConfig || 'development';
  return getConfigurationByFile(file);
};

As you can see, one of them is for configuration file (development, production and stage) and it's executed when I start project. And the second one is knex.js which I use to work with database. When I try to call this function in tests I get an error which says Please check your plugins file:

cy.task('getAllPosts').then((config) => {
      console.log('config', config)
    })

I, probably, understand the problem, but can't resolve this.

P.S. Knex files:

const knex = require('../knex/knex')

module.exports = {
  async getAllPosts() {
    return knex('posts')
      .select('*')
  }
}

And just file with configurations:

const environment = process.env.NODE_ENV || 'development'
const config = require('./../../knexfile')[environment]
module.exports = require('knex')(config);
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda