CodeceptJS helper (version 1.0.1) designed to streamline end-to-end testing against PostgreSQL databases. This package allows developers to execute raw SQL queries directly from their CodeceptJS test scenarios, which is crucial for setting up test data, verifying database states, and cleaning up after tests. It integrates into the CodeceptJS ecosystem by being configured in `codecept.conf.js` and exposing its methods via the framework's actor object (`I`). This helper differentiates itself from general PostgreSQL client libraries by providing a test-centric interface within the CodeceptJS testing paradigm. The project is maintained by Percona-Lab, with its release cadence currently driven by community contributions and specific project needs.
npm install codeceptjs-postgresqlhelperVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure the `PostgresqlDBHelper` in a `codecept.conf.js` file, utilizing environment variables for secure credential management. It then provides an example CodeceptJS scenario (`my_db_test.js`) that uses the `I.runQuery` method to perform a full database test lifecycle: creating a temporary table, inserting test data, verifying the insertion, and finally cleaning up the table, ensuring isolated tests.
Use environment variables (e.g., `process.env.DB_HOST`) to pass credentials to the helper configuration. Tools like `dotenv` can assist with local development environment variables.
For dynamic values, ensure all inputs are properly sanitized or, if the underlying `pg` client were directly exposed, use parameterized queries. For test data originating from trusted scripts, this risk is reduced but still a good practice to be aware of.
If standalone PostgreSQL interaction is needed outside CodeceptJS tests, use the `pg` package directly or another dedicated PostgreSQL client library.
Verify the PostgreSQL service status, check firewall rules, and confirm `host` and `port` settings in `codecept.conf.js` match your database server configuration.
Verify that the PostgreSQL server is running, listening on the specified port (`5432` by default), and accessible from the machine running CodeceptJS tests. Check firewall rules if applicable. Confirm `host` and `port` in `codecept.conf.js`.
Double-check the `user` and `password` values in `codecept.conf.js` against your PostgreSQL user credentials. Ensure the user has permissions to connect to the specified database.
Ensure the `database` name in `codecept.conf.js` matches an existing database on your PostgreSQL server, or create the database if it's missing.