This package provides a set of Cypress commands and plugin utilities for interacting directly with a PostgreSQL database during end-to-end tests. It allows test suites to execute SQL queries, verify data, or seed test data by leveraging the `pg` client library. The current stable version is 1.0.8. Based on the README, it appears to support older Cypress plugin architectures (e.g., `cypress/plugins/index.js`), which suggests it is not actively maintained for the latest Cypress versions (Cypress 10+ uses `cypress.config.js`). Its primary differentiation is enabling direct database interaction within Cypress tests, streamlining data setup and verification workflows, offering a direct bridge for database operations within the Cypress testing environment, which can be critical for test data management and assertions.
npm install cypress-postgresqlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure `cypress-postgresql` in a Cypress setup (pre-Cypress 10.0), define database credentials, load custom commands, and execute a basic insert and select query within a test.
For Cypress 10+, manual refactoring is needed to adapt the plugin logic to the `cypress.config.js` setup. This may involve using `defineConfig` and handling `on('task', ...)` directly within the configuration file or creating a custom `setupNodeEvents` function. Alternatively, consider using a more modern Cypress database plugin.Ensure `npm install pg` or `yarn add pg` is run in your project's root directory alongside `cypress-postgresql`.
Utilize environment variables (e.g., `process.env.PG_USER`) in your `cypress.json` or `cypress.config.js` for database credentials. Pass them during test execution, for example, using a `.env` file and a package like `dotenv` or directly in your CI/CD pipeline.
For new projects, prefer Cypress 10+ and integrate database tasks directly into `cypress.config.js` or explore alternative, actively maintained Cypress database plugins that support the latest configuration patterns.
Ensure `pg` is installed (`npm install pg`) and that `cypress-postgresql` is `require`d in the plugin file (e.g., `const postgreSQL = require('cypress-postgresql');`) as it exposes `loadDBPlugin` as a method on its default export.Verify that your PostgreSQL server is running and accessible from where Cypress tests are executed. Double-check all database credentials in your `cypress.json` file for accuracy. Ensure no firewall rules are blocking the connection.
Review your SQL query for typos in table or column names. Confirm that the table and columns exist in the target database. Check the database user's permissions to ensure they have read/write access to the necessary tables.