Home > Software engineering >  Trouble connecting to SQL Server with Cypress
Trouble connecting to SQL Server with Cypress

Time:10-26

Having an issue with where i seem to be connecting to SQL Server but cannot find the server/db.

enter image description here

I have been trying to follow the steps in this guide for Cypress 9 but to no avail.

enter image description here

CodePudding user response:

You have the pattern for cypress.config.js plus the one for cypress.config.ts in your config file, but it's either/or not both at once.
See example Configuration.

Since you use typescript, try

import { defineConfig } from 'cypress'
import sqlServer from 'cypress-sql-server'

const dbSettings = {
  "userName": "x",
  "password": "x",
  "server": "xxx\\SQLEXPRESS",
  "options": {
    "database": "xxxxxx",
    "encrypt": true,
    "rowCollectionOnRequestCompletion": true,
    "trusted_connection": true
  }
}

export default defineConfig({
  chromeWebSecurity: false,
  ...  // other cofinfig settings
  e2e: {
    setupNodeEvents(on, config) {
      config.db = dbSettings;
      const tasks = sqlServer.loadDBPlugin(dbSettings);
      on('task', tasks);
      return require('./cypress/plugins/index.ts')(on, config)
    },
    experimentalSessionAndOrigin: true,
    specPattern: 'cypress/e2e/tests/orders/*',
    baseUrl: 'http://localhost:4200',
  },
})
  • Related