Registry / testing / cypress-postgres

cypress-postgres

JSON →
library1.1.1jsnpmunverified

Cypress plugin to query PostgreSQL databases directly from Cypress tests. Current stable version is 1.1.1, with low release cadence (last update 2020). Allows passing SQL queries via cy.task() and retrieving results for assertions. Supports multiple database connections by passing connection details inline. Limited to Node-based Cypress runner; no TypeScript support.

npm install cypress-postgres
INSTALL
IMPORT
SIG · CYPRESS-POSTGRES
C
cypress-postgres
testingjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dbQuery task
on('task', { dbQuery: (query) => require('cypress-postgres')(query.query, query.connection) })
import dbQuery from 'cypress-postgres'
Used in cypress/plugins/index.js as a Node event; not a direct import in test files.
require('cypress-postgres')
const cypressPostgres = require('cypress-postgres')
import cypressPostgres from 'cypress-postgres'
Cypress plugins are CommonJS; ESM not supported.
cy.task('dbQuery', ...)
cy.task('dbQuery', { query: 'SELECT * FROM users', connection: {...} })
cy.task('dbQuery', 'SELECT * FROM users')
Second argument must be an object with query and optional connection property.

Shows plugin setup in plugins file, database configuration, and a sample test query.

// cypress/plugins/index.js module.exports = (on) => { on('task', { dbQuery: (query) => require('cypress-postgres')(query.query, query.connection) }); }; // cypress.json (or cypress.env.json) { "db": { "user": "postgres", "host": "localhost", "database": "postgres", "password": "", "port": 5432 } } // In a test file cy.task('dbQuery', { query: 'SELECT NOW()' }).then((result) => { expect(result).to.have.length(1); });
Debug
Known issues
gotchaDatabase credentials are stored in cypress.json which may be committed to source control. Use cypress.env.json or environment variables for sensitive data.
fix
Store credentials in cypress.env.json and reference via Cypress.env('db') instead of hardcoding in cypress.json.
affects: >=0.0.0
breakingThe plugin uses require('cypress-postgres') directly in the plugins file. If the package is not installed correctly, tests will fail with 'Cannot find module' error.
fix
Ensure npm install --save-dev cypress-postgres is run and the package is present in node_modules.
affects: >=0.0.0
gotchaQuery results are returned as raw rows from node-postgres. For SELECT queries, the result is an array of objects, but the plugin does not handle errors; rejected promise will cause test failure.
fix
Wrap cy.task in a try/catch or use .catch to handle query failures gracefully.
affects: >=0.0.0
deprecatedThe plugin has not been updated since 2020 and may not work with Cypress versions > 10 due to plugin system changes.
fix
Migrate to Cypress's new component testing or use a different database plugin that supports modern Cypress.
affects: >=10.0.0
Errors
Common errors & fixes
Error: Cannot find module 'cypress-postgres'
Package not installed or node_modules missing.
fix
Run 'npm install --save-dev cypress-postgres'.
cy.task('dbQuery') failed with: error: password authentication failed for user
Incorrect credentials in cypress.json or environment variables.
fix
Verify user, password, host, database, and port in db configuration.
dbQuery is not a registered task
Plugin not properly registered in cypress/plugins/index.js.
fix
Add on('task', { dbQuery: ... }) as shown in the README.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
pgrequiredRequired to execute PostgreSQL queries.
Agent activity
13 hits · last 30 days
node
12
Resources
cypress-postgres — npm install cypress-postgres · libregistry