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);