Open maximbashevoy opened 4 years ago
I'm facing the same . Is there anyway to fix it ?
const db = pgp(connection); let response = db.any(query); pgp.end(); return response; Above changes needs to be added to the index.js After reading DB, close the connection before returning.
I'm facing the same issue too.
In my plugins/index.js
file I have
const postgres = require('cypress-postgres');
module.exports = (on, config) => {
on('task', {
dbQuery: query => postgres(query.query, query.connection),
});
}
When I run tests using the task dbQuery
I get this in terminal:
WARNING: Creating a duplicate database object for the same connection.
at module.exports (/Users/<username>/<path>/node_modules/cypress-postgres/cypress/plugins/index.js:21:14)
at dbQuery (/Users/<username>/<path>/tests/cypress/plugins/index.js:39:27)
at invoke (/Users/<username>/Library/Caches/Cypress/6.9.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:47:14)
I'm facing the same issue too.
In my
plugins/index.js
file I haveconst postgres = require('cypress-postgres'); module.exports = (on, config) => { on('task', { dbQuery: query => postgres(query.query, query.connection), }); }
When I run tests using the task
dbQuery
I get this in terminal:WARNING: Creating a duplicate database object for the same connection. at module.exports (/Users/<username>/<path>/node_modules/cypress-postgres/cypress/plugins/index.js:21:14) at dbQuery (/Users/<username>/<path>/tests/cypress/plugins/index.js:39:27) at invoke (/Users/<username>/Library/Caches/Cypress/6.9.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:47:14)
hey man! did u manage to solve it? Im facing this issue right now
I'm facing the same issue too. In my
plugins/index.js
file I haveconst postgres = require('cypress-postgres'); module.exports = (on, config) => { on('task', { dbQuery: query => postgres(query.query, query.connection), }); }
When I run tests using the task
dbQuery
I get this in terminal:WARNING: Creating a duplicate database object for the same connection. at module.exports (/Users/<username>/<path>/node_modules/cypress-postgres/cypress/plugins/index.js:21:14) at dbQuery (/Users/<username>/<path>/tests/cypress/plugins/index.js:39:27) at invoke (/Users/<username>/Library/Caches/Cypress/6.9.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:47:14)
hey man! did u manage to solve it? Im facing this issue right now
Sorry, I didn't manage to fix it... Please let me know if you find a working solution π
Yes i did.. have forked ur proj and raised a PR too
On Mon, 1 Nov 2021, 9:53 pm Klas Idar LangΓΈ-Larsen, < @.***> wrote:
I'm facing the same issue too. In my plugins/index.js file I have
const postgres = require('cypress-postgres');
module.exports = (on, config) => {
on('task', { dbQuery: query => postgres(query.query, query.connection), });
}
When I run tests using the task dbQuery I get this in terminal:
WARNING: Creating a duplicate database object for the same connection.
at module.exports (/Users/<username>/<path>/node_modules/cypress-postgres/cypress/plugins/index.js:21:14) at dbQuery (/Users/<username>/<path>/tests/cypress/plugins/index.js:39:27) at invoke (/Users/<username>/Library/Caches/Cypress/6.9.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:47:14)
hey man! did u manage to solve it? Im facing this issue right now
Sorry, I didn't manage to fix it... Please let me know if you find a working solution π
β You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/siddharth23/cypress-postgres/issues/2#issuecomment-956129388, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG6RBZZNZHTLNV6YDETSTW3UJZWR3ANCNFSM4ROWCPFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I'm facing the same issue too. In my
plugins/index.js
file I haveconst postgres = require('cypress-postgres'); module.exports = (on, config) => { on('task', { dbQuery: query => postgres(query.query, query.connection), }); }
When I run tests using the task
dbQuery
I get this in terminal:WARNING: Creating a duplicate database object for the same connection. at module.exports (/Users/<username>/<path>/node_modules/cypress-postgres/cypress/plugins/index.js:21:14) at dbQuery (/Users/<username>/<path>/tests/cypress/plugins/index.js:39:27) at invoke (/Users/<username>/Library/Caches/Cypress/6.9.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:47:14)
hey man! did u manage to solve it? Im facing this issue right now
Sorry, I didn't manage to fix it... Please let me know if you find a working solution π
const pgp = require('pg-promise')();
const postgressConfig = require(require('path').resolve('cypress.json'));
function dbConnection (query,userDefineConnection) {
let connection = postgressConfig.db
if (userDefineConnection!=undefined){
connection=userDefineConnection
}
const db = pgp(connection);
return db.any(query).finally(db.$pool.end)
}
// import cppg from 'cypress-postgres';
module.exports = on => {
on("task", {
dbQuery:(query)=> dbConnection(query.query,query.connection)
});
};
I tried this one, and it works perfect. No warnings or errors. U can use pg-promise directly rather than cypress-postgres, because if u check source code of cypress-posgtres it also uses pg-promise under the hood
Thanks @nurbashanghai - worked like a charm! π π₯³
After repeatedly running a test with a call to
cy.task("dbQuery"...
I get warnings:Is it to do with the way dbQuery task is added in plugins? Any advice?