Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!