Registry / testing / cypress-multiple-db-sql-server

cypress-multiple-db-sql-server

JSON →
library1.0.0jsnpmunverified

Cypress plugin (v1.0.0) for executing SQL queries against Microsoft SQL Server databases, leveraging the tedious driver. Extends the cypress-sql-server concept by allowing connections to multiple databases by passing the database name as a command parameter. Key differentiator: supports multiple databases within the same server via dynamic database selection, and optionally multiple servers by providing full config per call. Primarily for E2E testing to seed/verify database state. Low release cadence (single version).

npm install cypress-multiple-db-sql-server
INSTALL
IMPORT
SIG · CYPRESS-MULTIPLE-D
C
cypress-multiple-db-sql-server
testingjavascriptv1.0.0
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.

sqlQueryCommand
import { sqlQueryCommand } from 'cypress-multiple-db-sql-server'
const { sqlQueryCommand } = require('cypress-multiple-db-sql-server')
Both ESM and CJS work, but TypeScript types are included; prefer ESM import.
sqlQueryPlugin
import { sqlQueryPlugin } from 'cypress-multiple-db-sql-server'
import sqlQueryPlugin from 'cypress-multiple-db-sql-server'
sqlQueryPlugin is a named export, not a default export.
execSql
import { execSql } from 'cypress-multiple-db-sql-server'
import { execSqlTask } from 'cypress-multiple-db-sql-server'
execSql is the lower-level function; it is also available via named export.

Registers the Cypress task and custom command using TypeScript. Configures DB connection via env, then executes query against 'myDatabase'.

// cypress.config.ts import { defineConfig } from 'cypress'; import { sqlQueryPlugin } from 'cypress-multiple-db-sql-server'; export default defineConfig({ e2e: { setupNodeEvents(on, config) { on('task', { ...sqlQueryPlugin }); return config; }, }, env: { db: { authentication: { type: 'default', options: { userName: 'sa', password: process.env.DB_PASSWORD ?? '' } }, server: 'localhost', options: { database: '', encrypt: true, rowCollectionOnRequestCompletion: true, trustServerCertificate: true, port: 1433 } } } }); // support/commands.ts import { sqlQueryCommand } from 'cypress-multiple-db-sql-server'; sqlQueryCommand(); // In spec: cy.sqlServerQuery('myDatabase', 'SELECT * FROM Users').then((rows) => { cy.log(JSON.stringify(rows)); });
Debug
Known issues
gotchaDatabase name must be passed as first argument to sqlServerQuery; ignoring the env config's database field.
fix
Always provide the database name parameter in cy.sqlServerQuery(dbName, query).
affects: >=1.0.0
gotchaThe database configuration is picked up from Cypress env object under 'db'; any typo (e.g., 'dB') will cause silent failure.
fix
Ensure env.db is set with correct casing and structure in cypress.config.ts.
affects: >=1.0.0
breakingRequires Node.js >=12 and Cypress >=10 (due to use of setupNodeEvents).
fix
Upgrade Cypress to version 10 or higher.
affects: >=1.0.0
gotchaMultiple servers: parseConfig expects a full configuration object to be passed to execSql; not passed as env variable.
fix
When using execSql directly, provide a config object as the first argument (not from env).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'authentication')
Missing or misconfigured env.db in Cypress config.
fix
Add valid db configuration under env in cypress.config.ts (or cypress.json for older versions).
Error: Failed to connect to localhost:1433 - getaddrinfo ENOTFOUND localhost
SQL Server not running or hostname incorrect.
fix
Ensure SQL Server is running and reachable. Update server field in db config if needed.
Error: Login failed for user 'sa'
Incorrect username or password in configuration.
fix
Verify credentials in env.db.authentication.options.userName and .password.
CypressError: `cy.task('sqlServer:execute')` failed with the following error: > 'undefined' is not a function
Plugin not registered correctly in setupNodeEvents.
fix
Add on('task', { ...sqlQueryPlugin }) inside setupNodeEvents.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
tediousrequiredMicrosoft SQL Server driver for Node.js; required for database connectivity
Agent activity
5 hits · last 30 days
node
4
Resources
cypress-multiple-db-sql-server — npm install cypress-multiple-db-sql-server · libregistry