siddharth23 / cypress-postgres

Use this plugin to query Postgres database and use response in cypress tests
https://github.com/siddharth23/cypress-postgres
7 stars 10 forks source link

Creating a duplicate database object for the same connection #2

Open maximbashevoy opened 4 years ago

maximbashevoy commented 4 years ago

After repeatedly running a test with a call to cy.task("dbQuery"... I get warnings:

WARNING: Creating a duplicate database object for the same connection.
    at module.exports (e2e-tests/node_modules/cypress-postgres/cypress/plugins/index.js:21:14)
    at dbQuery (/e2e-tests/cypress/plugins/index.js:24:29)
    at invoke (/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/task.js:41:14)

Is it to do with the way dbQuery task is added in plugins? Any advice?

dhalawa-bread commented 3 years ago

I'm facing the same . Is there anyway to fix it ?

kawadesoni commented 3 years ago

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.

KleisKlasKluss commented 3 years ago

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)
nurbashanghai commented 3 years ago

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

KleisKlasKluss commented 3 years ago

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 πŸ˜„

kawadesoni commented 3 years ago

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.

nurbashanghai commented 3 years ago

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 πŸ˜„

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

KleisKlasKluss commented 3 years ago

Thanks @nurbashanghai - worked like a charm! πŸš€ πŸ₯³