Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a duplicate database object for the same connection #2

Open
maximbashevoy opened this issue Sep 16, 2020 · 8 comments
Open

Comments

@maximbashevoy
Copy link

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
Copy link

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

@kawadesoni
Copy link
Contributor

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
Copy link

KleisKlasKluss commented Aug 20, 2021

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
Copy link

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
Copy link

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
Copy link
Contributor

kawadesoni commented Nov 1, 2021 via email

@nurbashanghai
Copy link

nurbashanghai commented Nov 2, 2021

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
Copy link

Thanks @nurbashanghai - worked like a charm! 🚀 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants