thiagodp / codeceptjs-dbhelper

📜 Let your CodeceptJS tests talk to databases
MIT License
9 stars 1 forks source link

Support for adding new adapter #14

Open esteban-serfe opened 2 years ago

esteban-serfe commented 2 years ago

Hi:

I'm trying to add a new adapter for my specific setup.

I'm using database-js-mysql2 to be able to connect to the newest version for mysql 8 which is not compatible with the MySQL adapter.

I've created the package, it works and tests works as expected.

I've installed it and get the following error:

Cannot read properties of undefined (reading 'setStatus')

With the following connection string: mysql2://root:rootpwd@localhost/qblite

is there anything else I need to configure so the new driver is accepted?

I'm using this functions inside a helper.

thiagodp commented 2 years ago

Hi @esteban-serfe,

thank you for providing a new MySQL driver for database-js. I'll list it in the project's page soon.

Your package should work without configuring anything. I couldn't determine the reason from the given error message. The method setStatus isn't in the codeceptjs-dbhelper's source code. Could you get the stack trace?

esteban-serfe commented 2 years ago

Hi @thiagodp I'll try to recreate this with a simple test case and post the code for you to see. I could not have a stack trace of this with --debug or other flags on the error.

I'm using it right now inside the helper with the following code and works without any issue:

async runQuery( query )
  {
    const { DbHelper } = this.helpers;
    await DbHelper.connect("test", "mysql2://root:rootpwd@localhost/qblite" );
    let result = await DbHelper.query("test", query );
    await DbHelper.removeConnection("test"); 
    return result;
  }

I think that the error might be triggered by trying to use this directly in the Actor class (steps_file.js) directly. My initial code was something like:

module.exports = function() {
  return actor({
    runQuery: function( query ) {
        await DbHelper.connect("test", "mysql2://root:rootpwd@localhost/qblite" );
        let result = await DbHelper.query("test", query );
        await DbHelper.removeConnection("test"); 
         return result;
    }

.....more code....
  }); 
}

Let me know if you have any questions.

I'll be submitting a request for adding also withint the database-js repository.

Regards